buli
2022-05-14 ead4df22dca33a867279471821ca675f91dec760
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
public with sharing class StageProgressBarExtension {
    public String targetId { get; set; }
    public String targetStageName { get; set; }
    public String recordTypeName { get; private set; }
    public List<String> stages { get; set; }
    
    public StageProgressBarExtension(ApexPages.StandardController controller) {
        Opportunity opp = [select RecordTypeId, RecordType.DeveloperName from Opportunity where Id = :controller.getRecord().Id];
        recordTypeName = opp.RecordType.DeveloperName;
        
        stages = SoapApi.getPicklistValueByRecordType('Opportunity', new String[]{opp.RecordTypeId}, 'StageName');
        /*
        stages = new List<String>();
        PartnerSoapSforceCom.DescribeLayoutResult dlr = SoapApi.describeLayout('Opportunity', null, new String[]{opp.RecordTypeId});
        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 == 'StageName') {
                    PartnerSoapSforceCom.PicklistEntry[] pe = ptrList[j].picklistValues;
                    for (Integer k = 0; k < pe.size(); k++) {
                        stages.add(pe[k].label);
                    }
                    break;
                }
            }
        }
        */
    }
    
    public void updateOpp() {
        Opportunity opp = new Opportunity(
            Id = targetId,
            StageName = targetStageName
        );
        StaticParameter.StageProgressBarUpdate = True;
        update opp;
    }
}