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
@RestResource(urlMapping='/OFSTaskFinish/*')
global with sharing class OFSTaskFinishRest {
    @HttpPost
    global static void doPost(Id Tid) {
        system.debug('OFSTaskFinishRest.start');
        RestResponse res = RestContext.response;
        res.addHeader('Content-Type', 'application/json');
        
        String jsonResponse;
        
        List<Task> tlist = [select Id,Subject,OwnerId,Description,ActivityDate,QuoteIraiId__c,Status
                            from Task
                            where Id = :Tid];
        if(tlist.size()<=0){
            //TODO:
            //error message:no event or wrong Id 
            res.statusCode = 200;
            jsonResponse = '{"'+ System.Label.OFSErrorStatus +'": "'+ System.Label.OFSErrorFailure +'", "'+ System.Label.OFSErrorMessage +'": "No matching task was found"}';
            res.responseBody = blob.valueOf(jsonResponse);
               return;
               
        }else{
            tlist[0].Status = '完了';
            
            try{
                update tlist[0];
                res.statusCode = 200;
                jsonResponse = '{"'+ System.Label.OFSErrorStatus +'": "'+ System.Label.OFSErrorSuccess +'", "'+ System.Label.OFSErrorMessage +'": "'+ tlist[0].Id +'"}';
                //jsonResponse = '{"status": "Success", "Message": "' + tlist[0].Id + '"}';
                res.responseBody = blob.valueOf(jsonResponse);
                return;
            }catch ( Exception ex ) {
                //TODO:
                //error message:cannot update exception
                res.statusCode = 200;
                jsonResponse = '{"'+ System.Label.OFSErrorStatus +'": "'+ System.Label.OFSErrorFailure +'", "'+ System.Label.OFSErrorMessage +'": "'+ ex +'"}';
                //jsonResponse = '{"status": "Failure", "Message": "' + ex + '"}';
                res.responseBody = blob.valueOf(jsonResponse);
                return;
            }
        }        
    }
}