function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Subhasini Bhosal 6Subhasini Bhosal 6 

I am not sure how to use REST API to update a Case record by passing the the updated value in JSON format. For instance if I want to update the priority of an existing case from High to Low. Can somebody help on this?

HI ,
I have written written apex class to create a case and return a case by Id using REST API and JSON.I am not sure how to use REST API to update a Case record by passing the the updated value in JSON format. For instance if I want to update the priority of an existing case from High to Low. Can somebody help on this?


-------------------------------------------
@RestResource(urlMapping='/Case/*')

global with sharing class CaseCreater {
 @HttpGet
    global static Case getCaseById() {
        RestRequest req = RestContext.request;        
            String caseId = req.requestURI.substring(
                                      req.requestURI.lastIndexOf('/')+1);
        Case result =
                       [SELECT  Status,Origin from Case where  Id = :caseId];
        return result;
    }
    @HttpPost
    global static String createCase(String priority,String type, String status,
        String origin,String reason, String subject, String description ) {
        Case c = new Case(
         
            Priority=priority,
            Type= type,            
            Status=status,
            Origin=origin,
            Reason=reason,
            Subject=subject,
            Description=description          
                            );
        insert c;
        return c.Id;
    }
}
//SELECT  Status,Origin,priority,Product__c,Type,Reason,
//Subject,Description,account.name,case.contact.name from Case where status='New'

 
Naval Sharma4Naval Sharma4
Hi Subhasini,

Can you add one more method.
@HttpPost
    global static boolean updateCase(String caseId, String priority) {
        Case c = new Case(
            Id = caseId,
            Priority=priority,       
       );
        update c;
        return true;
    }
}

Let me know if you need more help.

Thanks,
Naval