+ Start a Discussion
gopipatel_2610gopipatel_2610 

Apex trigger on opportunity update

Hi ,
 
I am trying to create an update trigger on opportunity. and if any opportunity is updated i wanted to merge all the partners in the given opprotunity in to a new custom field call merge_field.
 

I am new to apex. can anyone tell me how this is possible. and some sample code where i can start with.
 
Thanks,
 
Best Answer chosen by Admin (Salesforce Developers) 
gopipatel_2610gopipatel_2610
Hi ,
 
I am using the following code but it says "Partners_Merge_Field__C" does not exist. I have created that custom field. I can see in the sforce explorer but still it shows error. So do we have to set some diff properties for the custom field.
 
Also can you help me with the following code. What has to be changed. I wanted to merge all the AccoutTo.Name into the "Partners_Merge_Field__c"
 
Thanks,
 
 
trigger UpdateOpportunity  on Opportunity bulk (after update)
 {
      for (Opportunity opp : Trigger.new)
        {
             Id OppId;     
             OppId = opp.Id;
Partner[] ThisOppPartner = [select  AccountTo.Name  From Partner  WHERE OpportunityId = :OppId ];
for(Opportunity o: ThisoppPartner)
{
  Partners_Merge_Field__c = ThisoppPartner[];
   o.update(Partners_Merge_Field__c);
}
update;
 
}
}

All Answers

TehNrdTehNrd
A little more detail is required. Where are these partners?  Related list, on the opp, is it a text field?
gopipatel_2610gopipatel_2610
Yes these partners are on Opportunity. Actually its a child of Opportunity called OpportunityPartner
New custom field created is called "merge field" and its a text and this field is on opportunity.
 
So when ever any opportunity is updated I wanted to fire a trigger called (after update) which will merge all these partners which are in OpportunityPartner list into this custom field "merge field". Each partner in the merge field should be seperated by ";".
 
so for example
Here is the partners list
partner1
partner2
partner3
 
new merge field will look like this
partner1;partner2;partner3
 
 
Thanks,
gopipatel_2610gopipatel_2610
Hi ,
 
I am using the following code but it says "Partners_Merge_Field__C" does not exist. I have created that custom field. I can see in the sforce explorer but still it shows error. So do we have to set some diff properties for the custom field.
 
Also can you help me with the following code. What has to be changed. I wanted to merge all the AccoutTo.Name into the "Partners_Merge_Field__c"
 
Thanks,
 
 
trigger UpdateOpportunity  on Opportunity bulk (after update)
 {
      for (Opportunity opp : Trigger.new)
        {
             Id OppId;     
             OppId = opp.Id;
Partner[] ThisOppPartner = [select  AccountTo.Name  From Partner  WHERE OpportunityId = :OppId ];
for(Opportunity o: ThisoppPartner)
{
  Partners_Merge_Field__c = ThisoppPartner[];
   o.update(Partners_Merge_Field__c);
}
update;
 
}
}
This was selected as the best answer
Noob001Noob001
Hi, Did you figure this out? I am trying to do the same with a related list located on a custom objet. THanks!