You need to sign in to do that
Don't have an account?
Adam Lee 60
Bringing back Lead Name using Trigger on Case
Hi all.
I am very new to code so can someone please give me some advice?
I am trying to create trigger for when a case is created.
This is what I want to do:
if email address is on a lead, then populate the 'Lead' field. otherwise just leave the Lead field blank and save.
I've put an exception in at the moment so I can save the trigger but this needs replacing,
Hope you can help.
Thanks in advance
I am very new to code so can someone please give me some advice?
I am trying to create trigger for when a case is created.
This is what I want to do:
if email address is on a lead, then populate the 'Lead' field. otherwise just leave the Lead field blank and save.
trigger UpdateLeadOnCase on Case (before update) { public id leadID; public id caseId; public string caseEmail; Id caseRT1 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Inbound MTB Emails').getRecordTypeId(); Id caseRT2 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Inbound Sponsors').getRecordTypeId(); Id caseRT3 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Inbound Summits Del EU').getRecordTypeId(); Id caseRT4 = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Inbound Summits Del US').getRecordTypeId(); for(Case ca: Trigger.New) { try { if(ca.SuppliedEmail!=null) { Lead L = [Select ID,Name from Lead where Email =: ca.SuppliedEmail limit 1]; ca.Lead__c=l.Id; } else { //ca.Lead__c=''; } } catch(Exception ex) { ca.addError('No email address is found'); } } }
I've put an exception in at the moment so I can save the trigger but this needs replacing,
Hope you can help.
Thanks in advance
In line number 19, what is ca.Lead__c ?
Hi Adam,
Please follow this below code snippet and let me know in case of any help
Hi Adam,
Please use this below code snippet, ignore last one : -
Hi Adam,
Please mark the best answer, if it works for you :), otherwise let me know the issue, if you are still facing.
Thanks