• Amuktha Rao 19
  • NEWBIE
  • 0 Points
  • Member since 2016

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

I've got this trigger halfway there whereby it will update Opportunity Description with the Partner ID from the Partner on the related list. I only did it this way to make sure the value being returned was the one I wanted. Anyway, I need this to update a custom Partner Account look up field on the Account Object. (I'm new to this). Can anyone point me in the right direction in terms of what I need to do next?

 

trigger PopulatePartnerOnAccountFromList on Opportunity (before update) {
// THIS TRIGGER WILL OVERWRITE ANY PARTNER DEFINED IN THE FIELD Partner ON THE ACCOUNT OBJECT.
// SET THIS FIELD TO READ ONLY OR CHANGE THE FUNCTIONALITY BELOW TO AVOID DATA BEEING OVERWRITTEN BY MISTAKE...

   for (Opportunity o : Trigger.new) {
   
 


       // CREATE ARRAY OF ALL PARTNERS ON THIS OPPORTUNITY. THE REASON WHY WE DONT PICK THE PRIMARY PARTNER ONLY
       // IS BECAUSE THE PRIMARY FLAG IS NOT ALWAYS SET WHEN PARTNERS ARE ADDED TO OPPORTUNITIES. ONLY WHEN SALES DOES TIS
       // MANUALLY FROM THE RELATED LIST IS PRIMARY CHECKBOX CHECKED...


       OpportunityPartner[] PartnerArray =
       [select AccountToID, IsPrimary from OpportunityPartner where OpportunityId = :o.id ORDER BY isPrimary DESC, CreatedDate];
       if (PartnerArray.size() > 0) {
         
           // IF PRIMARY IS DEFINED THEN THIS WILL BE THE FIRST OBJECT. IF NOT THE FIRST ADDED CONTACT ROLE WILL BE ADDED...
           o.Description = PartnerArray[0].AccountToID;
          
       }else{
      
           // IF NO PARTNERS EXIST RETURN NULL...
           o.Description = null;
                 }
   }
 }