Configure outbound application and integration security
题目要求如下:
Install the unmanaged package from the prework if you haven’t already. Configure a named credential and remote site according to the specifications outlined in the business requirements. Enter the billing service credentials in the custom setting.
题目要求如下 Configure the PMS Connected App according to the specifications outlined in the business requirements. Then register the connected app with the Org Registration Heroku app and test the connection. Enter the project service security token into the custom setting.
Synchronize Salesforce opportunity data with Square Peg’s PMS external system
Build a Process Builder process on the opportunity object to invoke an Apex REST callout to the external PMS as outlined in the requirements section. 本题考查的是进程生成器(Process Builder)调用Apex类。
之后需要新建一个进程生成器(Process Builder) ,可以命名为Update Opportunity with Opportunity object selection.
总图为:
选择Opportunity,中间判断条件可以设置为:Opportunity Type with stage change
下面是用进程生成器(Process Builder)调用Apex类
Test outbound Apex REST callout logic
Build tests for your Apex outbound service logic using the included stubs (ProjectCalloutServiceMock and ProjectCalloutServiceMockFailure) and callout test class (ProjectCalloutServiceTest) in the package. You must have 90% test coverage to pass this challenge and assert values to prove that your logic is working as expected.
基于上一题写一个测试类,同时要求90%代码覆盖率。 成功例子
1 2 3 4 5 6 7 8 9 10 11 12 13 14
@isTest global classProjectCalloutServiceMockimplementsHttpCalloutMock{ //Implement http mock callout here // Implement this interface method global HTTPResponse respond(HTTPRequest request){ // Create a fake response HttpResponse response = new HttpResponse(); response.setHeader('Content-Type', 'application/json'); response.setStatus('OK'); response.setStatusCode(201); return response; } }
失败的例子
1 2 3 4 5 6 7 8 9 10 11 12 13 14
@isTest global classProjectCalloutServiceMockFailureimplementsHttpCalloutMock{ //Implement http mock callout here // Implement this interface method global HTTPResponse respond(HTTPRequest request){ // Create a fake response HttpResponse response = new HttpResponse(); response.setHeader('Content-Type', 'application/json'); response.setStatus('Bad Response'); response.setStatusCode(500); return response; } }
@isTest privateclassProjectCalloutServiceTest{ //Implement mock callout tests here @testSetupstaticvoidtestSetupdata(){ //create the opportunity record Opportunity opp1 = new Opportunity(); opp1.Name = 'Test Opp1'; opp1.Type = 'New Project'; opp1.Amount = 100; opp1.CloseDate = Date.today(); opp1.StageName = 'Submitted Project'; insert opp1; //create the opportunity record Opportunity opp2 = new Opportunity(); opp2.Name = 'Test Opp2'; opp2.Type = 'New Project'; opp2.Amount = 200; opp2.CloseDate = Date.today(); opp2.StageName = 'Resubmit Project'; insert opp2; //create the Custom Settings ServiceTokens__c servToken = new ServiceTokens__c(); servToken.Name = 'ProjectServiceToken'; servToken.Token__c = 'qwertyuiopnjhgft'; insert servToken; } @isTest staticvoidtestSuccessMessage(){ Opportunity opp = [Select Id, Name FROM Opportunity WHERE Name = 'Test Opp1' Limit 1]; List<Id> lstOfOppIds = new List<Id>(); lstOfOppIds.add(opp.Id); // Set mock callout class Test.setMock(HttpCalloutMock.class, new ProjectCalloutServiceMock()); // This causes a fake response to be sent // from the class that implements HttpCalloutMock. Test.startTest(); ProjectCalloutService.postOpportunityToPMS(lstOfOppIds); Test.stopTest(); // Verify that the response received contains fake values opp = [select StageName from Opportunity where id =: opp.Id]; System.assertEquals('Submitted Project',opp.StageName); } @isTest staticvoidtestFailureMessage(){ Opportunity opp = [Select Id, Name FROM Opportunity WHERE Name = 'Test Opp2' Limit 1]; List<Id> lstOfOppIds = new List<Id>(); lstOfOppIds.add(opp.Id); // Set mock callout class Test.setMock(HttpCalloutMock.class, new ProjectCalloutServiceMockFailure()); // This causes a fake response to be sent // from the class that implements HttpCalloutMock. Test.startTest(); ProjectCalloutService.postOpportunityToPMS(lstOfOppIds); Test.stopTest(); // Verify that the response received contains fake values opp = [select StageName from Opportunity where id =: opp.Id]; System.assertEquals('Resubmit Project',opp.StageName); } }
Synchronize external PMS system project data with Salesforce
Use the requirements above to implement an Apex REST service to process related project and opportunity data that comes in from the Square Peg external application. Before checking this section, run the service method in the ProjectRESTService class to confirm that it’s working as expected.
@RestResource(urlMapping = '/project/*') global with sharing classProjectRESTService{ @HttpPost global static String postProjectData(String ProjectRef, String ProjectName, String OpportunityId, Date StartDate, Date EndDate, Double Amount, String Status){ String retMsg = 'Error'; SavePoint sp1 = Database.setSavePoint(); try{ List<Opportunity> lstOfOpps = new List<Opportunity>(); if(OpportunityId != null && OpportunityId.trim().length() > 0){ Opportunity opp = [SELECT Id, DeliveryInstallationStatus__c, Discount_Percent__c FROM Opportunity WHERE Id = :OpportunityId]; opp.DeliveryInstallationStatus__c = 'In progress'; lstOfOpps.add(opp); } UPDATE lstOfOpps; List<Project__c> lstOfRrjts = new List<Project__c>(); Project__c prjt = new Project__c(); prjt.ProjectRef__c = ProjectRef; prjt.Name = ProjectName; prjt.Opportunity__c = OpportunityId; prjt.Start_Date__c = StartDate; prjt.End_Date__c = EndDate; prjt.Billable_Amount__c = Amount; prjt.Status__c = Status; lstOfRrjts.add(prjt); UPSERT lstOfRrjts; retMsg = 'OK'; }catch(Exception ex){ Database.rollback(sp1); retMsg = ex.getMessage(); } return retMsg; } }
Test inbound Apex REST service logic
Build tests for your Apex REST service logic using the stub for the test class (ProjectRESTServiceTest) in the package. You must have 90% test coverage to pass this challenge and assert values to prove that your logic is working as expected.
Synchronize Salesforce project data with Square Peg’s external billing system
Perform the necessary steps, as outlined in the requirements, to make an outbound authenticated Apex callout to Square Peg’s external billing system’s SOAP service. To pass this challenge, delete the unused Async process class that is autogenerated from the WSDL AsyncBillingServiceProxy.
Build tests for your SOAP callout and assert proper behavior using the included stubs (BillingCalloutServiceMock and BillingCalloutServiceMockFailure) and callout test class (BillingCalloutServiceTest) in the package. You must have 90% test coverage to pass this challenge and assert values to prove that your logic is working as expected.
1 2 3 4 5 6 7 8
@isTest global classBillingCalloutServiceMockimplementsWebServiceMock{ global voiddoInvoke(Object stub,Object request,Map<String, Object> response,String endpoint,String soapAction,String requestName,String responseNS, String responseName,String responseType){ BillingServiceProxy.billProjectResponse_element response_x = new BillingServiceProxy.billProjectResponse_element(); response_x.status = 'OK'; response.put('response_x', response_x); } }
1 2 3 4 5 6 7
global classBillingCalloutServiceMockFailureimplementsWebServiceMock{ global voiddoInvoke(Object stub,Object request,Map<String, Object> response,String endpoint,String soapAction, String requestName, String responseNS,String responseName,String responseType){ BillingServiceProxy.billProjectResponse_element response_x = new BillingServiceProxy.billProjectResponse_element(); response_x.status = 'ERROR'; response.put('response_x', response_x); } }
Synchronize external billing data with Salesforce in real time
Configure Salesforce Connect to integrate with Square Peg’s external billing system to expose invoice information as children of projects as outlined in the requirements.
根据题目要求,需要设置一个external data source的连接。路径为:setup–>external data source