function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AbhijitAbhijit 

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

Message Edited by Abhijit on 09-21-2009 12:34 PM
CaptainObviousCaptainObvious

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.

AbhijitAbhijit
Ohh Sorry the name of trigger is SetPrimaryContact by mistake i renamed it . I am getting that error when i am assigning value to Project field .
JonSimmonsJonSimmons
The error "List index out of bounds: 0:" means that the index you have set doesn't exist.  In this case it means that your query for contactRole isn't returning any records