function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
raja subbu 1raja subbu 1 

plz help me i am new to this..what is c.phone and trigger.oldmap.get(c.accountid).phone) in below is it not same.plz explain plz

 for(Contact c:[selectid,accountid,phone,mailingstreet,mailingcity,mailingpostalcode,mailingcountry,mailingstate fromcontact where accountid in :trigger.new]) {
    account a = trigger.newmap.get(c.accountid);
    boolean updatedrecord = false;
   if(c.phone == trigger.oldmap.get(c.accountid).phone) {
      c.phone = a.phone;
      updatedrecord = true;
    }
Best Answer chosen by raja subbu 1
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi Raja,

As per the mentioned code

1.Firstly we are fetching all the contacts related to the updated accounts.
2.Then checking if the contacts have the same number as the account old number (before updating account) .If the contact phone number matches with the old number of account then we update the contact number with the latest account's phone number.

Let me explain you with example:
Account 'A' before update has phone Number 123456
After update has 3456789

then we firsly fetch contacts of the Account 'A' ,let it be c1 and c2.
if c1 phone number is same as '123456' then we update it to new number '3456789'.
similarly for contact c2.

This is how the code works.
Thanks
Bhargavi.

All Answers

Murali MattaMurali Matta
Hi Raja,

if(c.phone == trigger.oldmap.get(c.accountid).phone)  in this line you are comparing new phone with account old phone in account

Example: If you are editing a record detail page it is having old phone value as 987654321 and now you are updating phone value to 12345789. so, here you are checking new value to old value.


trigger.oldmap.get(c.accountid).phone) In this line you are getting previous value of phone for the passed account id.

Example: you are having an account id 001asd123MM now you are updating phone value for this account id. Here you are passing account id to get the old phone and comparing it with the new phone.

Let me know if you have any confusion.

Kindly mark this as solved if the reply was helpful.

Thanks,
Murali

Thanks.
Murali
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi Raja,

As per the mentioned code

1.Firstly we are fetching all the contacts related to the updated accounts.
2.Then checking if the contacts have the same number as the account old number (before updating account) .If the contact phone number matches with the old number of account then we update the contact number with the latest account's phone number.

Let me explain you with example:
Account 'A' before update has phone Number 123456
After update has 3456789

then we firsly fetch contacts of the Account 'A' ,let it be c1 and c2.
if c1 phone number is same as '123456' then we update it to new number '3456789'.
similarly for contact c2.

This is how the code works.
Thanks
Bhargavi.
This was selected as the best answer