Skip to content

Instantly share code, notes, and snippets.

@shrutis22
Created July 31, 2016 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shrutis22/46496ed096292112bbf7f078634544dc to your computer and use it in GitHub Desktop.
Save shrutis22/46496ed096292112bbf7f078634544dc to your computer and use it in GitHub Desktop.
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