| | |
| | | // 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'); |
| | | 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); |
| | |
| | | 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には、RecordTypeId(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; |
| | |
| | | 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'); |
| | |
| | | } |
| | | return rtn; |
| | | } |
| | | |
| | | // 編集用レイズとの項目の r,w,wm の情報を 返す |
| | | // Mapには、RecordTypeId(18桁) => {api名 => r,w,wm} |
| | | public static Map<String, Map<String, String>> getEditRWByRecordType(String sObjectType, String[] recordTypeIds) { |
| | | |
| | | // SObjectのRecordTypeに応じて、PicklistのValueを抽出 |
| | | 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; |
| | | } |
| | | } |
| | | } |