+ Start a Discussion
RickerRicker 

cross object trigger for field update

Hi I am trying to figure out to how trigger works for updating checkbox on Case object when checkboxfield of other custom object is set to true ,Lets say I have a custom field Required__c on Destination object and I have a Criteria__c  field on Case object, whenever required__c is true I want to update the criteria__c on case object to true , can anyone please guide me on this 

Thanks in advance
Best Answer chosen by Ricker
Shawn Reichner 29Shawn Reichner 29
Try the following code:

Without having all of yoru API names and etc, there may be syntax errors below, and if the c.add(d.CaseLookupField__c) give an error, try to add  .ID after the __c

Also you will want to place in yoru exact field api names if they are different, especially the CaseLookupfield.

Let us know if this helps you,

Shawn
 
trigger updateCase on Destination__c (after insert, after update) {

     List<Case> c = new List<Case>();

     for(Destination d : Trigger.new){
          If(d.Required__c == True){
              c.add(d.CaseLookupField__c);
          }
     }
     
     if(c.Size()>0){
     update c;
     }
}

 

All Answers

Shawn Reichner 29Shawn Reichner 29
Try the following code:

Without having all of yoru API names and etc, there may be syntax errors below, and if the c.add(d.CaseLookupField__c) give an error, try to add  .ID after the __c

Also you will want to place in yoru exact field api names if they are different, especially the CaseLookupfield.

Let us know if this helps you,

Shawn
 
trigger updateCase on Destination__c (after insert, after update) {

     List<Case> c = new List<Case>();

     for(Destination d : Trigger.new){
          If(d.Required__c == True){
              c.add(d.CaseLookupField__c);
          }
     }
     
     if(c.Size()>0){
     update c;
     }
}

 
This was selected as the best answer
RickerRicker
Thanks @shawn for your help