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
HTANIRSHTANIRS 

Apex Rest to update account

Hi Experts,

I need to update accountnumber in account using rest services.
Need your help on code snippet to update.
I tried the below code but getting error when trying to update.
Error 
System.QueryException: List has no rows for assignment to SObject Class.RESTClass.updateAccount: line 7, column 1
 
@HttpPatch 
    global static String updateAccount(string accnumber){
        String accid1 = RestContext.request.params.get('id');
        Account acc = [select accountnumber from account where id =: accid1];
        acc.accountnumber = accnumber;
        update acc;
        return 'account updated';
    }

Let me know what I need to change to make this work.

Thanks
Danish HodaDanish Hoda
Hi there,
Are you sure the JSOn you are getting is having "id" field containing Account Id?