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
Ashok S 7Ashok S 7 

how to solve the problem

Hi,
When i writing the trigger .In that trigger i write the Map
code
----------------------
trigger contactupdate on Contact (before update,After delete) 
{
  if(Trigger.isbefore && trigger.isupdate)
  {
      Map<Id,Account> my = new  Map<Id,Account>();
      //my = Trigger.newMap;
      list<contact>con = new list<contact>();
      list<contact> cons = [select id,phone,accountid from contact where accountid in:my.keySet()];
      for(contact c:cons)
      {
          c.phone = my.get(c.accountid).phone;
          con.add(c);
      }
      update con;
  }
    Map<Id,Account> deleteconn = new Map<Id,Account>();
        deleteconn = trigger.oldMap;
    if(Trigger.isAfter && Trigger.isdelete)
    {
         
      //list<contact>con = new list<contact>();
      list<contact> cons = [select id,phone,accountid from contact where accountid in:deleteconn.keySet()];  
        delete cons;
    }
}
when i save the following code it will display the error
Illegal assignment from Map<Id,Contact> to Map<Id,Account>
Best Answer chosen by Ashok S 7
N.V.V.L.Vinay KumarN.V.V.L.Vinay Kumar
Hi Ashok,

Instead of the following code.

Map<Id,Account> deleteconn = new Map<Id,Account>();
deleteconn = trigger.oldMap;

Map<Id,Contact> deleteconn = new Map<Id,Contact>();
deleteconn = trigger.oldMap;

Thanks & Regards,
N. Vinay Kumar.

All Answers

Chandra Sekhar CH N VChandra Sekhar CH N V
Your trigger is on Contact Object, so trigger.old map will capture all contactIds. Write it on Account object instead.
N.V.V.L.Vinay KumarN.V.V.L.Vinay Kumar
Hi Ashok,

Instead of the following code.

Map<Id,Account> deleteconn = new Map<Id,Account>();
deleteconn = trigger.oldMap;

Map<Id,Contact> deleteconn = new Map<Id,Contact>();
deleteconn = trigger.oldMap;

Thanks & Regards,
N. Vinay Kumar.
This was selected as the best answer
N.V.V.L.Vinay KumarN.V.V.L.Vinay Kumar
Hi Ashok,

my bad 

It's true what chnadra said.

Or if you ca elobarate your requirement, we can help you with exact solution.

Regards,
N. Vinay.