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
crob1212crob1212 

Field Update Help

I have a checkbox on the case object that, when checked, I want to put a check in another checkbox on a custom object.  I can't do this through workflow b/c of the relationship between the Cases object and the custom object.  So I'm assuming that the best way to do this is via a trigger, which I've never done but am eager to learn.  Basically, it needs to do this:

(Preface: the case will be entered from a record in a custom object called Request; and will, therefore, be related to the Request.)

If Hold_Addressed__c (custom field on Cases object)=TRUE,  then look at the request with which the case is related and update Hold__c (custom field on the Request object) to TRUE.

 

Any suggesstions are appreciated.

 

Thanks

Message Edited by crob1212 on 01-03-2010 11:35 PM
AcronymAcronym

I would create an after update trigger on the case object and update your field from there.  If might look something like this:

 

 

trigger updateRequestHold on Case (after update, after insert) { Map<String, Case> requestIds = new Map<String, Case>(); for (Integer i=0;i<trigger.new.size();i++) { Case newCase = trigger.new[i]; // See if the case has a related request if (newCase.Request__c != null) { // If it is an insert then we will add the request id if (trigger.isInsert) { requestIds.put(newCase.Request__c, newCase); } else { // Make sure the Hold_Addressed__c field has actually changed Case oldCase = trigger.old[i]; if (newCase.Hold_Addressed__c != oldCase.Hold_Addressed__c) { requestIds.put(newCase.Request__c, newCase); } } } } if (requestIds.size() > 0) { List<Request__c> reqsToUpdate = [Select Hold__c, Id From Request__c Where Id in :requestIds.keySet()]; for (Request__c r : reqsToUpdate) { r.Hold__c = requestIds.get(r.Id).Hold_Addressed__c; } update reqsToUpdate; } }