高章伟
2022-02-15 3871fb42959175bf233b673c0800a905f7274d59
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
55
56
57
58
59
public with sharing class CustContController {
    //合成url
    public String ccUrl { get; private set; }
    //两个用来拼接url
    public String accid { get; private set; }
    public String conid { get; private set; }
    //初始化
    public loaner_user__c lou { get; private set; }
    public loaner_user__c lu { get; private set; }
    //判断
    public String isOk {get; private set; }
 
    public CustContController() {
        accid = System.currentPageReference().getParameters().get('accid');
        conid = System.currentPageReference().getParameters().get('conid');
    }
 
    public void init(){
       
        lou = new loaner_user__c();
        List<Account> accList = new List<Account>();
        List<Contact> conList = new List<Contact>();
        if (String.isNotBlank(accid)) {
            accList = [select id from Account where id =: accid];    
        }
        if (String.isNotBlank(conid)) {
            conList = [select id from Contact where id =: conid];
        }
        
        if(accList.size() >0){
            lou.Customer__c = accid;
        }
 
        if(conList.size() > 0 ){
            lou.Contact__c = conid;
        }
    }
 
    public void getisOk(){
        isOk = '';
        //前台选的客户与联系人都可以取到他俩的id,选没选没关系,只需要查询比较他俩都被选中的情况下
        Contact cont = new Contact();
        if (String.isNotBlank(lou.Contact__c)) {
           cont = [select AccountId from Contact where id =:lou.Contact__c]; 
        }
        System.debug(cont.AccountId);
        if (cont.AccountId != null) {
           if (String.isNotBlank(lou.Customer__c) && String.isNotBlank(lou.Contact__c)) {
                isOk = cont.AccountId == lou.Customer__c ? '1' : '0';
           }
           if (String.isBlank(lou.Customer__c)) {
            isOk = '2';
           }
        }else if (String.isNotBlank(lou.Customer__c)){
            isOk = '1';
        }
        System.debug(isOk);
    }
}