Apex: customer360CommunicationsHelper
Tue Jan 16 2024 10:36:06 GMT+0000 (Coordinated Universal Time)
Saved by @FloLiman
public with sharing class customer360CommunicationsHelper { @AuraEnabled(cacheable=true) public static List<Map<String, String>> getCaseAccountContact(List<Id> caseId) { //Creating a new Map String to return the variables List<Map<String, String>> caseAccountContactList = new List<Map<String, String>>(); //SOQL querey to retrieved the Desired fields from the Case List<Case> relatedCases = [SELECT AccountId, ContactId, Account.Name, Contact.AlternativeBillingName__c, Contact.ContactPreferences__c, Contact.PreferredCommunicationFormat__c, Contact.Individual.HasOptedOutSolicit FROM Case WHERE Id IN :caseId LIMIT 1]; Case relatedCase = relatedCases[0]; //Checking if there is an AccountId and ContactId on the Case if (relatedCase.AccountId != null && relatedCase.ContactId != null) { //Creating a new Map String to add the fields onto Map<String, String> caseAccountContactMap = new Map<String, String>(); //All the desired fields are then put into the caseAccountContactMap caseAccountContactMap.put('AccountName', relatedCase.Account?.Name); caseAccountContactMap.put('AccountId', relatedCase.AccountId); caseAccountContactMap.put('ContactId', relatedCase.ContactId); caseAccountContactMap.put('ContactAlternativeBillingName', String.isBlank(relatedCase.Contact?.AlternativeBillingName__c) ? '' : relatedCase.Contact.AlternativeBillingName__c); caseAccountContactMap.put('ContactOpted', relatedCase.Contact?.Individual.HasOptedOutSolicit != null && relatedCase.Contact.Individual.HasOptedOutSolicit ? 'Opt Out' : ''); caseAccountContactMap.put('ContactPreferences', relatedCase.Contact?.ContactPreferences__c != null ? relatedCase.Contact.ContactPreferences__c : ''); caseAccountContactMap.put('PreferredCommunicationFormat', relatedCase.Contact?.PreferredCommunicationFormat__c != null ? relatedCase.Contact.PreferredCommunicationFormat__c : ''); //The caseAccountContactMap is added onto the caseAccountContactMap caseAccountContactList.add(caseAccountContactMap); } return caseAccountContactList; } }
Comments