/* * Author: Bubba Li * Created Date: 02/08/2022 * Purpose: SearchContactController * Test Class: SearchContactController * History: * 02/08/2022 - Bubba Li - Initial Code. * * */ public without sharing class SearchContactController { public String searchKeyWord{set;get;} public String staticResource {get; set;} public String contactAWSIds {set;get;} public String contactsInfo {set;get;} public String PIPL_Search_Contact_Label{set;get;} public SearchContactController() { String accountId = ApexPages.currentPage().getParameters().get('accountId'); PIPL_Search_Contact_Label = Label.PIPL_Search_Contact_Label; //1. Query Contact by accountId List conList = new List(); system.debug('Account Id from Front-end:'+accountId); if(String.isNotBlank(accountId) && String.isNotEmpty(accountId)){ conList = new List([select Id,AWS_Data_Id__c from Contact where AccountId=:accountId and AWS_Data_Id__c!='']); } //2. Prepare the Contact Info Map awsIdToContactMap = new Map(); List conAWSIds = new List(); for(Contact con:conList){ conAWSIds.add(con.AWS_Data_Id__c); awsIdToContactMap.put(con.AWS_Data_Id__c,con); } contactsInfo = JSON.serialize(awsIdToContactMap); contactAWSIds = JSON.serialize(conAWSIds); staticResource = JSON.serialize(PIHelper.getPIIntegrationInfo('Contact')); } @RemoteAction public static Response searchContacts(String awsContactIds) { Response resp = new Response(); resp.status = 'fail'; if(String.isBlank(awsContactIds)||String.isEmpty(awsContactIds)){ return resp; } List awsDataIds = (List) JSON.deserialize(awsContactIds, List.class); Map awsIdToContactMapTemp = new Map(); List conListTemp = new List([select Id,AWS_Data_Id__c from Contact where AWS_Data_Id__c in:awsDataIds]); for(Contact con:conListTemp){ awsIdToContactMapTemp.put(con.AWS_Data_Id__c,con); } if(awsIdToContactMapTemp.keySet().size()>0){ resp.status = 'success'; resp.message = JSON.serialize(awsIdToContactMapTemp); } return resp; } public class Response{ public String message{set;get;} public String status{set;get;} } }