You need to sign in to do that
Don't have an account?
Trigger Error
Hi,
Scenario : I have custom object called SFDC_Project__c which has look up to cases through Case__c field.
When i create case and through same detail page through related list if i click New Project, i want to copy value of Trigger_Value field from cases to project Cases_Trigger_Value__c after clicking save.
I have written trigger on project:
trigger SetPrimaryContact on SFDC_Project__c (before insert)
{
for (SFDC_Project__c o : Trigger.new)
{
List<Case> contactRole = new List<Case>();
contactRole = [select ID, Trigger_Value__c from Case where Id = :o.Case__r.id limit 1];
o.Cases_Trigger_Value__c = contactRole[0].Trigger_Value__c;
insert o;
}
}
Once i save i get error :
Error: Invalid Data. Review all error messages below to correct your data.
Apex
trigger SetPrimaryContact caused an unexpected exception, contact your
administrator: SetPrimaryContact: execution of BeforeInsert
caused by: System.ListException: List index out of bounds: 0:
Trigger.SetPrimaryContact: line 8, column 47
Any help will be appriciated .
Thanks & Regards,
Abhijit
From your error log, it looks like there's another trigger that is causing the error:
Apex trigger SetPrimaryContact caused an unexpected exception
Additionally, because your SetCaseValue trigger runs before insert, you do not need the insert o; DML statement.