@RestResource(urlMapping='/OFSTaskCreate/*') global with sharing class OFSTaskCreateRest { @HttpPost global static void doPost(String subject, String dt, String whatId, String whoId) { system.debug('OFSTaskCreateRest.start'); RestResponse res = RestContext.response; res.addHeader('Content-Type', 'application/json'); String jsonResponse; Task t = new Task( OwnerId = UserInfo.getUserId(), Subject = subject, Status = '未着手', Priority = '中' ); if (String.isBlank(dt) == false){ t.ActivityDate = Date.parse(dt); } else { t.ActivityDate = Date.today(); } if (String.isBlank(whatId) == false) { t.whatId = whatId; } if (String.isBlank(whoId) == false) { t.whoId = whoId; } try{ insert t; res.statusCode = 200; jsonResponse = '{"'+ System.Label.OFSErrorStatus +'": "'+ System.Label.OFSErrorSuccess +'", "'+ System.Label.OFSErrorMessage +'": "'+ t.Id +'"}'; //jsonResponse = '{"status": "Success", "message": "' + tlist[0].Id + '"}'; res.responseBody = blob.valueOf(jsonResponse); return; }catch ( Exception ex ) { //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; } } }