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
/*
 * Author:     Zhang,Heyang
 * Created Date: 06/06/2023
 * Purpose: When copying QIS, check whether the current record status allows replication
 * Test Class: LexQISCloneButtonControllerTest
 *
 * */
public with sharing class LexQISCloneButtonController {
    public LexQISCloneButtonController() {
 
    }
    @AuraEnabled
    public static Boolean checkStatus(String recordId){
        QIS_Report__c qis = [SELECT Id,QIS_Status__c FROM QIS_Report__c WHERE id =: recordId LIMIT 1];
        return qis.QIS_Status__c == '取消'? true : false;
    }
 
    @AuraEnabled
    public static sObject getClonedValues(Id recordId, String objectAPIName) {
        try {
            Map<String, Schema.SobjectType> schemaMap = Schema.getGlobalDescribe();
            Map<String, Schema.SObjectField> fieldMap = schemaMap.get(objectAPIName).getDescribe().fields.getMap();
            String soqlQuery = 'Select ';
            Schema.DescribeFieldResult fieldResult;
            Set<String> ignoreFields = new Set<String>{'createdbyid', 'lastmodifiedbyid', 'lastmodifieddate', 'createddate'};
            for(String s : fieldMap.keySet()) {
                if(!ignoreFields.contains(s)) {
                    fieldResult = fieldMap.get(s).getDescribe();
                    if(fieldResult.isCreateable() && !fieldResult.isUnique()) {
                        soqlQuery += s + ',';
                    }
                }
            }
        
            soqlQuery = soqlQuery.removeEnd(',');
            soqlQuery += ' FROM ' + objectAPIName + ' WHERE ID = \'' + recordId + '\'';
            System.debug('soqlQuery=======>' + soqlQuery);
            Sobject record = Database.query(soqlQuery);
            return record;
        } catch(Exception e) {
            return null;
        }
    }
}