• Elise Fantoni
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

This should be a relatively simple request I think, but I can't find another example that has the specifics I need.

 

I would like to update one object based on changes made to another object where one string is equivalent.  In this case, I have a custom object (Customobj__c) that has a trigger on it to update a case with fields from that custom object based on a field that they both have in common.  One of the fields I want to update is a multi-select picklist, too (Event_Types__c).  The primary weirdness I am encountering is that the multi-select picklist doesn't always update when I save the Custom Object record, but I also suspect my code isn't laid out efficiently.  Can anyone help?

 

Here's the code:

 

trigger OnCustobjCaseFields on Customobj__c (before insert, before update)
{
String objSharedField; String objRecordId; String objAccount; String objEventTypes; for(Customobj__c obj: Trigger.new) { if (obj.Shared_Field__c != Null) { objSharedField = obj.Shared_Field__c; objRecordId = obj.Id; objAccount = obj.Account__c; objEventTypes = obj.Event_Types__c; } } List<Case> cases = new List<Case>([SELECT Id, Shared_Field__c, AccountId, Expected_Event_Types__c FROM Case WHERE Shared_Field__c = :objSharedField]); List<Case> caseUpdateList = new List<Case>(); for(Case c: cases) { c.AccountId = objAccount; c.App__c = objRecordId; c.Expected_Event_Types__c = objEventTypes; caseUpdateList.add(c); } if(caseUpdateList.size() > 0) { update caseUpdateList; } }

 

  • September 30, 2013
  • Like
  • 0