Print this page

Flow Error when using Lead and trying to access Standard or Custom Fields

Knowledge Article Number 000206307
Description If you are using a flow which is using a "Loop" to go over all the leads (screenshot below). In each loop, email is sent with Lead information. But if in email body, you are trying to access any fields other than the Lead or ID then you will get an "System.UnexpectedException".
User-added image
Next step in above is to send an email with Lead info. Email is set in emailBody and following is the text of body. 
Lead: {!Lead}
Lead ID: {!Lead.Id}
Lead Company: {!Lead.Company}

This will fail as is but if "{!Lead.Company}" is removed then it will work. This flow is used in following code and running it will result in "System.UnexpectedException".
private void recycle(Lead[] lds) { 
	Map<String, Object> params = new Map<String, Object>(); 
	params.put('LeadsIn', lds);     
	Flow.Interview.Test recycleLeadsFlow = new Flow.Interview.Test(params); 
string q ='SELECT Id FROM Lead LIMIT 2'; 


To achieve above mentioned functionality, flow can be changed as following:

- Loop throw the leads
- Use FastLookup to look for that lead (screenshot below)
- Use that in the emailBody

This way, you should be able to use all the fields in the lead.

User-added image

Lead: {!myLead}
Lead ID: {!myLead.Id}
Lead Company: {!myLead.Company}

promote demote