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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
public with sharing class LexAgenceCopyPIController {
    //.客户人员的复制按钮
    @AuraEnabled
    public static Agency_Contact__c init(String recordId){
        Agency_Contact__c res = new Agency_Contact__c();
        try{
            res = [SELECT Id,Name,Department_Class__c,Contact__c,Agency_ID__c,
            Type__c,    Doctor_Division1__c,    Agency_Hospital__c,AWS_Data_Id__c
                FROM Agency_Contact__c 
                    WHERE Id=:recordId];
            return res;
        }
        catch (Exception e) {
            return null;
        }
    }
 
    //客户人员的复制按钮
    @AuraEnabled
    public static String init2(String recordId){
        String s='';
        try {
            String objectName = 'Contact'; // 要获取字段的对象名
            Map<String, Schema.SObjectType> globalDescribe = Schema.getGlobalDescribe();
            Schema.SObjectType objType = globalDescribe.get(objectName);
            if (objType != null) {
                Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
                Map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();
                s+='SELECT ';
                // 现在,fieldMap中包含了对象的所有字段信息
                for (String fieldName : fieldMap.keySet()) {
                    if(!fieldName.equals('id'))
                        s+=fieldName+',';
                }
 
                s=s.removeEnd(',');
                s+=' FROM Contact where id=\''+recordId+'\'';
                system.debug('SQL:'+s);
                List<Contact> opportunitys = Database.query(s);
                s='';
                if(opportunitys.size()>0){
                    system.debug('in!');
                    for (String fieldName : fieldMap.keySet()) {
                        String formaF=fieldMap.get(fieldName).getDescribe().getName();
                        if(opportunitys.get(0).get(fieldName)!=null&&!opportunitys.get(0).get(fieldName).equals('null'))
                            s+=formaF+'='+opportunitys.get(0).get(fieldName)+',';
                    }
                    s=s.removeEnd(',');
                    return s;
                }
            }
            return s;
        } catch (Exception e) {
            System.debug('lexCopyToBaseController init error:'+e.getMessage());
        }
        return s;
    }
 
    //客户的新建意向按钮
    @AuraEnabled
    public static List<Account> init3(String recordId){
        List<Account> res = new List<Account>();
        try{
            res = [SELECT Id,Name,Department_Class__c,Hospital_Name__c,Hospital__c,RecordTypeId,Department_Name__c,Hospital_ID__c
                        FROM Account 
                            WHERE Id=:recordId];
            return res;
        }
        catch (Exception e) {
            return null;
        }        
    }
    @AuraEnabled
    public static string typeid(){
        try {
            return Schema.SObjectType.Lead.getRecordTypeInfosByDeveloperName().get('Standard').getRecordTypeId();
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }
}