I've a requirement where I want to assign leads based on state I need to compare Lead's custom field state(text) with Custom settings field State(text Area) and UserName(text) and and if Lead state matches one of the state values in State (textarea) then assign owners based on that custom settings Username field.
I know we can use Lead Assignment rule but we want state and Username field Dynamic according to user's needs.
Example
Records in Custom Settings
State = TX,AR,LA
Username = Alice
State = DE,NC,TN,VA,WV
UserName = John
if Leads state = 'LA' then it should be assigned to Alice .
How can I compare Lead's text field with Cust settings textArea.
I have written a trigger but I am getting errors
public class RoundRobinLeads { public static void RoundRobinLeadMethod(List<Lead> leadList){ Map<Id,StateAssignment__c> mapOfStateOwners = new Map<Id,StateAssignment__c>(); Map<Id,Lead> mapleadsWithStates = new Map<Id,Lead>(); List<Lead> leadsWithStates= new List<Lead>(); for(StateAssignment__c s:[SELECT id ,State__c,UserName__c from StateAssignment__c]){ mapOfStateOwners.put(s.Id,s); } for(Lead l:leadList){ if(l.State__c != null){ leadsWithStates.add(l); mapleadsWithStates.put(l.id,l); } } for(StateAssignment__c st : mapOfStateOwners.KeySet() ){ for(Lead l: leadsWithStates){ if(l.State__c == st.State__c.contains(l.State__c)){ l.OwnerId = mapOfStateOwners.get(st.Id).UserName__c; } } } }}
but it gives error
Comparison arguments must be compatible types: String, Boolean
how can I compare Lead's text and custom settings text area field?
#Round-robin #Lead Assignment #Custom Settings #Sales Cloud #Service Cloud #Trailhead
Hello @Shivani Tanwar,
Please use the below code to get the error resolve -
public class RoundRobinLeads { public static void RoundRobinLeadMethod(List<Lead> leadList){ Map<Id,StateAssignment__c> mapOfStateOwners = new Map<Id,StateAssignment__c>(); Map<Id,Lead> mapleadsWithStates = new Map<Id,Lead>(); List<Lead> leadsWithStates= new List<Lead>(); for(StateAssignment__c s:[SELECT id ,State__c,UserName__c from StateAssignment__c]){ mapOfStateOwners.put(s.Id,s); } for(Lead l:leadList){ if(l.State__c != null){ leadsWithStates.add(l); mapleadsWithStates.put(l.id,l); } } for(StateAssignment__c st : mapOfStateOwners.KeySet() ){ for(Lead l: leadsWithStates){ if(st.State__c.contains(l.State__c)){ l.OwnerId = mapOfStateOwners.get(st.Id).UserName__c; } } } } }
in the If condition contains return true and false so we need to check for the true or false or we can just leave without checking.
Hope it will help you, if it will help mark it as BEST ANSWER.
Thanks,
Yash Agrawal