Skip to main content Join the Agentforce Virtual Hackathon to build innovative solutions and compete for a $50k Grand Prize. Sign up now. Terms apply.

Marketplace is related to Asset (e.g., via a lookup or master-detail relationship). Related Lists    Asset is related to Account (e.g., via a lookup field like AccountId). Related Lists    Account has a field called Active Marketplace (Text Field)    When a Marketplace record is created or updated, update 'Active Marketplace' on the Account with comma separated values of all marketplaces.  Example : Active Marketplace = Marketplace 1,  Marketplace 2, demoMarketplace, ...   

1 件の回答
  1. 昨日、8:55

    Hi @Aditya Kiran Mishra

     

     

    You can update the

    Active Marketplace field with a comma-separated list of related Marketplace names using the following Apex snippet:

    apexCopyEditString activeMarketplace = String.join(marketplaceNamesList, ', ');

    This will ensure all related Marketplace

    names are combined into a single string with commas separating them. 

     

    Sample code logic is below. 

     

    Fetch all Marketplaces related to the Accounts

     

    for (Marketplace__c mp : [SELECT Id, Name, Asset__c FROM Marketplace__c WHERE Asset__c IN :assetToAccountMap.keySet()]) { 

            Id accountId = assetToAccountMap.get(mp.Asset__c); 

            if (!accountToMarketplaceNames.containsKey(accountId)) { 

                accountToMarketplaceNames.put(accountId, new List<String>()); 

            } 

            accountToMarketplaceNames.get(accountId).add(

    mp.Name

    ); 

     

    Update Active Marketplace field on Accounts

     

    for (Id accId : accountToMarketplaceNames.keySet()) { 

            Account acc = new Account(Id = accId); 

            acc.Active_Marketplace__c = String.join(accountToMarketplaceNames.get(accId), ', '); 

            accountsToUpdate.add(acc); 

        } 

     

        if (!accountsToUpdate.isEmpty()) { 

            update accountsToUpdate; 

        } 

     

    Thanks, 

    A. Gobinath

0/9000