You need to sign in to do that
Don't have an account?
Vignesh Ramshetty
geeting error Variable does not exist: Phone at line 16 column 59
Public class accountrecord {
Public static void making(List<Account> varacc){
Map<Id,Account> varmap = new Map<Id,Account>();
List <Contact> listcontact = new List <Contact>();
for(Account vara :varacc ){
if (vara.Phone != trigger.oldMap.get ( vara.id ).Phone){
varmap.put(vara.id,vara);
}
}
if(varmap.size() > 0){
listcontact = [SELECT AccountId, phone FROM Contact Where AccountId in: varmap.keyset() ];
if(listcontact.size() > 0){
for(Contact con : listcontact ){
con.Phone = varmap.get(con.AccountId).phone;
}
update listcontact ;
}
}
}
}
Public static void making(List<Account> varacc){
Map<Id,Account> varmap = new Map<Id,Account>();
List <Contact> listcontact = new List <Contact>();
for(Account vara :varacc ){
if (vara.Phone != trigger.oldMap.get ( vara.id ).Phone){
varmap.put(vara.id,vara);
}
}
if(varmap.size() > 0){
listcontact = [SELECT AccountId, phone FROM Contact Where AccountId in: varmap.keyset() ];
if(listcontact.size() > 0){
for(Contact con : listcontact ){
con.Phone = varmap.get(con.AccountId).phone;
}
update listcontact ;
}
}
}
}
I have updated the code can you try this.
Trigger:
Apex Class:
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
Do you have phone field in Account. If so can you share the API name of that field.
Thanks,
Your code is in Handler and the handler does not know trigger.oldMap. Can you share the trigger so can help you on both .
Thanks,
if(trigger.isafter == true && trigger.isupdate == true ){
accountrecord.making(trigger.new);
}
Apex Class :
Public class accountrecord {
Public static void making(List<Account> varacc){
Map<Id,Account> varmap = new Map<Id,Account>();
List <Contact> listcontact = new List <Contact>();
for(Account vara :varacc ){
if (vara.Phone != trigger.oldMap.get ( vara.id ).Phone){
varmap.put(vara.id,vara);
}
}
if(varmap.size() > 0){
listcontact = [SELECT AccountId, phone FROM Contact Where AccountId in: varmap.keyset() ];
if(listcontact.size() > 0){
for(Contact con : listcontact ){
con.Phone = varmap.get(con.AccountId).phone;
}
update listcontact ;
}
}
}
}
I have updated the code can you try this.
Trigger:
Apex Class:
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,