Li Jun
2022-03-24 f127c76b19f5316032d4bed127a1dde710c48d74
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
public without sharing class SearchLeadController {
    public String searchKeyWord{set;get;}
    public String staticResource {get; set;}
    public String leadAWSIds {set;get;}
    public String leadsInfo {set;get;}
    public String PIPL_Search_Contact_Label{set;get;}
    public SearchLeadController() {
        // String accountId = ApexPages.currentPage().getParameters().get('accountId');
        searchKeyWord = ApexPages.currentPage().getParameters().get('searchLeadKeyWord');//add by Li Jun 20220321
        PIPL_Search_Contact_Label = Label.PIPL_Search_Contact_Label;
        //1. Query Contact by accountId
        List<Lead> leadList = new List<Lead>();
        // system.debug('Account Id from Front-end:'+accountId);
        // if(String.isNotBlank(accountId) && String.isNotEmpty(accountId)){
        //     leadList = new List<Lead>([select Id,AWS_Data_Id__c from Lead where AccountId=:accountId and AWS_Data_Id__c!='']);
        // }    
        leadList = new List<Lead>([select Id,AWS_Data_Id__c from Lead where AWS_Data_Id__c!='']);    
        //2. Prepare the Contact Info
        Map<String,Lead> awsIdToLeadMap = new Map<String,Lead>();
        List<String> leAWSIds = new List<String>();
        for(Lead le:leadList){
            leAWSIds.add(le.AWS_Data_Id__c);
            awsIdToLeadMap.put(le.AWS_Data_Id__c,le);
        }
        leadsInfo = JSON.serialize(awsIdToLeadMap);
        leadAWSIds = JSON.serialize(leAWSIds);
        staticResource = JSON.serialize(PIHelper.getPIIntegrationInfo('Lead'));        
    }
 
    @RemoteAction
    public static Response searchLeads(String awsLeadIds) {
        Response resp = new Response();
        resp.status = 'fail';
        if(String.isBlank(awsLeadIds)||String.isEmpty(awsLeadIds)){
            return resp;
        }
        List<String> awsDataIds = (List<String>) JSON.deserialize(awsLeadIds, List<String>.class);
        Map<String,Lead> awsIdToLeadMapTemp = new Map<String,Lead>();
        List<Lead> leadListTemp = new List<Lead>([select Id,AWS_Data_Id__c from Lead where AWS_Data_Id__c in:awsDataIds]);
        for(Lead le:leadListTemp){
            awsIdToLeadMapTemp.put(le.AWS_Data_Id__c,le);
        }
        if(awsIdToLeadMapTemp.keySet().size()>0){
            resp.status = 'success';
            resp.message = JSON.serialize(awsIdToLeadMapTemp);
        }
        return resp;
    }
 
    public class Response{
        public String message{set;get;}
        public String status{set;get;}
    }
}