From 08a21f49f2eaf9cfc19ceb67b196cc36ba689305 Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期五, 13 五月 2022 20:52:25 +0800
Subject: [PATCH] FIxSWOPageIssue

---
 force-app/main/default/classes/SoapApi.cls |   66 +++++++++++---------------------
 1 files changed, 23 insertions(+), 43 deletions(-)

diff --git a/force-app/main/default/classes/SoapApi.cls b/force-app/main/default/classes/SoapApi.cls
index 16cb4b9..1846deb 100644
--- a/force-app/main/default/classes/SoapApi.cls
+++ b/force-app/main/default/classes/SoapApi.cls
@@ -5,13 +5,20 @@
     // https://developer.salesforce.com/forums/ForumsMain?id=906F000000092a6IAA
     private static Map<String, String> domainInstanceMap { get; private set; }
     static {
+        domainInstanceMap = new Map<String, String>();
+        domainInstanceMap.put('1', 'ap0');
+        domainInstanceMap.put('2', 'ap2');
+        domainInstanceMap.put('9', 'ap1');
+        domainInstanceMap.put('O', 'cs5');
+        domainInstanceMap.put('N', 'cs6');
+        domainInstanceMap.put('0', 'cs112');
         soap = new PartnerSoapSforceCom.Soap();
         soap.SessionHeader = new PartnerSoapSforceCom.SessionHeader_element();
         // This is important, give session id, to let the call work.
         soap.SessionHeader.sessionId = UserInfo.getSessionId();
-        soap.endpoint_x = URL.getSalesforceBaseUrl().toExternalForm() + '/services/Soap/u/33.0';
+        //system.debug('=========='+soap.SessionHeader.sessionId.subString(3, 4)); 
+        soap.endpoint_x = 'https://' + domainInstanceMap.get(soap.SessionHeader.sessionId.subString(3, 4)) + '-api.salesforce.com/services/Soap/u/33.0';
     }
-
     /*
     PartnerSoapSforceCom.DescribeLayoutResult dlr = SoapApi.describeLayout('Repair__c', null, new String[]{'01210000000QmS9'});
     System.debug('layoutId=' + dlr.layouts[0].id);
@@ -42,22 +49,14 @@
             layoutItem.layoutComponents.add(layoutComponent);
             return dlr;
         } else {
-            System.debug('=====1====='+sObjectType);
-        System.debug('=====2====='+recordTypeIds);
-        System.debug('=====3====='+layoutName);
             return soap.describeLayout(sObjectType, layoutName, recordTypeIds);
         }
     }
 
     // 绶ㄩ泦鐢ㄣ儸銈ゃ偤銇ㄣ伄闋呯洰銇� r,w,wm 銇儏鍫便倰 杩斻仚
     // Map銇伅銆丷ecordTypeId(18妗�) => {api鍚� => r,w,wm}
-    // 濡傛灉Object涓瀹氳褰曠被鍨嬶紝璇ユ柟娉曚笉鑳藉彇鍑哄搴旇褰曠被鍨嬬殑椤圭洰锛屼慨鏀瑰悗鏂规硶鍚嶏細getEditRWByRecordType --涓嬩竴涓柟娉�
     public static Map<String, Map<String, String>> getEditLayoutItemRW(String sObjectType, String[] recordTypeIds) {
-        System.debug('=====1====='+sObjectType);
-        System.debug('=====2====='+recordTypeIds);
         PartnerSoapSforceCom.DescribeLayoutResult dlr = describeLayout(sObjectType, null, recordTypeIds);
-         System.debug('=====1====='+sObjectType);
-        System.debug('=====2=====--------');
         Map<String, Map<String, String>> rtn = new Map<String, Map<String, String>>();
         for (Integer lidx = 0; lidx < dlr.layouts.size(); lidx++) {
             String recordTypeId = dlr.recordTypeMappings[lidx].recordTypeId;
@@ -67,8 +66,7 @@
             for (PartnerSoapSforceCom.DescribeLayoutSection section : dlr.layouts[lidx].editLayoutSections) {
                 for (PartnerSoapSforceCom.DescribeLayoutRow row : section.layoutRows) {
                     for (PartnerSoapSforceCom.DescribeLayoutItem item : row.layoutItems) {
-                        if (item.layoutComponents != null && item.layoutComponents.size() > 0
-                                && String.isBlank(item.layoutComponents[0].value) == false) {
+                        if (item.layoutComponents != null && item.layoutComponents.size() > 0 && String.isBlank(item.layoutComponents[0].value) == false) {
                             rtnInner.put(item.layoutComponents[0].value, 'r');
                             if (item.editableForUpdate) {
                                 rtnInner.put(item.layoutComponents[0].value, 'w');
@@ -83,39 +81,21 @@
         }
         return rtn;
     }
-
-    // 绶ㄩ泦鐢ㄣ儸銈ゃ偤銇ㄣ伄闋呯洰銇� r,w,wm 銇儏鍫便倰 杩斻仚
-    // Map銇伅銆丷ecordTypeId(18妗�) => {api鍚� => r,w,wm}
-    public static Map<String, Map<String, String>> getEditRWByRecordType(String sObjectType, String[] recordTypeIds) {
+    
+    // SObject銇甊ecordType銇繙銇樸仸銆丳icklist銇甐alue銈掓娊鍑�
+    public static List<String> getPicklistValueByRecordType(String sObjectType, String[] recordTypeIds, String picklistApi) {
         PartnerSoapSforceCom.DescribeLayoutResult dlr = describeLayout(sObjectType, null, recordTypeIds);
-        Map<String, Map<String, String>> rtn = new Map<String, Map<String, String>>();
-        //
-        Map<String, PartnerSoapSforceCom.DescribeLayout> layputMap = new Map<String, PartnerSoapSforceCom.DescribeLayout>();
-        for (PartnerSoapSforceCom.DescribeLayout layout : dlr.layouts) {
-            layputMap.put(layout.id, layout);
-        }
-        //for (Integer lidx = 0; lidx < dlr.layouts.size(); lidx++) {
-        for (Integer lidx = 0; lidx < dlr.recordTypeMappings.size(); lidx++) {
-            String recordTypeId = dlr.recordTypeMappings[lidx].recordTypeId;
-            Map<String, String> rtnInner = new Map<String, String>();
-            rtn.put(recordTypeId, rtnInner);
-            System.debug('recordTypeId=' + recordTypeId);
-            PartnerSoapSforceCom.DescribeLayout layout = layputMap.get(dlr.recordTypeMappings[lidx].layoutId);
-            //for (PartnerSoapSforceCom.DescribeLayoutSection section : dlr.layouts[lidx].editLayoutSections) {
-            for (PartnerSoapSforceCom.DescribeLayoutSection section : layout.editLayoutSections) {
-                for (PartnerSoapSforceCom.DescribeLayoutRow row : section.layoutRows) {
-                    for (PartnerSoapSforceCom.DescribeLayoutItem item : row.layoutItems) {
-                        if (item.layoutComponents != null && item.layoutComponents.size() > 0
-                                && String.isBlank(item.layoutComponents[0].value) == false) {
-                            rtnInner.put(item.layoutComponents[0].value, 'r');
-                            if (item.editableForUpdate) {
-                                rtnInner.put(item.layoutComponents[0].value, 'w');
-                            }
-                            if (item.required) {
-                                rtnInner.put(item.layoutComponents[0].value, 'wm');
-                            }
-                        }
+        List<String> rtn = new List<String>();
+        for (Integer i = 0; i < dlr.layouts.size(); i++) {
+            String recordTypeId = dlr.recordTypeMappings[i].recordTypeId;
+            PartnerSoapSforceCom.PicklistForRecordType[] ptrList =  dlr.recordTypeMappings[i].picklistsForRecordType;
+            for (Integer j = 0; j < ptrList.size(); j++) {
+                if (ptrList[j].picklistName == picklistApi) {
+                    PartnerSoapSforceCom.PicklistEntry[] pe = ptrList[j].picklistValues;
+                    for (Integer k = 0; k < pe.size(); k++) {
+                        rtn.add(pe[k].label);
                     }
+                    break;
                 }
             }
         }

--
Gitblit v1.9.1