You need to sign in to do that
Don't have an account?
Apex Trigger
I am missing a processing step regarding Apex Triggers. I am attempting to create a trigger for the Account object. The logic is validating that the text field TrackerOrgType__c is not null then append the string to the multi select field Organization_Type__c field. Currently the error ,"Apex trigger AccountOrgUpdate caused an unexpected exception, contact your administrator: AccountOrgUpdate: execution of AfterUpdate caused by: System.ListException: List index out of bounds: 1: Trigger.AccountOrgUpdate: line 4, column 28". I am not sure why the list is out of bounds when I am only working with 1 record. Would anyone like to shed some light on this?
trigger AccountOrgUpdate on Account (after insert, after update) { //Organization Type //TrackerOrgType Account ac = trigger.new[1]; if (ac.TrackerOrgType__c != null){ ac.Organization_Type__c = ';'+ac.TrackerOrgType__c; } }
Use before instead of after in trigger like this (before insert, before update)
try this
All Answers
Try this,
Use this instead
Butthis trigger of your will work only for single record, if you want to write it for bulk use this
Now I am getting the error, "Review all error messages below to correct your data.
Apex trigger AccountOrgUpdate caused an unexpected exception, contact your administrator: AccountOrgUpdate: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.AccountOrgUpdate: line 15, column 4" when I attempt to use
Use before instead of after in trigger like this (before insert, before update)
try this
The reason for this is in after trigger trigger.new is not updatable.
That makes perfect since, but now I discovered it is overwriting the Organization_Type__c field where as I was attempting to append. Is there a way to accomplish this?
I found that I can read in the Organization_Type__c into a Stirng variable and then reassign the Organization_Type__c field the variable plus the Tracker_Org_type__c.