You need to sign in to do that
Don't have an account?
Urgent: Apex Trigger not updating Look up field
Hey ,
I have a situation in which whenever a TASK is created , it should automatically create a new record in custom object ( XYZ__C) by taking values from the custom fields in TASK object. Custom objec(XYZ__C) has 3 fields , 2 picklists and one is lookup field. My trigger is fetching the values for picklists but it is not fetching for lookup field. Its is giving the below error. Trigger is also mentioned below . I have checked all the previous threads also. Anyone who can fix the below code would be great
Apex trigger createleadinterest caused an unexpected exception, contact your administrator: createleadinterest: execution of AfterUpdate caused by: System.StringException: Invalid id: 2012 Fall: Trigger.createleadinterest: line 13, column 1
trigger createleadinterest on Task (after insert,after update) {
List <XYZ__c> leadinterest = new List <XYZ__c>();
for (Task tk : Trigger.new) {
if (tk.Type == 'Web Form') {
XYZ__c ld = new XYZ__c (); //instantiate the object to put values for future record
ld.Primary_Source__c = tk.Task_Source__c; // and so on so forth untill you map all the fields.
ld.Term__c = tk.Enrollment_Term__c; // Term__c is a look up field on XYZ__c
leadinterest.add(ld);
}
}
try {
insert leadinterest;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
How does the Enrollment_Term__c link to the Term record in Salesforce? So your XYZ object has a link to the Term__c but the Task's Enrollment_Term__c is not a Term__c Id... what is it?
In any case that question should give you the direction you need to go... try something like this (you'll have to fix it to work with your objects)
Again this will probably not compile for you but should give you a better idea of what you need to do.
I think I was not able to present the question clearly. But I tweaked your solution its not working. It actually confused me more. Let me try to rephrase the question. Enrollment_term__c is a field on Task object and Term__c is field on XYZ__C object. This Term__c field is also look up field on sme other object. So in the scenario , only two objects ( TASK and XYZ__c ) are involved. I just want whenever new task is created , it should trigger new record in XYZ__c by taking the field values from TASK object and populating it to record in XYZ__c object.
I would really appreciate if you can tweak my slution and let me what I am missing
Thanks
I understood what you're saying. What I was recommending to you is based off the error you posted:
Apex trigger createleadinterest caused an unexpected exception, contact your administrator: createleadinterest: execution of AfterUpdate caused by: System.StringException: Invalid id: 2012 Fall: Trigger.createleadinterest: line 13, column 1
So, based off you're error message, the Task object's Enrollment_term__c is populated with the value: 2012.
The value 2012 is not a valid Salesforce Id, and that is why you can't populated it on the Term__c field of the XYZ__c object. So try to see if it's one of the following issues: