Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creates a Kanban Viewer for the Lead Object in Lightning Design System
public class LeadKanbanController {
public static String LEAD_MOVED = '{0} was moved successfully to {1}';
public List<Schema.PicklistEntry> leadStatuses { get; set; }
public Map<String, List<Lead>> allLeads { get; set; }
public class UpdateStatus {
public Boolean isSuccess;
public String message;
}
public LeadKanbanController() {
leadStatuses = Lead.Status.getDescribe().getPicklistValues();
fetchLeads();
}
@RemoteAction
public static UpdateStatus updateLeadStatus( Id leadId, String newLeadStatus ) {
Lead leadDetails = [
SELECT Id
,Name
FROM Lead
WHERE Id = :leadId
];
leadDetails.Status = newLeadStatus;
UPDATE leadDetails;
UpdateStatus updatedLeadDetails = new UpdateStatus();
updatedLeadDetails.isSuccess = true;
updatedLeadDetails.message = String.format( LEAD_MOVED, new List<String>{ leadDetails.Name, newLeadStatus } );
return updatedLeadDetails;
}
private void fetchLeads() {
List<Lead> leads = [
SELECT Id
,Name
,Title
,Company
,Email
,Status
FROM Lead
];
allLeads = new Map<String, List<Lead>>();
for( Lead lead : leads ) {
if( !allLeads.containsKey( lead.Status ) ) {
allLeads.put( lead.Status, new List<Lead>{ lead } );
}
else {
allLeads.get( lead.Status ).add( lead );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment