You need to sign in to do that
Don't have an account?
Synthia B.
Apex Trigger: Insert Record in a custom object (related list)
I am not sure what is incorrect in this trigger. I am getting Error: Compile Error: unexpected token: 'for' at line 4 column 1
Scenario:
- After creating a new Opportunity
- Object Implementation should populate a list of 12 Records when save is clicked.
Scenario:
- After creating a new Opportunity
- Object Implementation should populate a list of 12 Records when save is clicked.
trigger IMP on Opportunity (after insert) { List <implementation__c> ImpToInsert = new List <implementation__c> for (Opportunity o : Trigger.new) { implementation__c rec = new implementation__c (Opportunity__c = o.id); ImpToInsert.add(rec); } database.saveResult[] sr = database.insert(impToInsert,false); for(integer x=0;x<sr.size();x++){ if(sr[x].isSuccess() == false) system.debug(logginglevel.error,sr[x].getErrors()[0].getMessage()); } }
All Answers
Please let us know if this will help you.
Thanks,
Amit Chaudhary
I am getting the following error with the corrected code.
Error: Compile Error: Invalid field Opportunity__c for SObject Implementation__c at line 6 column 68
Your last code worked however, after creating a new opportunity, the implementation object pulls one record type and it is an id.
The records types are listed in the implementation object.
--yvk