Created
July 31, 2016 10:14
-
-
Save shrutis22/46496ed096292112bbf7f078634544dc to your computer and use it in GitHub Desktop.
Creates a Kanban Viewer for the Lead Object in Lightning Design System
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
,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