You need to sign in to do that
Don't have an account?
retrieving field values after insert
I have created an after insert trigger for Case object that creates a corresponding lead when it is accepted from a Salesforce to Salesforce Connection. However, when I try to retrieve the field values after the insert they are null except for the ID. Can you please take a look at my code to see what I am doing wrong.
trigger createCaseLead on Case (after insert) {
List<Case> updatedCases = Trigger.new;
system.debug('Number of cases =' + updatedCases.size());
List<Lead> caseLead = new List<Lead>();
//Loops Through all of the new Cases and Creates
//a corresponding lead
for (Case c : updatedCases){
system.debug('ID = ' + c.ID);
system.debug('LastName = ' + c.Contact_Name_Copy__c); //This is returning null
system.debug('Company = '+ c.Org_Name__c); //This is returning null
caseLead.add(new Lead(Company = c.Org_Name__c,
Street = c.Org_Street__c,
City = c.Org_City__c,
State = c.Org_State__c,
Country = c.Org_Country__c,
email = c.Copy_Contact_Email__c,
LastName = c.Contact_Name_Copy__c,
LeadSource = 'Department of Commerce Customers',
Case_ID__c = c.Id,
How_did_you_find_this_Company1__c = 'DOC - ' + c.Fee_Based_Service__c
));
}
insert caseLead;
}
trigger createCaseLead on Case (after insert) {
List<Case> updatedCases = Trigger.new;
system.debug('Number of cases =' + updatedCases.size());
List<Lead> caseLead = new List<Lead>();
//Loops Through all of the new Cases and Creates
//a corresponding lead
for (Case c : updatedCases){
system.debug('ID = ' + c.ID);
system.debug('LastName = ' + c.Contact_Name_Copy__c); //This is returning null
system.debug('Company = '+ c.Org_Name__c); //This is returning null
caseLead.add(new Lead(Company = c.Org_Name__c,
Street = c.Org_Street__c,
City = c.Org_City__c,
State = c.Org_State__c,
Country = c.Org_Country__c,
email = c.Copy_Contact_Email__c,
LastName = c.Contact_Name_Copy__c,
LeadSource = 'Department of Commerce Customers',
Case_ID__c = c.Id,
How_did_you_find_this_Company1__c = 'DOC - ' + c.Fee_Based_Service__c
));
}
insert caseLead;
}
Please take a look at this link:
https://help.salesforce.com/HTViewHelpDoc?id=business_network_lead_inbox.htm&language=en_US
If this is the case, you may need to move your code to a future call.
All Answers
If these are not relationship fields then they should be populated in trigger.
Thanks,
Naval
Are those fields relationships?
Also, I suggest you put your trigger logic in a separate class (i.e. a Trigger handler). For my answer, I'm going to modify your existing code.
Could you try the following code:
Please find the below code:
Here I considered:
(1) Optimized the code. Please do let me know if it helps you.
Regards,
Mahesh
Please take a look at this link:
https://help.salesforce.com/HTViewHelpDoc?id=business_network_lead_inbox.htm&language=en_US
If this is the case, you may need to move your code to a future call.
Thank you for this. This delay is what was causing the issue, even with the @future call. The work around that I am going to use is to schedule a job that runs once a day to create the leads.