Search Here

Get post update delete Api

 workbench

/services/apexrest/Accounts/AccountService?Id=0015i00000y6vKPAAY

/**
 * @description       :
 * @author            : ChangeMeIn@UserSettingsUnder.SFDoc
 * @group             :
 * @last modified on  : 12-18-2023
 * @last modified by  : ChangeMeIn@UserSettingsUnder.SFDoc
**/
@RestResource(urlMapping='/Accounts/AccountService/*')
Global with sharing class AccountService {

    @HttpGet
    Global static Account getAccount() {
        String accountId = RestContext.request.params.get('Id');
        return [SELECT Id, Name FROM Account WHERE Id = :accountId];
    }

    @HttpPost
    Global static Account createAccount(String accName) {
        Account accObj = new Account(Name = accName);
        insert accObj;
        return accObj;
    }

    @HttpPatch
    Global static Account updateAccount(String accId, String accName) {
        Account accObjUp = [SELECT Id, Name FROM Account WHERE Id = :accId];
        accObjUp.Name = accName;
        update accObjUp;
        return accObjUp;
    }

    @HttpDelete
    Global static void deleteAccount() {
        String accId = RestContext.request.params.get('Id');
        delete [SELECT Id FROM Account WHERE Id = :accId];
    }
}

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.