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
Rabbani sayyed 8Rabbani sayyed 8 

I have two objects, Account (Std) 2. Airports (Cstm) There is a field in Accounts called 'Airport Supplied' Question: i would to like retrieve multiple name of airports in the above field E.g.:Airport Supplied = Delhi, Goa, London, Paris? Any suggestions

I have two objects, Account (Std) 2. Airports (Cstm) There is a field in Accounts called 'Airport Supplied'  Question: i would to like retrieve multiple name of airports in the above field E.g.:Airport Supplied = Delhi, Goa, London, Paris Please provide the best advise
Nitin PaliwalNitin Paliwal
HI,
I am assuming airports has a lookup of account .

Now,Use this below code and make the necessary changes in the API names.

trigger updateAccountField on Aircraft__c (after insert,after update,after delete) {
 
  set<String> updatedAccountRecordIDs = new set<String>();
  list<Account> updateAccounts = new list<Account>();
  if(trigger.isInsert || trigger.isUpdate){
   for(Aircraft__c aircraft : trigger.new){
    if(trigger.old == null || trigger.oldMap.get(aircraft.Id).Account__c != aircraft.Account__c){
     updatedAccountRecordIDs.add(aircraft.Account__c);
    }
   }
  }
  if(trigger.isDelete){
   for(Aircraft__c aircraft : trigger.old){
    updatedAccountRecordIDs.add(aircraft.Account__c);
   }
  }
  for(Account acc : [select Id,Airport_Supplied__c,(Select Id,Name from Aircrafts__r) from Account Where Id In :updatedAccountRecordIDs]){
   string airports = '';
   for(Aircraft__c aircraft : acc.Aircrafts__r){
    if(airports == '') 
     airports = aircraft.Name;
    else
     airports += ','+aircraft.Name;
   }
   acc.Airport_Supplied__c = airports;
   updateAccounts.add(acc);
  }
  update updateAccounts;
 
}

Thanks
Nitin
 
Mudasir WaniMudasir Wani
Hello,

Use multipicklist field for "Airport Supplied" that is the best data type  you can use.

Thanks,
Mudasir