diff --git a/demo-app/main/default/classes/CustomerWebServiceDemo.cls b/demo-app/main/default/classes/CustomerWebServiceDemo.cls new file mode 100644 index 0000000..c340729 --- /dev/null +++ b/demo-app/main/default/classes/CustomerWebServiceDemo.cls @@ -0,0 +1,94 @@ +@RestResource(UrlMapping='/*/customers/*') +global with sharing class CustomerWebServiceDemo { + @HttpGet + global static void doGet() { + libak_RestFramework.handleRequest(CustomerRestRouter.class); + } + @HttpPost + global static void doPost() { + libak_RestFramework.handleRequest(CustomerRestRouter.class); + } + @HttpPut + global static void doPut() { + libak_RestFramework.handleRequest(CustomerRestRouter.class); + } + @HttpDelete + global static void doDelete() { + libak_RestFramework.handleRequest(CustomerRestRouter.class); + } + + public class CustomerRestRouter extends libak_RestRouter { + override public libak_RestRouter setRoutes() { + this.routeToRestProcessorType = new Map{ + '/v1/customers' => CustomersProcessorV1.class, + '/v1/customers/:customer_sf_id' => CustomerProcessorV1.class + }; + return this; + } + } + + public class CustomersProcessorV1 extends libak_RestProcessor { + protected override libak_RestFramework.IRestResponse handleGet() { + List accounts = [ + SELECT Id, Name, Phone, BillingStreet, BillingCity, BillingState, BillingPostalCode + FROM Account + LIMIT 100 + ]; + + if (accounts.isEmpty()) { + return new libak_ErrorResponse(404, 'Accounts are not found', ''); + } else { + return new libak_JsonResponse(accounts); + } + } + + protected override libak_RestFramework.IRestResponse handlePost() { + Account newAccount = (Account)JSON.deserialize(this.request.requestBody.toString(), Account.class); + insert newAccount; + + return new libak_JsonResponse(newAccount); + } + } + + public class CustomerProcessorV1 extends libak_RestProcessor { + protected override libak_RestFramework.IRestResponse handleGet() { + List accounts = [ + SELECT Id, Name, Phone, BillingStreet, BillingCity, BillingState, BillingPostalCode + FROM Account + WHERE Id = :this.getUriParam('customer_sf_id') + ]; + + if (accounts.isEmpty()) { + return new libak_ErrorResponse(404, 'Accounts are not found', ''); + } else { + return new libak_JsonResponse(accounts.get(0)); + } + } + + protected override libak_RestFramework.IRestResponse handlePut() { + String accountId = this.getUriParam('customer_sf_id'); + List existingAccounts = [SELECT Id FROM Account WHERE Id = :accountId]; + + if (existingAccounts.isEmpty()) { + return new libak_ErrorResponse(404, 'Account are not found', ''); + } + + Account updatedAccount = (Account)JSON.deserialize(this.request.requestBody.toString(), Account.class); + updatedAccount.Id = accountId; + update updatedAccount; + return new libak_JsonResponse(updatedAccount); + } + + protected override libak_RestFramework.IRestResponse handleDelete() { + String accountId = this.getUriParam('customer_sf_id'); + List existingAccounts = [SELECT Id FROM Account WHERE Id = :accountId]; + + if (existingAccounts.isEmpty()) { + return new libak_ErrorResponse(404, 'Account are not found', ''); + } + + delete existingAccounts.get(0); + return new libak_SuccessResponse('Account deleted successfully'); + } + } +} \ No newline at end of file diff --git a/demo-app/main/default/classes/CustomerWebServiceDemo.cls-meta.xml b/demo-app/main/default/classes/CustomerWebServiceDemo.cls-meta.xml new file mode 100644 index 0000000..998805a --- /dev/null +++ b/demo-app/main/default/classes/CustomerWebServiceDemo.cls-meta.xml @@ -0,0 +1,5 @@ + + + 62.0 + Active + diff --git a/demo-app/main/default/connectedApps/libak_salesforce_rest_framework.connectedApp-meta.xml b/demo-app/main/default/connectedApps/libak_salesforce_rest_framework.connectedApp-meta.xml new file mode 100644 index 0000000..6442ff6 --- /dev/null +++ b/demo-app/main/default/connectedApps/libak_salesforce_rest_framework.connectedApp-meta.xml @@ -0,0 +1,22 @@ + + + akohan91@gmail.com + + + https://login.salesforce.com + false + false + false + false + false + false + false + true + true + Full + + + ENFORCE + infinite + +