Write a trigger to update contact when accounts phone changed.

AnswerBot
2y

Trigger to update contact when accounts phone changed

  • Create a trigger on Account object

  • Query for related Contacts

  • Update Contact phone field with Account phone field value

Rudra Chauhan
2mo
hi
Anonymous
1y

trigger UpdatePhone on Account (after update) {

Map<Id,Account> accToPhoneMap = new Map<Id,Account>();

for(Account acc : Trigger.new){

if(acc.Phone != trigger.oldMap.get(acc.Id).Phone){

accToPhoneMap.put(acc.Id,acc);

}

List<Contact> relatedContact = [Select Id,Name,AccountId, Phone from Contact WHERE AccountId IN :accToPhoneMap.keySet()];

for(Contact con : relatedContact){

con.Phone = accToPhoneMap.get(con.AccountId).Phone;

}

}

}

Backseat Engineer
2y

trigger createContact on Account (before update) {

MAP<Id,Integer> oldMap=new MAP<Id, Integer>();

List<Contact> condetails =NEW List<Contact>();

For(Account acc:trigger.old){

oldMap.put(acc.Id, ...read more

Anonymous
2y

trigger updatedcontact on Account (After Insert){

List<Account> acclist = new List<Account>();

List<Contact Conlist = new List<Contact>();

for(Account acc : trigger.new)

{

if(acc.Phone != trigger.old...read more

reshu gupta
2y

trigger updatedcontact on Account (After Insert){

List<Account> acclist = new List<Account>();

List<Contact Conlist = new List<Contact>();

for(Account acc : trigger.new)

{

if(acc.Phone != trigger.old...read more

Aviral Srivastava
2d
REMEMBER NOT TO WRITE THE LOGIC INTO TRIGGER ITSELF!
Add answer anonymously...
Deloitte Salesforce Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter