Last active
November 24, 2022 10:00
-
-
Save mannharleen/5e58d0c2f3d841cf0d51ddd01d2acc11 to your computer and use it in GitHub Desktop.
Salesforce trailhead - Apex-Integration-Services-Apex-Web-Services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks