liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
global with sharing class OCM_Ctrl2 {
    global Rental_Apply__c ra {get;set;}
    global Repair__c rp {get;set;}
    global Asset ast {get;set;}
    
    global OCM_Ctrl2(){
        if (!Test.isRunningTest()) {
            ra = new Rental_Apply__c(photoType__c='');
            rp = new Repair__c(photoType__c='');
            ast = new Asset(photoType__c='');
            string pid = ApexPages.currentPage().getParameters().get('pid') ;
            string objectName = SchemaGlobalDescribe.findObjectNameFromRecordIdPrefix(pid);
            SObject s = Database.query('SELECT recordTypeId FROM ' + objectName + ' where id=\''+pid+'\'');
            String recordTypeId = String.valueOf(s.get('recordTypeId'));
            System.debug('objectName='+objectName+'       recordTypeId='+recordTypeId);
            if(objectName == 'Rental_Apply__c'){
                ra.RecordTypeId = recordTypeId;
            } else if(objectName == 'Repair__c'){
                rp.RecordTypeId = recordTypeId;
            } else if(objectName == 'Asset'){
                ast.RecordTypeId = recordTypeId;
            }
        }
    }
    
}