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
prasanth kumarprasanth kumar 

trigger on case causing problem please help

if the new case origin is web then it should add to case team. But i am getting this error. 

  Error: Invalid Data. 
Review all error messages below to correct your data.
The page you submitted was invalid for your session. Please click Save again to confirm your change.

 
trigger casefromweb on Case (after insert) {
CaseTeamTemplate ctt = [Select Id From CaseTeamTemplate where Name = 'second case team' limit 1];
    for(case c1:trigger.new)
    {
       if(c1.Origin=='web')
        {
            CaseTeamTemplateRecord cttr = new CaseTeamTemplateRecord(TeamTemplateId = ctt.Id, ParentId = c1.ParentId);
upsert cttr;
        }
    }
    
}



 
Paul_BoikoPaul_Boiko
This error message means that your session has expired, so if you login to your org again and try to save this trigger it should work.
 
prasanth kumarprasanth kumar
i have done that one alos.    is there any error in the code ?
Paul_BoikoPaul_Boiko
I see one issue with this code (it's not bulkified): you need to do upsert outside of for loop:
 
trigger casefromweb on Case (after insert) {
CaseTeamTemplate ctt = [Select Id From CaseTeamTemplate where Name = 'second case team' limit 1];
    List<CaseTeamTemplateRecord > cttrs = new List<CaseTeamTemplateRecord >();
    for(case c1:trigger.new)
    {
       if(c1.Origin=='web')
        {
            CaseTeamTemplateRecord cttr = new CaseTeamTemplateRecord(TeamTemplateId = ctt.Id, ParentId = c1.ParentId);
            cttrs.add( cttr );
        }
    }
    upsert cttrs;
}
Other than that it looks good. I was able successfully save it in my org.