trigger contactupdate on Opportunity (after insert,after update) {
List<Contact> lstConToUpdate = new List<Contact>();
Map<id,string> accids = new Map<id,string>();
for(Opportunity opp : Trigger.new)
{
accids.put(opp.AccountId,opp.Phone__c);
}
List<Contact> listCon =[select id,name,AccountId,phone from contact where Accountid=:accids.keyset()];
for(contact con: listCon)
{
if(accids.containsKey(con.AccountId))
{
con.Phone = accids.get(con.AccountId);
lstConToUpdate.add(con);
}
}
if(lstConToUpdate.size() > 0)
{
update lstConToUpdate;
}
}
List<Contact> lstConToUpdate = new List<Contact>();
Map<id,string> accids = new Map<id,string>();
for(Opportunity opp : Trigger.new)
{
accids.put(opp.AccountId,opp.Phone__c);
}
List<Contact> listCon =[select id,name,AccountId,phone from contact where Accountid=:accids.keyset()];
for(contact con: listCon)
{
if(accids.containsKey(con.AccountId))
{
con.Phone = accids.get(con.AccountId);
lstConToUpdate.add(con);
}
}
if(lstConToUpdate.size() > 0)
{
update lstConToUpdate;
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.