+ Start a Discussion

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.
System.QueryException: List has no rows for assignment to SObject Class.RESTClass.updateAccount: line 7, column 1
    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.

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