Posts

Showing posts from August, 2020

Apex Integration Services

 AccountManager.apxc @RestResource(urlMapping='/Accounts/*/contacts') global with sharing class AccountManager {     @HttpGet     global static Account getAccount() {         RestRequest request = RestContext.request;         // grab the caseId from the middle of the URL         String accountId = request.requestURI.substringBetween('Accounts/','/contacts');         Account result =  [SELECT Id, Name, (Select Id, Name from Contacts)                            FROM Account                            WHERE Id = :accountId];         return result;     } }     AccountManagerTest @IsTest private class AccountManagerTest {     @isTest static void testGetContactsByAccountId() {     ...

Apex SOAP Callouts - Generate an Apex class using WSDL2Apex and write a test class.

  Generate an Apex class using WSDL2Apex for a SOAP web service, write unit tests that achieve 100% code coverage for the class using a mock response, and run your Apex tests. Use WSDL2Apex to generate a class called 'ParkService' in public scope using  this WSDL file . After you click the 'Parse WSDL' button don't forget to change the name of the Apex Class Name from 'parksServices' to 'ParkService'. Create a class called 'ParkLocator' that has a 'country' method that uses the 'ParkService' class and returns an array of available park names for a particular country passed to the web service. Possible country names that can be passed to the web service include Germany, India, Japan and United States. Create a test class named ParkLocatorTest that uses a mock class called ParkServiceMock to mock the callout response. The unit tests must cover all lines of code included in the ParkLocator class, resulting in 100% code coverage. ...

Apex REST Callouts - Create an Apex class that calls a REST endpoint and write a test class.

To pass this challenge, create an Apex class that calls a REST endpoint to return the name of an animal, write unit tests that achieve 100% code coverage for the class using a mock response, and run your Apex tests. The Apex class must be called 'AnimalLocator', have a 'getAnimalNameById' method that accepts an Integer and returns a String. The 'getAnimalNameById' method must call https://th-apex-http-callout.herokuapp.com/animals/id, using the ID passed into the method. The method returns the value of the 'name' property (i.e., the animal name). Create a test class named AnimalLocatorTest that uses a mock class called AnimalLocatorMock to mock the callout response. The unit tests must cover all lines of code included in the AnimalLocator class, resulting in 100% code coverage. Run your test class at least once (via 'Run All' tests the Developer Console) before attempting to verify this challenge. AnimalLocator.apxc public class AnimalLocator...

Schedule Jobs Using the Apex Scheduler - Create an Apex class that uses Scheduled Apex to update Lead records.

Create an Apex class that implements the Schedulable interface to update Lead records with a specific LeadSource. Write unit tests that achieve 100% code coverage for the class. This is very similar to what you did for Batch Apex. Create an Apex class called 'DailyLeadProcessor' that uses the Schedulable interface. The execute method must find the first 200 Leads with a blank LeadSource field and update them with the LeadSource value of 'Dreamforce'. Create an Apex test class called 'DailyLeadProcessorTest'. In the test class, insert 200 Lead records, schedule the DailyLeadProcessor class to run and test that all Lead records were updated correctly. The unit tests must cover all lines of code included in the DailyLeadProcessor class, resulting in 100% code coverage. Run your test class at least once (via 'Run All' tests the Developer Console) before attempting to verify this challenge. Answer DailyLeadProcessor.apxc global class DailyLeadProcessor implem...

Control Processes with Queueable Apex - Create an Queueable Apex class that inserts Contacts for Accounts.

Create a Queueable Apex class that inserts the same Contact for each Account for a specific state. Write unit tests that achieve 100% code coverage for the class. Create an Apex class called 'AddPrimaryContact' that implements the Queueable interface. Create a constructor for the class that accepts as its first argument a Contact sObject and a second argument as a string for the State abbreviation. The execute method must query for a maximum of 200 Accounts with the BillingState specified by the State abbreviation passed into the constructor and insert the Contact sObject record associated to each Account. Look at the sObject clone() method. Create an Apex test class called 'AddPrimaryContactTest'. In the test class, insert 50 Account records for BillingState "NY" and 50 Account records for BillingState "CA". Create an instance of the AddPrimaryContact class, enqueue the job and assert that a Contact record was inserted for each of the 50 Accounts wi...