Data Integration Specialist Superbadge Walkthrough


Hello, and welcome to Another Salesforce Blog!  Here I will be posting solutions to problems that I couldn’t find an answer to in hopes of helping those who find themselves stuck when using the Salesforce platform.

This blog post is going to be a walkthrough with helpful hints for the some of the tricker steps of the Data Integration Specialist Superbadge.

Disclaimer: this is only one way to solve the challenge, and is not meant to be a full solution.

There is no shortage of full answers for the challenge on the internet, but this post is meant for folks who are learning Salesforce (like me!) and would like to work through the solution with a few hints for the tricky parts.

Again, copying and pasting what is in this blog post will NOT complete the challenge.

Step One – Quiz Credential Security

This step is a quiz to make sure that you know that cheating is bad and will not be tolerated. I’m putting this here as a reminder that this is not a full solution, and I will not post the full solution! Easy 500 points.

Step 1 Resources:

3 Steps to Safeguarding Your Credentials – Salesforce Blog.

Step 1 Hints:

What would Codey do?

Steps Two and Three – Configure Security Settings.

Next, we set up our org for development. This requires installing the required managed package (easy through the new Trailhead Development Org interface!), set up our named credentials and remote site settings, and create a Connected App. Some of the objects are already created in Salesforce and you just need to add a record, so pay attention, and some of the URLs are HTTP and some are HTTPS, so don’t type them in on autopilot if you’re looking for a first ascent bonus. One thing I had to make sure of was that the box to Generate Authorization Header on the Named Credential was UNCHECKED.

Screenshot of the Install A Package page in the Playground Starter section of the new Trailhead layout.

You can verify that your steps are correct by submitting your Consumer Key and Consumer Secret values in the Project Management System and testing in the linked site.

Screenshot of the Project Management System (PMS) user interface.

Step 2 and 3 Resources:

Named Credentials as Callout Endpoints – Salesforce Developers documentation.
Named Credentials – Salesforce Help.
Adding Remote Site Settings – Salesforce Developers documentation.
Connected Apps – Salesforce Developers documentation.

Step Four – Create an Apex Invoking Flow.

This step took a while and a little bit of back and forth between Flow Builder and Developer Console. I eventually settled on a simple record triggered flow with a less than simple Apex build out.

Screenshot of Flow Builder.

Within the ProjectCalloutService Apex action, we pass in the Opportunity Id of the record that triggered the flow. From there, it gets a little complicated.

Per the instructions:

Implement a method (named PostOpportunityToPMS) in an Apex class (named ProjectCalloutService), and invoke it from the flow action. Ensure your method gets the necessary opportunity data and invokes an authenticated REST callout. We want to design for potential future enqueuing inside other asynchronous jobs, so implement asynchronous logic with queueable Apex in an inner class (named QueueablePMSCall) inside ProjectCalloutSevice to execute the callout logic.

https://trailhead.salesforce.com/content/learn/superbadges/superbadge_integration

We know that we’ll have an inner class called QueueablePMSCall, and we know we’ll be passing in a list of Opportunity Ids with a singular Opportunity Id in it, so let’s start there. It’s also super easy to serialize SObjects into JSON using a wrapper class, as we learned in Creating Child Objects Using Apex REST API, so let’s make a wrapper class.

As I said, I’m not posting the whole solution, but here is the outline of the code that I used to pass this challenge to get you started.

public with sharing class ProjectCalloutService {
        
    //Complete the implementation for business and callout logic
    
    @InvocableMethod
	public static void postOpportunityToPMS(List<Id> oppIds){...}
    
    //public QueueablePMSCall to enqueue Apex
    public class QueueablePMSCall implements System.Queueable, Database.allowsCallouts {

        public QueueablePMSCall(...){...}
        
        public void execute(QueueableContext qc) {...}
    }
    
    //OppWrapper wrapper class to easily serialize into JSON
    public class OppWrapper {
        public String opportunityId;
        public String opportunityName;
        public String accountName;
        public Date closeDate;
        public Decimal amount;
        
        public OppWrapper(Opportunity opp) {
            this.opportunityId = opp.Id;
            this.opportunityName = opp.Name;
            this.accountName = opp.Account.Name;
            this.closeDate = opp.CloseDate;
            this.amount = opp.Amount;
        }
    }
}

Don’t forget, when the callout is successful, set the Opportunity Stage Name to ‘Submitted Project’!

Step Five – Test Classes

This step is dependent on the code you write in Step Four, so I’m just going to post some resources that helped me. You must have 90% test coverage, as well as assert calls to verify that your logic is working as expected. I was able to get 100% coverage by using a failure case and a success case.

Step 5 Resources:

Testing HTTP Callouts by Implementing the HttpCalloutMock Interface – Salesforce Developer documentation.
Control Processes with Queueable Apex – Trailhead that includes writing test classes for queueable Apex.

Step Six – Synchronizing PMS with Salesforce.

This step is super easy, but it took me a minute to figure out what it was asking. We want to ingest parameters in the method signature rather than deserializing from JSON, meaning, we’re going to have a method with seven parameters. Check the Trailhead Help article for hints on this one under the Apex REST Sesource section.

Step 6 Resources:

Data Integration Specialist Superbadge Trailhead Challenge Help – Trailhead.

Step Seven – Test Classes

This is building a test class for an annotated @RestResource class. Pretty simple if you read the above documentation!

Step Eight – Synchronize Salesforce with Square Peg’s Billing System

This step passed, although I’m not sure if the code is working, as there is an error in the Heroku site that prevents me from testing my code. My code is also technically not best practices, because it has a future callout in a FOR loop, but…to be honest, I was unsure of how else to write this. Forgive me, I have COVID. Anyways. First, we download the WSDL file linked in the steps, and then we generate an Apex Class based on the WSDL file. We then use the method in the generated Apex to write our BillingCalloutService file. This is what I came up with:

public with sharing class BillingCalloutService {
    //Implement business and callout logic methods here
    public static void callBillingService(...) {...}
    
    @future(callout=true)
    public static void futureCallout(String ProjectRef, Decimal Amount) {
        ServiceCredentials__c sc = ServiceCredentials__c.getValues('BillingServiceCredential');
        BillingServiceProxy.project proj = new BillingServiceProxy.project();
        
        proj.username = sc.Username__c;
        proj.password = sc.Password__c;
        proj.projectid = ProjectRef;
        proj.billAmount = Amount;
        
        BillingServiceProxy.InvoicesPortSoap11 proxy = new BillingServiceProxy.InvoicesPortSoap11();
        
        String str = proxy.billProject(proj);
        
        Project__c p = new Project__c(ProjectRef__c = ProjectRef, Status__c='Billed');
        upsert p ProjectRef__c;
    }
}

I imagine I will refactor this later when my Molnupiravir has done its job!

Step 8 Resources:

Use SOAP API Unit – Trailhead.
Create an Apex Class from a WSDL File – Salesforce Developer documentation.

Step Nine – More test classes!

See Step Five! I basically copied and tweaked my test classes for that step by making the mock classes for Web Services. I was able to get 100% test coverage.

Step 9 Resources:

Test Web Service Callouts – Salesforce Developer documentation.

Step Ten – Configure Salesforce Connect.

This step took a little finagling, but we got it. Make sure that you have the Invoices Related List on the page layout.

Summary

In all, this superbadge took about eight hours. I hope that this post helps you complete it as well!

Thanks for reading, let me know if you have any comments or questions!

-Evelyn, Another Salesforce Blog

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

$5.00
$15.00
$50.00
$5.00
$15.00
$50.00
$5.00
$15.00
$50.00

Or enter a custom amount

$

Help keep Another Salesforce Blog on the internet by donating today!

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: