-
Notifications
You must be signed in to change notification settings - Fork 35
/
REST_AccountService_V2.cls
40 lines (32 loc) · 1.37 KB
/
REST_AccountService_V2.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/****************************************************************************************************
* Description - Sample Apex REST service with GET method
* Author - Matthew Lamb
****************************************************************************************************/
@RestResource(urlMapping='/v2/accounts/*')
global with sharing class REST_AccountService_V2 {
@HttpGet
global static AccountWrapper doGet() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
AccountWrapper response = new AccountWrapper();
String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
List<Account> result = [SELECT Id, Name, Phone, Website FROM Account WHERE External_Id__c = :accountId];
if(result != null && result.size() > 0) {
response.acct = result[0];
response.status = 'Success';
}
else {
response.acct = null;
response.status = 'Error';
response.message = 'This account could not be found, please try again.';
res.StatusCode = 404;
}
return response;
}
global class AccountWrapper {
public Account acct;
public String status;
public String message;
public AccountWrapper(){}
}
}