public with sharing class SearchContactForAgencyOppController { public String accountId{set;get;} public String searchKeyWord{set;get;} public String staticResource {get; set;} public String ObjectTypeLabel {get; set;} public String contactAWSIds {set;get;} public String domId {set;get;} public SearchContactForAgencyOppController() { accountId = ApexPages.currentPage().getParameters().get('hosId'); searchKeyWord = ApexPages.currentPage().getParameters().get('keyword'); domId = ApexPages.currentPage().getParameters().get('domId'); ObjectTypeLabel = Schema.getGlobalDescribe().get('Agency_Contact__c').getDescribe().getLabel(); staticResource = JSON.serialize(PIHelper.getPIIntegrationInfo('Agency_Contact__c')); List conList = [SELECT Id,Name,AWS_Data_Id__c,Hospital_Name__c,Type__c,Doctor_Division1__c FROM Agency_Contact__c WHERE Agency_Hospital__c = :accountId]; List conAWSIds = new List(); for(Agency_Contact__c con:conList){ conAWSIds.add(con.AWS_Data_Id__c); } contactAWSIds = JSON.serialize(conAWSIds); } @RemoteAction public static List searchContacts(String awsResult,String keyword,String hosId) { if(String.isBlank(keyword)){ return null; } List awsData = new List(); Map awsIdMap = new Map(); if(String.isNotBlank(awsResult)){ awsData = (List)JSON.deserialize(awsResult,List.class); if(awsData == null || awsData.size() == 0){ return null; } for(AwsData cus : awsData){ awsIdMap.put(cus.dataId,cus); } } List conList = [SELECT Id,Name,AWS_Data_Id__c,Hospital_Name__c,Type__c,Doctor_Division1__c FROM Agency_Contact__c WHERE AWS_Data_Id__c IN :awsIdMap.keySet() AND Agency_Hospital__c = :hosId]; for(Agency_Contact__c con : conList){ con.Name = awsIdMap.get(con.AWS_Data_Id__c).name; con.Type__c = awsIdMap.get(con.AWS_Data_Id__c).type; con.Doctor_Division1__c = awsIdMap.get(con.AWS_Data_Id__c).doctorDivision1; } //get Contact No PI List conListNoPi = [SELECT Id,Name,Hospital_Name__c,Type__c,Doctor_Division1__c FROM Agency_Contact__c WHERE Name LIKE :keyword]; conList.addAll(conListNoPi); return conList; } public class AwsData{ public String dataId{set;get;} public String name{set;get;} public String sfRecordId{set;get;} public String type{set;get;} public String doctorDivision1{set;get;} } }