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, ...
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.
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);
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