-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContactDetailsRestHandler.cls
49 lines (41 loc) · 1.46 KB
/
ContactDetailsRestHandler.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
41
42
43
44
45
46
47
48
49
/*
HTTP Method: GET
URL: [sf instance url]/services/apexrest/RestAPI/getContactDetails?id=003f000000mi2cq
Response:
{
"Account": {
"Name": "Test",
"Id": "001f000000lmoZbAAI",
"attributes": {
"url": "/services/data/v34.0/sobjects/Account/001f000000lmoZbAAI",
"type": "Account"
}
},
"AccountId": "001f000000lmoZbAAI",
"LastName": "test",
"FirstName": "test",
"Name": "test test",
"Id": "003f000000mi2cqAAA"
}
*/
public with sharing class ContactDetailsRestHandler extends AbstactRestHandler {
public static final String ACTION = 'getContactDetails';
public override String getActionName(){
return ACTION;
}
public override String getHttpMethod(){
return HTTP_GET;
}
public override void execute(RestRequest request, RestResponse response){
String contactId = request.params.get('id');
Contact contactVar = getContactDetails(contactId);
AbstactRestHandler.JSONResponse(response, contactVar);
}
private Contact getContactDetails(String contactId){
List<Contact> contacts = [SELECT Id, Name, FirstName, LastName, Account.Id, Account.Name FROM Contact WHERE Id = :contactId LIMIT 1];
if (contacts.isEmpty()){
throw new RestHandlerException('Not found contact with id = ' + contactId);
}
return contacts.get(0);
}
}