+ Start a Discussion

Trigger Please



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?






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();
    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.


First of all please define relationship between both objects. 


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

Thank you for the trigger. I will create this new trigger today. And will get back to you.
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