You need to sign in to do that
Don't have an account?
Michael M
Test code for basic trigger
Would someone be able to help me write test code for this trigger:
trigger ReferralCreateContact on Lead (after insert) {
if (trigger.isinsert){
if (trigger.isafter){
for (lead ld : trigger.new){
if (ld.nextofkin__c !=null && ld.Emergency_Contact_Phone__c !=null){
String first;
String last;
String s = ld.NextofKin__c;
String [] lines = s.split(' ');
first = lines[0];
last = lines[1];
List<Contact> contactToInsert = new List<contact>();
Contact newContact = new Contact();
newContact.RecordTypeId='0121N000001HoR7QAK';
newContact.related_referral__c = ld.id;
newContact.firstname = first;
newContact.lastname = last;
newContact.MobilePhone=ld.Emergency_Contact_Phone__c;
newContact.recordtypeid= '0122g0000005rSbAAI';
newContact.ownerid = ld.ownerid;
contactToInsert.add(newContact);
insert contactToInsert;
}
}
}
}
}
trigger ReferralCreateContact on Lead (after insert) {
if (trigger.isinsert){
if (trigger.isafter){
for (lead ld : trigger.new){
if (ld.nextofkin__c !=null && ld.Emergency_Contact_Phone__c !=null){
String first;
String last;
String s = ld.NextofKin__c;
String [] lines = s.split(' ');
first = lines[0];
last = lines[1];
List<Contact> contactToInsert = new List<contact>();
Contact newContact = new Contact();
newContact.RecordTypeId='0121N000001HoR7QAK';
newContact.related_referral__c = ld.id;
newContact.firstname = first;
newContact.lastname = last;
newContact.MobilePhone=ld.Emergency_Contact_Phone__c;
newContact.recordtypeid= '0122g0000005rSbAAI';
newContact.ownerid = ld.ownerid;
contactToInsert.add(newContact);
insert contactToInsert;
}
}
}
}
}
Please try the below code:
If any problem arises then please let me know.
Thanks and Regards
Ayush Sharma
All Answers
Please try the below code:
If any problem arises then please let me know.
Thanks and Regards
Ayush Sharma
Thank you so much. I ran the test, but it failed and gave this error message:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “Referral Process” process failed. Give your Salesforce admin these details. <b>An unhandled fault has occurred in this flow</b><br>An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information.: [] Class.ReferralCreateContactTest.refTestMethod: line 11, column 1