You need to sign in to do that
Don't have an account?
Bill Block
Trigger Issue with Convert Mapping (Apex Newbie)
Hey all!
With some help I wrote this custom trigger that allows our reps to list some additional contacts and their information on Lead records that then transform into Contact records on lead convert.
Only way to get around this with the current trigger is to list dummy Contact name data in the custom lead fields before the Lead gets converted.
What would be the best way to encapsulate the trigger so that it doesn't fire when names aren't listed / just when one additional contact is listed?
With some help I wrote this custom trigger that allows our reps to list some additional contacts and their information on Lead records that then transform into Contact records on lead convert.
trigger CreateMoreLeadContacts on Lead (after update) { list < Contact > listContacts = new List < Contact>(); for(Lead objLead : trigger.new) { if(objlead.IsConverted && !trigger.oldMap.get(objLead.Id).IsConverted) { Contact c1=New Contact( LastName=objLead.Secondary_Lead_Contact_Name__c, Phone=objLead.Secondary_Lead_Phone__c, Email=objLead.Secondary_Lead_Email__c); c1.AccountId = objLead.ConvertedAccountId; listContacts.add(c1); Contact c2=New Contact( LastName=objLead.Tertiary_Lead_Contact_Name__c, Phone=objLead.Tertiary_Lead_Phone__c, Email=objLead.Tertiary_Lead_Email__c); c2.AccountId = objLead.ConvertedAccountId; listContacts.add(c2); } } if ( listContacts.size() > 0 ) insert listContacts; }The trigger works just fine and as expected... however, i've now indentified an issue when trying to convert a Lead when no data is present in both "Secondary Contact Lead Name" & "Tertiary Contact Lead Name".
Only way to get around this with the current trigger is to list dummy Contact name data in the custom lead fields before the Lead gets converted.
What would be the best way to encapsulate the trigger so that it doesn't fire when names aren't listed / just when one additional contact is listed?
Regards
Andrew
All Answers
Regards
Andrew
Your suggestion worked, though, I changed the if statement from isblank to isnotempty(custom field) and it's working like a charm =)
Glad you got it sorted.
Regards
Andrew