Li Jun
2022-03-17 69dc5df6ec51f6f7f6737c61d9c4c1e7757a2b96
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
60
global class NewAndEditContactController extends NewAndEditBaseController 
{
    public String unifiedIContactID{set;get;}
    
    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
        controller.addFields(fieldList);
        Init(controller.getRecord());
        String contactId = controller.getRecord().Id;
        if(contactId != null){
            Contact c = [select UnifiedI_Contact_ID__c from Contact where Id =:contactId ];
            system.debug('Contact c = '+c);
            unifiedIContactID = c.UnifiedI_Contact_ID__c;
        }
 
    }
    
    PageReference RedirectStandardPage(){
        Map<string,string> mso = ApexPages.currentPage().getParameters();
        system.debug(mso);
        mso.remove('sfdc.override');
        PageReference pg = new PageReference('/003/e');
        mso.putAll(mso);
        pg.getParameters().put('nooverride','1');
        pg.setRedirect(true);
        return pg;
    }
 
    public PageReference PageLoad(){
        system.debug('rtTypeId='+rtTypeId);
        string s = null;
        
        if(!string.isBlank(rtTypeId)){
            s = Schema.SObjectType.Contact.getRecordTypeInfosById().get(rtTypeId).getDeveloperName();
            if(s == 'Agency' || s == 'Internal_staff'){
                return RedirectStandardPage();
            }
        }
        string accid = ApexPages.currentPage().getParameters().get('accid');
        if(!string.isBlank(accid)){
            List<Account> accs = [select RecordType.DeveloperName from account where id = :accid];
            if(accs.size()>0){
                s = accs[0].RecordType.DeveloperName;
                if(s == 'Office' || s == 'AgencyContact' || s == 'Agency'){
                    return RedirectStandardPage();
                }
            }
            
            
        }
        return null;
    }
    
    @RemoteAction
    global static Response saveContact(String leadJson,String transId,Boolean isNew) {
        return save(new Contact(),leadJson,transId,isNew);
    }
}