Skip to content

Instantly share code, notes, and snippets.

@mannharleen
Last active November 24, 2022 10:00
Show Gist options
  • Save mannharleen/5e58d0c2f3d841cf0d51ddd01d2acc11 to your computer and use it in GitHub Desktop.
Save mannharleen/5e58d0c2f3d841cf0d51ddd01d2acc11 to your computer and use it in GitHub Desktop.
Salesforce trailhead - Apex-Integration-Services-Apex-Web-Services
@RestResource(urlMapping='/Accounts/*/contacts')
global with sharing class AccountManager {
@HttpGet
global static account getAccount() {
RestRequest request = RestContext.request;
String accountId = request.requestURI.substring(request.requestURI.lastIndexOf('/')-18,
request.requestURI.lastIndexOf('/'));
List<Account> a = [select id, name, (select id, name from contacts) from account where id = :accountId];
List<contact> co = [select id, name from contact where account.id = :accountId];
system.debug('** a[0]= '+ a[0]);
return a[0];
}
}
@Istest(SeeAllData=true)
public class AccountManagerTest {
@IsTest
public static void testaccountmanager() {
RestRequest request = new RestRequest();
request.requestUri = 'https://mannharleen-dev-ed.my.salesforce.com/services/apexrest/Accounts/00190000016cw4tAAA/contacts';
request.httpMethod = 'GET';
RestContext.request = request;
system.debug('test account result = '+ AccountManager.getAccount());
}
}
@AfreedSfdc
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment