Challenge 1

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.

install the Step 1 –unmanaged package present in a use case in your org for all users.

Advertisement

Setup -> Remote site settings -> New

Use the following endpoint information to configure a Remote Site Setting:

Remote site name – BillingService

Remote site URL – http://sb-integration-bs.herokuapp.com

Add Step 3 –custom setting to ServiceCredential

Setup-> Custom settings-> ServiceCredential -> Manage ->new

Label – BillingServiceCredential

Setup -> Named credential -> New Named credential

Label – ProjectService

Name – ProjectService

URL – https://sb-integration-pms.herokuapp.com/projects

Identity Type – Named Principal

Authentication Protocol – Password Authentication

Username – pmsUser1

Password – pmsPass1

Generate Authorization Header -Checked

Don’t forget to check out: Salesforce CPQ Certified Specialists – All You Need To Know

Challenge 2

Setup -> App Manager -> New Connected App

Connected App – Name ProjectService

API Name – ProjectService

Contact email -Your email

Enable OAuth Settings – Checked

Callback URL- https://sb-integration-pms.herokuapp.com/oauth/_callback

Selected OAuth Scopes – Full access & Perform requests on your behalf at any time (refresh_token, offline_access)

As the time the Step 2 –connected app is configured, copy the Consumer Key and Consumer Secret.

Step 3 – Configure Org Registration

Click on the integration herokuapp link -> log into your DE org ->Allow access ->Enter the Consumer key -> Consumer Secret -> test connected App

(Copy the token value)

Save the token value as a Step 4 –ServiceToken record in the custom setting named Token.

Challenge 3

Object manager -> Opportunity -> Fields and relationships -> Type ->Opportunity Type Picklist Values (New) Write ‘New Project’ -> Save

Object manager -> Opportunity -> Fields and relationships -> Stage ->Opportunity Stages Picklist Values (New)

Step 3 – Work on the ProjectCalloutService Class

public class ProjectCalloutService {
    //Complete the implementation for business and callout logic
    @InvocableMethod
    public static void postOpportunityToPMS(List<Id> oppoIds){
        Opportunity opp = [SELECT Id,Name,Account.Name,CloseDate,Amount FROM Opportunity WHERE Id = :oppoIds[0]];
        String serviceToken = ServiceTokens__c.getValues('ProjectServiceToken').Token__c;        
        String jsonInput = '{\n' +
            ' "opportunityId" : "'+opp.Id+'",\n'+
            ' "opportunityName" : "'+opp.Name+'",\n'+
            ' "accountName" : "'+opp.Account.Name+'",\n'+
            ' "closeDate" : "'+String.ValueOf(opp.CloseDate).mid(0,10)+'",\n'+   
            ' "amount" : "'+opp.Amount+'"\n}';            
        System.enqueueJob(new QueueablePMSCall(serviceToken, jsonInput, opp.Id));
    }        
    class QueueablePMSCall implements System.Queueable, Database.AllowsCallouts{
        private String serviceToken;
        private String jsonInput;
        private Id oppId;        
        public QueueablePMSCall(String serviceToken, String jsonInput, Id oppId){
            this.serviceToken = serviceToken;
            this.jsonInput = jsonInput;
            this.oppId = oppId;
        }        
        public void execute(QueueableContext qc){
            postToPMS(serviceToken, jsonInput, oppId);        
        }
    }    
    @Future(callout=true)
    private static void postToPMS(String serviceToken, String jsonInput, Id oppoId){
        HTTPRequest req = new HTTPRequest();
        req.setEndPoint('callout:ProjectService');
        req.setMethod('POST');
        req.setHeader('token',serviceToken);
        req.setHeader('Content-Type', 'application/json;charset=UTF-8');
        req.setBody(jsonInput);        
        HTTP http = new HTTP();
        HTTPResponse res = http.send(req);        
        Opportunity opp = new Opportunity(Id=oppoId);
        if(res.getStatusCode() == 201){
            opp.StageName = 'Submitted Project';                
            System.debug('Success: ' + res.getStatus());
        }else{
            opp.StageName = 'Resubmit Project';
            System.debug('Failure: ' + res.getStatusCode() + ' ' + res.getStatus());
        }
        update opp;
    }        
}

Check out another amazing blog by Aditya here: Superbadge ‘Business Administration Specialist’ Solution

Object – opportunity

Criteria – Conditions are met

  1. Type->equals->picklist->New Project
  2. StageName->IsChanged->Boolean->true
  3. StageName->equals->picklist->Closed Won

Customize the logic – 1 AND (2 AND 3)

Immediate Action Name – Post Opportunity To PMS

Invoke method – Apex class ( ProjectCalloutService )

Set Apex Variables – opioids->Field reference ->[Opportunity].Id

Please click here to read the original article as posted on Forcetalks.

We source the web to bring you best Salesforce articles for our reader’s convenience. If you want to have this article removed, please follow guidelines at Digital Millennium Copyright Act (DMCA)..