Owns lead-management business logic that sits above the raw Lead and Task entities: team and task statistics for dashboards, lead and note creation, lead search and ranking, task and calendar notifications, and lookup or creation of the sales/leads groups and organisation types used to configure the leadman app for a tenant. Reached from Java and templates via the request context as LeadmanService, and marked Safe so it can also be invoked from sandboxed contexts.


Properties

PropertyReturnsDescription
enableNewCompanyIdbooleanWhether the leadman app is configured to use the newer company id scheme, for the current tenant organisation.
leadsGroupGroupThe group that leads are added to as members, for the current tenant organisation. Creates the group if it does not already exist, using the configured "leadsGroup" name or "leads" if none is configured.
leadsOrgTypeOrgTypeThe organisation type used to mark lead organisations, for the current root folder's organisation. The configured value is looked up first by name and, for legacy configuration, falls back to treating it as an organisation type id.
salesOrgTypeOrgTypeThe organisation type used to mark sales organisations, for the current root folder's branch or organisation. The configured value is looked up first by name and, for legacy configuration, falls back to treating it as an organisation type id.

Methods

cancelTask(Task t) · teamTaskStatus(Profile p, Organisation adminOrg) · teamStats(Profile p, Organisation adminOrg) · taskStats(Profile currentUser) · createNote(Task task, String newNote, String actionType, boolean inbound, Date now, Profile curUser) · createNote(Lead lead, String newNote, String actionType, boolean inbound, Date now, Profile curUser) · findTasksByDueDate(int numDays) · findTasksByDueDate(Profile p, int numDays) · assignedTags(Profile p) · removeTask(Task t) · getSalesManagerOrgs(Profile currentUser, Organisation rootOrg) · updateTask(Task t) · fireTaskAssignmentChanged(Task t, Profile previousAssignee) · doLeadSearch(String fieldType, List<String> fieldNames, String queryString, List<String> teams, List<Long> filterGroups, List<String> sourcesFilter, List<String> assignedToFilter, List<String> funnelsFilter, Integer from, Integer size) · doLeadSearch(String fieldType, List<String> fieldNames, String queryString, List<String> teams, List<Long> filterGroups, List<String> sourcesFilter, List<String> assignedToFilter, List<String> funnelsFilter, List<String> stagesCriteria, Integer from, Integer size) · searchLeadsRanked() · searchLeadsRanked(Profile assignedTo, int start, int size) · searchLeadsRanked(Funnel funnel) · searchLeadsRanked(LeadSearchCriteria crit, SearchProperties searchProperties) · softDelete(Lead lead, Organisation org) · softDelete(Lead lead, Organisation org, Profile deletedBy) · hardDelete(Lead lead, Organisation org) · deleteLeadCompany(Organisation org) · removeLeadsForStage(FunnelRepository funnel, Branch version, String stageName, Organisation org) · getEngagementScore(Funnel funnel, Lead lead) · isEnableNewCompanyId() · appendNotes(List<StreamEventBean> list, List<LeadNote> notes) · getLeadsGroup() · getLeadProfileExtraFields(Profile profile) · getSalesOrgType() · getLeadsOrgType()

cancelTask(Task t)

Returns: void

Cancels a task, recording the current time as its cancellation date.

ParameterDescription
tthe task to cancel

teamTaskStatus(Profile p, Organisation adminOrg)

Returns: TaskStats

Calculates task completion statistics for the sales teams that the given profile manages, over the last 30 days. Searches the task index for tasks completed in that window and assigned to any organisation the profile manages as a sales manager, and counts how many were completed by their due date and how many were cancelled.

ParameterDescription
pthe sales manager whose managed teams' tasks are aggregated
adminOrgthe tenant admin organisation to search within

teamStats(Profile p, Organisation adminOrg)

Returns: TeamStats

Calculates lead and deal statistics for the sales teams that the given profile manages: the count and pipeline value of currently active leads, the count and value of deals closed in the last 30 days, and the number of tasks due within the next 7 days. Requires the profile to hold the sales manager role.

ParameterDescription
pthe sales manager whose managed teams' leads and deals are aggregated
adminOrgthe tenant admin organisation to search within

taskStats(Profile currentUser)

Returns: TaskStats

Calculates task completion statistics for tasks assigned to the given profile and completed so far this calendar year: how many were completed by their due date, the total completed, and how many were cancelled.

ParameterDescription
currentUserthe profile whose completed tasks are aggregated

createNote(Task task, String newNote, String actionType, boolean inbound, Date now, Profile curUser)

Returns: LeadNote

Creates and persists a note against the given task, recording who made it and whether it represents inbound or outbound communication.

ParameterDescription
taskthe task the note is attached to
newNotethe note text
actionTypethe type of action the note records, used for timeline display and grouping
inboundtrue if the note represents communication received from the customer, false if sent to them
nowthe time the note was created
curUserthe profile that created the note

createNote(Lead lead, String newNote, String actionType, boolean inbound, Date now, Profile curUser)

Returns: LeadNote

Creates and persists a note against the given lead, recording who made it and whether it represents inbound or outbound communication.

ParameterDescription
leadthe lead the note is attached to
newNotethe note text
actionTypethe type of action the note records, used for timeline display and grouping
inboundtrue if the note represents communication received from the customer, false if sent to them
nowthe time the note was created
curUserthe profile that created the note

findTasksByDueDate(int numDays)

Returns: List<Task>

Finds tasks due within the given number of days from now that are assigned to the current signed-in user.

ParameterDescription
numDaysthe number of days from now to search up to

findTasksByDueDate(Profile p, int numDays)

Returns: List<Task>

Finds tasks due within the given number of days from now that are assigned to the given profile, within the current tenant's admin organisation.

ParameterDescription
pthe profile whose due tasks are searched for
numDaysthe number of days from now to search up to

assignedTags(Profile p)

Returns: List<Group>

Finds the mailing-list groups the given profile belongs to within the current tenant organisation. Used to show or manage which tag groups a lead's profile is subscribed to.

ParameterDescription
pthe profile whose tag group memberships are looked up, may be null

removeTask(Task t)

Returns: void

Notifies the search index that a task has been removed, so it is dropped from search results. Has no effect if the task is null.

ParameterDescription
tthe task that was removed

getSalesManagerOrgs(Profile currentUser, Organisation rootOrg)

Returns: List<Organisation>

Finds the organisations, within rootOrg, for which the given profile holds the sales manager role. Scans the profile's group memberships for group roles granting the sales manager role and keeps only those within rootOrg.

ParameterDescription
currentUserthe profile whose sales manager group memberships are scanned
rootOrgthe organisation to restrict results to

updateTask(Task t)

Returns: void

Applies the side effects of a task change: runs notification and calendar-event checks, and notifies the search index that the task was updated. Has no effect if the task is null.

ParameterDescription
tthe task that was updated

fireTaskAssignmentChanged(Task t, Profile previousAssignee)

Returns: void

Fires a TaskAssigneeChangedEvent for the given task, recording who it was previously assigned to. Has no effect if the task is null.

ParameterDescription
tthe task whose assignment changed
previousAssigneethe profile the task was previously assigned to, may be null

doLeadSearch(String fieldType, List<String> fieldNames, String queryString, List<String> teams, List<Long> filterGroups, List<String> sourcesFilter, List<String> assignedToFilter, List<String> funnelsFilter, Integer from, Integer size)

Returns: KSearchResponse

Searches leads matching the given filter criteria, paged by from and size.

ParameterDescription
fieldTypethe lead field type being searched
fieldNamesthe field names to search within
queryStringthe free-text search string, may be blank
teamsteam names to filter by
filterGroupsgroup ids to filter by
sourcesFilterlead source names to filter by
assignedToFilterassignee identifiers to filter by
funnelsFilterfunnel names to filter by
fromthe zero-based offset of the first result to return
sizethe maximum number of results to return

doLeadSearch(String fieldType, List<String> fieldNames, String queryString, List<String> teams, List<Long> filterGroups, List<String> sourcesFilter, List<String> assignedToFilter, List<String> funnelsFilter, List<String> stagesCriteria, Integer from, Integer size)

Returns: KSearchResponse

Searches leads matching the given filter criteria, including funnel stage criteria, paged by from and size.

ParameterDescription
fieldTypethe lead field type being searched
fieldNamesthe field names to search within
queryStringthe free-text search string, may be blank
teamsteam names to filter by
filterGroupsgroup ids to filter by
sourcesFilterlead source names to filter by
assignedToFilterassignee identifiers to filter by
funnelsFilterfunnel names to filter by
stagesCriteriafunnel stage names to filter by
fromthe zero-based offset of the first result to return
sizethe maximum number of results to return

searchLeadsRanked()

Returns: KSearchResponse

Searches all leads with a match-all query. Intended as a base for lead ranking, though score boosting is not yet applied.

searchLeadsRanked(Profile assignedTo, int start, int size)

Returns: List<LeadRankedBean>

Searches open leads (those without a closedDate) and ranks results so leads assigned to the given profile, or with an active task assigned to them, are boosted above other results.

ParameterDescription
assignedTothe profile whose leads and active tasks are boosted in the ranking, may be null
startthe number of leading results to skip
sizethe maximum number of results to return

searchLeadsRanked(Funnel funnel)

Returns: KSearchResponse

Searches leads within the given funnel.

ParameterDescription
funnelthe funnel to search within

searchLeadsRanked(LeadSearchCriteria crit, SearchProperties searchProperties)

Returns: KSearchResponse

Searches leads matching the given criteria: funnel, optional group, optional current funnel node, created date range and status (active, cancelled or closed). Results are paged and sorted according to searchProperties when given.

ParameterDescription
critthe funnel and filter criteria to search by; must have a funnel set
searchPropertiespaging and sort order to apply, may be null to use default paging

softDelete(Lead lead, Organisation org)

Returns: void

Soft-deletes a lead, attributing the deletion to the current signed-in user, and updates the tasks and search index that reference it.

ParameterDescription
leadthe lead to delete
orgthe organisation the deletion event is raised against

softDelete(Lead lead, Organisation org, Profile deletedBy)

Returns: void

Soft-deletes a lead, attributing the deletion to the given profile, and updates the tasks and search index that reference it.

ParameterDescription
leadthe lead to delete
orgthe organisation the deletion event is raised against
deletedBythe profile the deletion is attributed to, may be null

hardDelete(Lead lead, Organisation org)

Returns: void

Deletes a lead without attributing the deletion to any profile, and updates the tasks and search index that reference it.

ParameterDescription
leadthe lead to delete
orgthe organisation the deletion event is raised against

deleteLeadCompany(Organisation org)

Returns: void

Soft-deletes an organisation that was used as a lead company: unlinks it from any leads that reference it as their company or assignee, removes all group memberships within it, and soft-deletes the organisation itself.

ParameterDescription
orgthe organisation to unlink and soft-delete

removeLeadsForStage(FunnelRepository funnel, Branch version, String stageName, Organisation org)

Returns: void

Clears the stage name from every lead currently at the given funnel stage, run within its own transaction. Used when a stage is removed from a funnel definition so existing leads are not left pointing at it.

ParameterDescription
funnelthe funnel repository the stage belongs to
versionthe funnel version (branch) to search leads within
stageNamethe name of the stage being removed
orgthe organisation to search leads within

getEngagementScore(Funnel funnel, Lead lead)

Returns: Float

The lead's engagement score, converted from the double stored on the lead entity to a float for display. The funnel parameter is currently unused.

ParameterDescription
funnelunused
leadthe lead whose engagement score is read

isEnableNewCompanyId()

Returns: boolean

Whether the leadman app is configured to use the newer company id scheme, for the current tenant organisation.

appendNotes(List<StreamEventBean> list, List<LeadNote> notes)

Returns: void

Converts lead notes into timeline stream event beans and appends them to the given list, for display on an activity timeline. Each note's title is taken from the matching customer action on its funnel where one is defined, otherwise from the note's own timeline title, and its category (danger, success or info) is derived from its action type.

ParameterDescription
listthe list that converted stream event beans are appended to
notesthe lead notes to convert and append

getLeadsGroup()

Returns: Group

The group that leads are added to as members, for the current tenant organisation. Creates the group if it does not already exist, using the configured "leadsGroup" name or "leads" if none is configured.

getLeadProfileExtraFields(Profile profile)

Returns: Map<ExtraField,String>

Builds the map of extra profile fields, and their current values, defined on the primary group memberships of the given profile. Excludes file-upload fields, and where the same field name appears on more than one membership only the required definition (or the first found) is kept.

ParameterDescription
profilethe profile whose extra fields are collected, may be null

getSalesOrgType()

Returns: OrgType

The organisation type used to mark sales organisations, for the current root folder's branch or organisation. The configured value is looked up first by name and, for legacy configuration, falls back to treating it as an organisation type id.

getLeadsOrgType()

Returns: OrgType

The organisation type used to mark lead organisations, for the current root folder's organisation. The configured value is looked up first by name and, for legacy configuration, falls back to treating it as an organisation type id.

To get full access to the Kademi Hub existing customers can login here, or new customers can register here.