Write a trigger to update contact when accounts phone changed.

AnswerBot
1y

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

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 oldMap=new MAP();

List condetails =NEW List();

For(Account acc:trigger.old){

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

Anonymous
2y

trigger updatedcontact on Account (After Insert){

List acclist = new List();

List();

for(Account acc : trigger.new)

{

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

reshu gupta
2y

trigger updatedcontact on Account (After Insert){

List acclist = new List();

List();

for(Account acc : trigger.new)

{

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

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
Get AmbitionBox app

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