Skip to main content
@RestResource(urlmapping='/v1/AccountName/*')

Global class AccounManager2 {

    /*

     @httpGet

     global static List<Account> accountInformation(){

        RestRequest request = RestContext.request;

        System.debug('request:'+request);

        String requestURI = request.requestURI;

        System.debug('requestURI:'+requestURI);

        String accName = '%'+requestURI.subStringAfterLast('/')+'%';

        System.debug('accName:'+accName);

         

        List<Account> accountList = [Select Id, Name, Rating, 

        Industry, Description, Phone, Fax

        FROM Account Where Name like : accName];

         

        return accountList;

         

       }

*/

    

    @httpPatch

    global static string updateAccEmail(String accName, String newRating){

        string respMessage=null;

        try{

            Account acc = [Select id,name,rating from Account where name=:accName];

            if(acc!=NULL && acc.rating !=newRating)

            {

                string oldRating = acc.rating;

                acc.rating = newRating;

                update acc;

                respMessage = 'Lead updated from old rating '+oldRating +' with new rating as '+newRating;

            }

            else{

                respMessage = 'Currently this account is having same rating  '+newRating;

            }

        }

        catch(Exception ex){

           respMessage ='Exception occured during lead update '+ex.getMessage();

        }

        return respMessage;

    }

    

}
1 Antwort
  1. 10. Okt. 2022, 02:55
    Hi Vinayak,

    I tried the same code and used workbench to execute Patch request. I did not face any issue.

    I hope there is some duplicate account with same name. Can you try to create a fresh account with some unique name and try.

    Let me know if you face any issues.

    If this solution helps, Please mark it as best answer.

    Thanks,
0/9000