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
nitin sharmanitin sharma 

Error on case Trigger


Hi All,

I am working on the case trigger which will update an acount object.I just started and got the folowing error.Can somebody help?
In the below given code I am assigning accountid to the map and along with the acocuntid I am trying to the add the complete record in map.However,When I
do that I get the following error.I want to use map here so I will appreciate if somebody can correct this error.I do not want ot use set or list here.

Method does not exist or incorrect signature: [MAP<String,Case>].add(Id, SOBJECT:Case) at line 7 column 18

Trigger UpaatingPicklist on Case (After insert,after update)
{
    Map<String,case> cap=new Map<String,case>();
        for(case c:trigger.new)
            {
           
                 cap.add(c.accountid,c);
                
            }
}
Justin ManchesterJustin Manchester
The only thing that stands out is "cap.add(..,..);" I was not running into any issues replacing this with "cap.put(c.AccountId,c);"
I also swapped a few other thing such as the map keys:

trigger UpatingPicklist on Case (After insert,After update)
{
    Map<ID,sObject> cap=new Map<ID,sObject>();
        for(Case c:trigger.new)
            {
                 cap.put(c.accountid,c);
               
            }
}

Let me know if that helped.
Cheers,