function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Giancarlo AmatiGiancarlo Amati 

how to populate a multipick list with no VF page

Hi Everyone,
every Opportunity has an Account linked to it. Every Account has a child (custom object) BCAccount record list. 1 Account can have multiple BCAccount records.

The opportunity has now a field BCAccountOpty which is a multi picklist field. 
I have created the following method in a Class:
 
public static Map<String, BCAccount__c> getBCAccountsForAccount(Set<Id> accountIds) {
      Map<String, BCAccount__c> bcaccountMap = new Map<String, BCAccount__c>();
    if(accountIds.size() > 0 ){
      for(BCAccount__c bcAccount : [Select Id, name, Account__c, recordTypeId, BCAccountId__c, Account__r.ownerId from BCAccount__c where Account__c in :accountIds ]){
        bcaccountMap.put(bcAccount.BCAccountId__c, bcAccount);
      }
      }
    return bcaccountMap;
    }

 
/*Builds the list of Available BCAcount from the Account.Id*/
public static void getBCAccounts(Opportunity optyObj) {
      Map<String, String> availableBCAccountsMap;
      Set<Id> accountIds = new Set<Id>();
      accountIds.add(optyObj.accountId);
      
        Map<String, BCAccount__c> bcAccountMap = getBCAccountsForAccount(accountIds);
        if(!bcAccountMap.isEmpty()){
          for(BCAccount__c bcAccount : bcAccountMap.values()){
            availableBCAccountsMap.put(bcAccount.BCAccountId__c, bcAccount.Name);
          }          
        }
    
    }
and one opportunity trigger which now looks like below. Now I need to populate the field "BCAccountOpty" when the opportunity is edited. 
I cannot figure out what I feel I need to build a 'for' loop over a List<SelectedOption> objects on the 'avlBCAccounts' variable. But what is the method to populate the actual BCAccountOpty field?


 
trigger OpportunityAvlbBCAccounts on Opportunity (after delete, after insert, after undelete, after update, before delete, before insert, before update) {

List<SelectOption> avlBCAccounts = new List<SelectOption>();

if(Trigger.isBefore){

        if(Trigger.isInsert || Trigger.isUpdate){
            Opportunity_GET_BCAccountUtils.getBCAccounts(trigger.new[0]);
            avlBCAccounts = Opportunity_GET_BCAccountUtils.getAvailableBCAccounts();
            for (List<SelectOption> c : avlBCAccounts) {
                 
            }
        }
    }
}

Thank you.

GC
 

ANUTEJANUTEJ (Salesforce Developers) 
Hi GC,

Were you able to resolve the issue??

Regards,
Anutej