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
sclosesclose 

Trigger Please

Hi.

 

Looking for help. I have a custom object with a custom field called Project Owner. I have another custom object with a custom field called Company. When company field is updated I want that date to populate in Project Owner field. Any suggestions?

 

Thanks,

SC

 

SamReadySamReady

Try this:

 trigger UpdateCompany on CustomObj__c (before update) {
    List<OtherObj__c> projOwnerList = new List<OtherObj__c>();
    
    for(CustomObj__c x : trigger.new){
        CustomObj__c xOld = trigger.oldMap.get(x.Id);
        if(x.Company__c != null){
            if(x.Company__c != xOld.Company__c){
        		x.OtherObj__r.ProjectOwner__c = date.Today();
            	projOwnerList.add(x.OtherObj__c);
            }
        }
    }
    
    update projOwnerList;
}

It only covers the update condition, but if you were checking for after insert as well, you would just need the if x.Company__c != null case without the nested condition after.

sandeep@Salesforcesandeep@Salesforce

First of all please define relationship between both objects. 

SamReadySamReady

I had made the assumption that the two objects were simply directly related (one ot many relationship). Did my solution meet your requirements?

sclosesclose
Thank you for the trigger. I will create this new trigger today. And will get back to you.
sclosesclose
After looking deeper I discovered there is 2 fields. When these 2 fields are populated with data together the project owner should be populated. See below.

A. Custom object named Project.
Custom field named Project Owner = Agency Name

B. Custom object named MCHN Role
1. Custom field name Company = Agency Name
2. Custom field name Role Type = Owner (Public)
When 1 and 2 match this should populate on the Project object custom field Project Owner