Li Jun
2022-04-19 ced601e566d84624364f8e3a698eddd427a85f85
force-app/main/default/classes/RentalApplyController.cls
@@ -1,10 +1,3 @@
/**
 * @description       :
 * @author            : ChangeMeIn@UserSettingsUnder.SFDoc
 * @group             :
 * @last modified on  : 03-28-2022
 * @last modified by  : ChangeMeIn@UserSettingsUnder.SFDoc
**/
global without sharing class RentalApplyController {
    public String layoutSectionsStr {get; set;}//for dynamic add readonly attribute
    public List <LayoutDescriberHelper.LayoutSection > layoutSections{set;get;}
@@ -12,6 +5,7 @@
    public static Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    public static String sobjectTypeValue = 'Rental_Apply__c';
    public Boolean isNewMode{set;get;}
    public Boolean isCloneMode{protected set;get;}
    public String rtTypeId {get; set;}
    public String AWSDataId{set;get;}
    public List<String> encryptedAPIList{set;get;}   
@@ -30,19 +24,30 @@
    public RentalApplyController(ApexPages.StandardController controller) {
        ApiPrefix = 'PIBackApi';    
        isNewMode = true;
        isCloneMode = false;
        Input_Required_Field_Msg = Label.Input_Required_Field_Msg;
        PIPL_Input_Account_Error_Msg = label.PIPL_Input_Account_Error_Msg;
        //获取所有字段
        List<String> fieldList = new List<String>(Schema.getGlobalDescribe().get('Rental_Apply__c').getDescribe().fields.getMap().keyset());  
        Map<string,string> mso = ApexPages.currentPage().getParameters();
        if(mso != null && mso.containsKey('newclone')){
            isCloneMode = true;
        }
        if(!Test.isRunningTest()){
            controller.addFields(fieldList);
        }
        SObject obj = controller.getRecord();
        SObject obj = controller.getRecord();
        if(obj.Id != null){
            //更新
            isNewMode = false;
            Rental_Apply__c rentalApplyData = [select Id,RecordTypeId,AWS_Data_Id__c,Loaner_medical_Staff__c,Loaner_medical_Staff__r.AWS_Data_Id__c from Rental_Apply__c where id =: obj.Id];
            rtTypeId = rentalApplyData.RecordTypeId;
            //Update record type for Rental Apply by Li Jun 20220419 start
            if(ApexPages.currentPage().getParameters().containskey('RecordType')){
                rtTypeId = ApexPages.currentPage().getParameters().get('RecordType');
            }
            controller.getRecord().put('RecordTypeId',rtTypeId);
            //Update record type for Rental Apply  by Li Jun 20220419 end
            AWSDataId = rentalApplyData.AWS_Data_Id__c;
            Map<String,String> sfIdToAWSIdMap = new Map<String,String>();
            if(rentalApplyData.Loaner_medical_Staff__r.Id != null){
@@ -51,7 +56,7 @@
            contactsInfo = JSON.serialize(sfIdToAWSIdMap);
        }else{
            //新建
            Map<string,string> mso = ApexPages.currentPage().getParameters();
            // Map<string,string> mso = ApexPages.currentPage().getParameters();
            system.debug('mso='+mso);
            if(mso.containsKey('Name')){
                controller.getRecord().put('Name',mso.get('Name'));
@@ -80,9 +85,23 @@
            if(mso.containsKey('00N10000003OJzc')){
                controller.getRecord().put('Loaner_received_staff__c',mso.get('00N10000003OJzc'));
            }
            rtTypeId = ApexPages.currentPage().getParameters().get('RecordType');
            obj.put('OwnerId',UserInfo.getUserId());
        }
        if(mso.containsKey('00N10000003Mp2H')){
            system.debug('00N10000003Mp2H='+mso.get('00N10000003Mp2H'));
            controller.getRecord().put('Status__c',mso.get('00N10000003Mp2H'));
        }
        if(mso.containsKey('00N10000007oQKh')){
            system.debug('00N10000007oQKh='+mso.get('00N10000007oQKh'));
            controller.getRecord().put('Split_Apply_Reason__c',mso.get('00N10000007oQKh'));
        }
        system.debug('Rental Apply Record Type:'+rtTypeId);
        LayoutDescriberHelper.LayoutWrapper LayoutWrapperValue = LayoutDescriberHelper.describeSectionWithFieldsWrapper(rtTypeId, 'Rental_Apply__c','classic');
        layoutSections = LayoutWrapperValue.layoutSections;
        layoutSectionsStr = JSON.serialize(layoutSections); //for dynamic add readonly attribute
@@ -151,17 +170,26 @@
        Response resp = new Response();
        Savepoint sp = Database.setSavepoint();
        String rid = '';
        Boolean isClone = false;
        String awsDataId = '';
        try{
            System.debug('abcde');
            if(isNew){
            awsDataId = (String)rentalApplyInfo.get('AWS_Data_Id__c');
            System.debug('awsDataId = ' + awsDataId);
            Rental_Apply__c[] RentalApplys = [select id from Rental_Apply__c where AWS_Data_Id__c =:awsDataId];
            if(!isNew){
                isClone = RentalApplys.size() == 0;
            }
            if(isNew || isClone){
                System.debug('rentalApplyInfozhj = ' + rentalApplyInfo);
                insert rentalApplyInfo;
                System.debug('rentalApplyInfo.Id' + rentalApplyInfo.Id);
            }else{
                System.debug('into update');
                String awsDataId = (String)rentalApplyInfo.get('AWS_Data_Id__c');
                System.debug('awsDataId = ' + awsDataId);
                Rental_Apply__c[] RentalApplys = [select id from Rental_Apply__c where AWS_Data_Id__c =:awsDataId];
                // String awsDataId = (String)rentalApplyInfo.get('AWS_Data_Id__c');
                // System.debug('awsDataId = ' + awsDataId);
                // Rental_Apply__c[] RentalApplys = [select id from Rental_Apply__c where AWS_Data_Id__c =:awsDataId];
                System.debug('RentalApplys[0].id = ' + RentalApplys[0].id);
                rentalApplyInfo.put('Id',RentalApplys[0].id);//For testing;
                update rentalApplyInfo;