liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
public with sharing class LexStockCancelController {
    public LexStockCancelController() {
        
    }
    @AuraEnabled
    public static Opportunity init(String recordId){
        try{
            Opportunity item=[select 
             Stock_cancel_reason__c,Whether_Upload_Question_Document__c
             from Opportunity
             where id = :recordId];
            return item;
 
        }catch(Exception e){
            System.debug('LexStockCancelController init error: '+e.getMessage());
        }
        return null;
    }
 
    @AuraEnabled
    public static UpdateResult updateOppotunity(        
        String recordId,
        String stStatus
    ) {
        UpdateResult result = new UpdateResult();
        result.recordId = recordId;
        try{
            Opportunity op=new Opportunity(id=recordId);
            if(stStatus!=null&&stStatus!=''){
                op.Stock_apply_status__c= stStatus;
            }
            update op;
            result.success = true;
            result.errors = new List<String>();
            return result;
        }catch(Exception e){
            result.success = false;
            result.errors = new List<String>();
            if(e.getMessage().contains(':')){
                String eMessage =e.getMessage();
                Integer left = eMessage.indexOf(',')+1;
                Integer right= eMessage.lastIndexOf('。 ')+1;
                if(right>eMessage.length()||right<=left){
                    right=eMessage.length();
                }
                String mes=eMessage.substring(left,right);
                result.errors.add(mes);
            }else{
                result.errors.add(e.getMessage());
            }
            System.debug(LoggingLevel.INFO,'updateOppotunity  Error : ' + e);
        }
        return result;
    }
    @AuraEnabled
    public static String submitApprovalRequest(String recordId) {
        try{
           Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
           req.setObjectId(recordId);
           Approval.ProcessResult result = Approval.process(req);
           if(result.getErrors()!=null&&result.getErrors().size()>0)return result.getErrors().get(0).getMessage();
        }catch(Exception e){
            System.debug('LexStockCancelController submitApprovalRequest  error: '+e.getMessage());
            return e.getMessage();
        }
           return null;
    }
    public class UpdateResult {
        @AuraEnabled public String recordId {get;set;}
        @AuraEnabled public Boolean success {get;set;}
        @AuraEnabled public List<String> errors {get;set;}
    }
    public class InitData{
       
    }
}