+ Start a Discussion
wcwill978wcwill978 

Opportunity trigger to update multi-picklist field on Account

I have about 10 fields on the opportunity page that are populated from a quote when a quote is set to primary. Anyways these are cureny fields for all our product classes. Everytime a part is purchased under that class the field is populated with the total value of product.

 

On the account screen I have a multi-picklist field (Products_Purchased__c) with the list of all products. I want to populate this picklist field everytime an opportunity is closed won and a value is entered on one of these fields. For example if I close an opportunity and there was $500 on the A-Series field on the opportunity I want A-Series to show on the Products_Purchased__c field on the account. 

 

So far I have this on the trigger:

 

trigger martCalcOpptyUpdateETSPurchasedonAcct on Opportunity (after insert, after update) {
List<Account> accsToUpdate = new List<Account>();

for(Opportunity opp : trigger.new)
{
    if (opp.StageName == 'Closed Won' && opp.A_Series__c > 0)
    accsToUpdate.add(new Account(Id = opp.Account.Id, ETS_Products_Purchased__c = 'A-Series'));
}
{
    if (opp.StageName == 'Closed Won' && opp.B_Series__c > 0)
    accsToUpdate.add(new Account(Id = opp.Account.Id, Products_Purchased__c = 'B-Series'));
}

if (accsToUpdate != null && !accsToUpdate.isEmpty())
Database.update(accsToUpdate);

}

 

Is there a way to colapse all the series and tell it to update the Products_Purchased field based on the field that has a value. An account can have multiple opportunities so we just want to show one value at a time so if we have 3 closed won opportunties all with A-Series purchased on the account screen i want to show only one A-Series, i think this will be taken care of by the multi-picklist.

 

Can some one help me expand this trigger to do what i'm looking for? Thank you.