@AuraEnabled
public static void updateContactAndAccountRecords(List<Map<String, Object>> updatedRecords) {
system.debug(updatedRecords + ' updatedRecords');
List<Contact> contactsToUpdate = new List<Contact>();
List<Account> accountsToUpdate = new List<Account>();
for (Map<String, Object> record : updatedRecords) {
if (record.containsKey('Id')) {
Contact c = new Contact();
c.Id = (String) record.get('Id');
if (record.containsKey('Phone')) {
c.Phone = (String) record.get('Phone');
}
contactsToUpdate.add(c);
}
if (record.containsKey('AccountId')) {
Account a = new Account();
a.Id = (String) record.get('AccountId');
Boolean hasOtherFields = false;
if (record.containsKey('AccountName')) {
a.Name = (String) record.get('AccountName');
hasOtherFields = true;
}
if (record.containsKey('AccountIndustry')) {
a.Industry = (String) record.get('AccountIndustry');
hasOtherFields = true;
}
if (record.containsKey('AccountShippingCountry')) {
a.ShippingCountry = (String) record.get('AccountShippingCountry');
hasOtherFields = true;
}
if (hasOtherFields) {
accountsToUpdate.add(a);
}
}
}
if (!contactsToUpdate.isEmpty()) {
update contactsToUpdate;
}
if (!accountsToUpdate.isEmpty()) {
update accountsToUpdate;
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter