buli
2022-04-08 b6f2c55d21463def425048aba48bed273156e9a9
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
/*
 * Author: Yanan Chen
 * Created Date: 02/22/2022
 * Purpose: Utility class for describe layouts
 * Test Class: NewAndEditContactController
 * History: 
 *      02/22/2022 - Yanan Chen - Initial Code.
 * 
 * */
global class NewAndEditContactController extends NewAndEditBaseController {
 
    public String accountId{get; set;}
    public Account account{get; private set;}
 
    public NewAndEditContactController(ApexPages.StandardController controller){
        
        List<String> fieldList = new List<String>(Schema.getGlobalDescribe().get('Contact').getDescribe().fields.getMap().keyset());  
        
        // Add fields to controller. This is to avoid the SOQL error in visualforce page
        //Get Account Id from url param
        this.accountId = ApexPages.currentPage().getParameters().get('retURL');
        System.debug('accountId = ' + accountId);
 
        // System.debug('accountType = ' + );
        if(!Test.isRunningTest()){
            controller.addFields(fieldList);
        }
        
        Init(controller.getRecord());
        
        if (this.accountId != '/003/o' && this.accountId != null && this.isNewMode) {
            ID accId = ID.valueOf(this.accountId.substring(1, this.accountId.length()));   
            System.debug('accId = ' + accId);
            
            account = [select id, Name, PhoneD__c, FaxD__c, Address1D__c, PostCodeD__c, ProductSegment__c from Account where id =:accId];
            System.debug('account = ' + account);
        }
 
        SObject obj = controller.getRecord();
        if(obj.Id == null){
            //初始化加载值
            obj.put('OwnerId',UserInfo.getUserId());
        }
 
        if (this.account != null) {
            obj.put('ProductSegment'+account.ProductSegment__c+'__c', true);
        }
        
        
    }
 
    
    @RemoteAction
    global static Response saveContact(String contactJson, String transId, Boolean isNew){
        return save(new Contact(), contactJson, transId, isNew);
    }
}