You need to sign in to do that
Don't have an account?

write a test class for the map?
public class Task14 {
public static void beforeupdate(Map<id,Account> oldmap,Map<id,Account> newmap){
list<id> accid=new list<id>();
for(id key:oldmap.keySet()){
Account old=oldmap.get(key);
Account newmp=newmap.get(key);
if(old.Phone!=newmp.Phone){
accid.add(key);
}
}
list<Contact> con=[select lastname,firstname,phone,accountid from Contact where accountid in:accid];
for(Contact c:con){
Account a=newmap.get(c.accountid);
Account b=oldmap.get(c.accountid);
c.Phone=a.Phone;
c.OtherPhone=b.phone;
}
update con;
}
}
==========================================================
trigger Task14Trigger on Account (before update) {
if(trigger.isbefore && trigger.isupdate){
Task14.beforeupdate(Trigger.oldmap, Trigger.newmap);
}
}
====================================================================
public static void beforeupdate(Map<id,Account> oldmap,Map<id,Account> newmap){
list<id> accid=new list<id>();
for(id key:oldmap.keySet()){
Account old=oldmap.get(key);
Account newmp=newmap.get(key);
if(old.Phone!=newmp.Phone){
accid.add(key);
}
}
list<Contact> con=[select lastname,firstname,phone,accountid from Contact where accountid in:accid];
for(Contact c:con){
Account a=newmap.get(c.accountid);
Account b=oldmap.get(c.accountid);
c.Phone=a.Phone;
c.OtherPhone=b.phone;
}
update con;
}
}
==========================================================
trigger Task14Trigger on Account (before update) {
if(trigger.isbefore && trigger.isupdate){
Task14.beforeupdate(Trigger.oldmap, Trigger.newmap);
}
}
====================================================================
Please check once sample code below :
Hope this helps.
Please check once and let me know in case of any help.
Thanks
Varaprasad
All Answers
Please check once sample code below :
Hope this helps.
Please check once and let me know in case of any help.
Thanks
Varaprasad
Please try this piece of code .
Hope it's help you.
Regards
Suraj
Kindly mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.
Thanks
Varaprasad
public static void updateOpportunityCity(List<Account> newList, Map<Id,Account> oldMap)
{
Map<Id,Account> accIdToMap=new Map<Id,Account>();
List<Opportunity> OppList=new List<Opportunity>();
for(Account acc: newList)
{
if(oldMap!=null && acc.City__c!=oldMap.get(acc.Id).City__c)
{
accIdToMap.put(acc.Id,acc);
}
}
for(Opportunity opp :[Select Id,AccountId,City__c From Opportunity Where AccountId IN :accIdToMap.keySet()])
{
if(accIdToMap.containsKey(opp.AccountId))
{
opp.City__c=accIdToMap.get(opp.AccountId).City__c;
oppList.add(opp);
}
}
if(!oppList.isEmpty())
{
update oppList;
}
}