+ Start a Discussion
Ryan BobadillaRyan Bobadilla 

Trying to pull Partner from PartnerOpportunity Object (related list on Opp) into lookup field on Opportunity... Not executing...please help :(


Here is the trigger that was created... pleass help!!

trigger UpdatePartnerOpportunity on Opportunity (before insert, before update) {

   for (Opportunity o : Trigger.new) {


                       System.debug(' output inside ' + o);

       OpportunityPartner[] PartnerArray = 
       [select AccountToID, IsPrimary from OpportunityPartner where OpportunityId = :o.id ORDER BY isPrimary DESC, CreatedDate];
                              System.debug(' PartnerArray ' + PartnerArray);

       if (PartnerArray.size() > 0) {
                     List<Opportunity> AccountArray = [select id,Partner_on_Opportunity__c from Opportunity where Id = :o.AccountId ];
           for (Opportunity a: AccountArray ){
                       System.debug(' output inside' + o.Partner_on_Opportunity__c);
            update o;
           o.Description = 'No Partner';
           System.debug(' Output else statement' + o.Description);
anto nirmalanto nirmal
Hi Ryan,

It would be helpful if you share the error message as well.
But still I noted a few keys things in your code.

Update and Insert events should be handled seperately when you are updating the record.
And you need not update the object in the before update event, because anyway the record gets updated.

Anto Nirmal