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
Steven Vawdrey 13Steven Vawdrey 13 

Update changes in rich text area field on Account to rich text area on Contact

I have created a custom rich text area field (called General Information) on the Account object and am successfully populating a rich text area field (also called General Information) on the Contact object. I would like:
  • To update the Contact General Information field anytime the Account General Information field is changed.
  • I would also like the field on the Contact object to remain editable--this value will eventually be populated on the Opportunity
  • Additionally, I would like ALL contacts associated with the Account to inherit the Account General Information value.
Is this possible? Any help or sample code would really be appreciated.
Best Answer chosen by Steven Vawdrey 13
Jasper WallJasper Wall
Use a process builder for this, and follow the steps given in 
https://help.salesforce.com/articleView?id=000213419&language=en_US&type=1

Here Account is the parent object and Contact is the child object.

Thanks,
Balayesu

All Answers

Jasper WallJasper Wall
Use a process builder for this, and follow the steps given in 
https://help.salesforce.com/articleView?id=000213419&language=en_US&type=1

Here Account is the parent object and Contact is the child object.

Thanks,
Balayesu
This was selected as the best answer
Steven Vawdrey 13Steven Vawdrey 13
Balayesu, Thank you so much for your help. The Process Builder worked and I’m pushing my text field from the Account to all Contacts as I’d hoped. I’m now trying to populate two fields based on changes made to the text field. I’ve created a text field called Last Modified By and a Date/Time field called Last Modified On. Whenever the General Information text field is changed (either text is modified/or deleted altogether), I would like to captue the user who did the modification along with the timestamp of when it was done. I created a workflow rule with the following formula: ISCHANGED(General_Information__c) But I can’t get the Field Update to populate the Last Modified By or Last Modified On fields. The Field Update forumula I tried: IF( ISCHANGED (General_Information__c ), $User.FirstName + " "+ " " +$User.LastName, NULL) does nothing. Can you tell me what I’m missing? I so appreciate your help! Steve
Jasper WallJasper Wall
Hi Steven,

To achieve this use a trigger, like this,
 
​trigger acctrigger on Account(after update) {
  Id=[SELECT Phone, Id FROM User WHERE Id = : UserInfo.getUserId()].Id;
   for(Account a:trigger.old){
    if(Trigger.oldMap.get(a.Id).generaltxt__c != Trigger.newMap.get(a.Id).generaltxt__c){
        a.lastmodifiedbytxt=Id;
        a.lastmodifiedtimetxt=System.datetime.now();
     }
  } 
}

Thanks,
Balayesu
 
Steven Vawdrey 13Steven Vawdrey 13
Jasper, I entered your code in the Apex Trigger but get the following error: Error: Compile Error: Variable does not exist: Id at line 2 column 5 Steve
Steven Vawdrey 13Steven Vawdrey 13
Questions regarding your last response:
  • What should I replace ID with?
  • What should I replace Phone with?
  • I think I have all of the other variables identified correctly
Sorry I'm not an experienced developer, so I'm still a little stuck.


trigger acctrigger on Account(after update) {
    Id=[SELECT Phone, Id FROM User WHERE Id = : UserInfo.getUserId()].Id;
    for(Account a:trigger.old){
        if(Trigger.oldMap.get(a.Id).GeneralInformation__c != Trigger.newMap.get(a.Id).GeneralInformation__c){
            a.Last_Modified_By__c=Id;
            a.Last_Modified_On=System.datetime.now();
        }
    }
}
Jasper WallJasper Wall
Hi Steven,
I forget to define Id in the code. you can remove phone in the sql statement,  just define ID like,
Id Id=[SELECT Id FROM User WHERE Id = : UserInfo.getUserId()].Id;

Thanks,
Balayesu

 
Steven Vawdrey 13Steven Vawdrey 13
So we're getting real close, and I so appreciate your help with this. The code in my Trigger is as follows:

trigger acctrigger on Account(After Update) {
  Id Id=[SELECT Id FROM User WHERE Id = : UserInfo.getUserId()].Id;
   for(Account a:trigger.old){
    if(Trigger.oldMap.get(a.Id).General_Information__c != Trigger.newMap.get(a.Id).General_Information__c){
        a.Last_modified_by__c=Id;
        a.Last_modified_on__c=System.datetime.now();
     }
  } 
}

It all compiles perfectly, but when I modify the General Information field I get the following error:
Error:Apex trigger acctrigger caused an unexpected exception, contact your administrator: acctrigger: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.acctrigger: line 5, column 1

I tried removing the "a.", the "__c), etc. with no luck. Do you see my syntax problems? I'm assuming it doesn't like line 6 either but it doesn't get that far.

Thanks again,
Steve