0% found this document useful (0 votes)
42 views31 pages

Scenario Based Salesforce Integration Interview Questions

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 31

By Smriti Sharan (sfdcamplified)

Scenario Based Salesforce Integration Interview


Questions. Discussing Detailed Solutioning
(Like Never Before)

Hello, my Name is Smriti Sharan. I am avid


blogger and youtuber. Follow my Blog and youtube to learn various
aspect of Salesforce.
https://t.me/sfdcamplified feel free to join telegram group. Feel free to
provide feedback if you find any issue with solutioning.

You are working on integrating Salesforce with Sizmek, an


external campaign management system. When a campaign is
created in Sizmek, it needs to be automatically created and
updated in Salesforce, including updating the campaign
hierarchy. How to achieve this?
First step is to breakdown the requirement and understand the data flow.
• A campaign is created in Sizmek.
• Sizmek sends a request to Salesforce to create the campaign.
• Salesforce creates the campaign and updates the hierarchy if
necessary.
• Salesforce responds back to Sizmek with the status of the request.

2.This is a call-in where Sizmek (external system) calls Salesforce to


perform operations.
By Smriti Sharan (sfdcamplified)

3.Connected App Setup:


• Create a Connected App in Salesforce to enable OAuth
authentication.
By Smriti Sharan (sfdcamplified)

• Obtain the Client ID and Client Secret for authentication.

4.OAuth Authentication:
• Implement OAuth 2.0 user-agent flow in Sizmek to obtain an access
token. The user-agent flow is simpler and more straightforward. It
reduces the need for server-side handling of OAuth tokens.

• Use this access token to authenticate API requests to Salesforce.

5.Connector in Sizmek:
Set up the connector with the necessary API user details through the
OAuth flow.
By Smriti Sharan (sfdcamplified)

6.Using Standard REST API:


Make HTTP POST requests to the Salesforce REST API
/sobjects/Campaign/ endpoint to create and update campaign records.
No need to write a custom Apex REST class for this purpose.

Quotes created in Salesforce (with Apttus package) need to


be fetched by SAP CRM at the end of the day and created in
SAP CRM. How to achieve this scenario?

1. Data Flow:
• A quote is created in Salesforce.
• At the end of the day, SAP CRM fetches all created quotes from
Salesforce.
• The fetched quotes are then created in SAP CRM.

2.Type of Integration: This is a call-out from Salesforce to SAP CRM to


fetch and synchronize data.

3.Solution: Use a custom REST API to expose the necessary data.


By Smriti Sharan (sfdcamplified)

Steps
1. Create an Apex Class for Callout. You can use future or batch or
queuable depends on scenario.

Future Methods: Would be ideal for small, quick updates that don’t require
monitoring.
Limits:
• Maximum of 50 future calls per transaction.
• Maximum of 200 future calls per 24-hour period per license.

Sample Code
public class FutureMethodExample {
@future(callout=true)
public static void updateQuote(String quoteId) {
// Logic to update Quote and make an external callout
Quote quote = [SELECT Id, Name FROM Quote WHERE Id =
:quoteId];
// Callout logic here
// Update quote logic here
}
}

Queueable Apex: Suitable for handling complex logic and chaining jobs if
the integration requires multiple steps.
Limits:
• Maximum of 50 Queueable jobs per transaction.
• Maximum of 200 jobs added to the queue per 24-hour period per
license.
• Limit of 100 enqueued jobs at once for an org.

Sample Code
By Smriti Sharan (sfdcamplified)

public class QueueableExample implements Queueable,


Database.AllowsCallouts {
private String quoteId;

public QueueableExample(String quoteId) {


this.quoteId = quoteId;
}

public void execute(QueueableContext context) {


// Logic to update Quote and make an external callout
Quote quote = [SELECT Id, Name FROM Quote WHERE Id =
:quoteId];
// Callout logic here
// Update quote logic here

// Optionally chain another job


System.enqueueJob(new AnotherQueueableJob());
}
}

Batch Apex: Best for nightly or periodic syncs where a large volume of
data needs to be processed.

Limits:
• Maximum of 5 active batch jobs at a time.
• Maximum of 100 batch jobs can be queued or active concurrently.
• Up to 2000 batch apex jobs can be submitted in a 24-hour period.
• Each batch can process a maximum of 50 million records.

Sample Code

public class BatchExample implements Database.Batchable<SObject>,


Database.AllowsCallouts {
public Database.QueryLocator start(Database.BatchableContext
context) {
By Smriti Sharan (sfdcamplified)
return Database.getQueryLocator('SELECT Id, Name FROM
Quote');
}

public void execute(Database.BatchableContext context,


List<Quote> scope) {
// Logic to process each batch of Quotes
for (Quote quote : scope) {
// Callout logic here
// Update quote logic here
}
}

public void finish(Database.BatchableContext context) {


// Logic to run after all batches are processed
}
}

// Example usage
public class BatchCaller {
public void someMethod() {
BatchExample batchJob = new BatchExample();
Database.executeBatch(batchJob, 100);
}
}

2. Schedule the callout to run at the end of the day using a


Scheduled Apex class.
Sample Code

public class ScheduleQuoteCallout implements Schedulable {


public void execute(SchedulableContext ctx) {
QuoteCalloutService.sendQuotesToSAP();
}
}

3.Scheduling the Job:


Use the Salesforce user interface or Developer Console to schedule the
job.
By Smriti Sharan (sfdcamplified)

ScheduleQuoteCallout job = new ScheduleQuoteCallout();


String cronExp = '0 0 23 * * ?'; // Schedule to run at 11 PM every day
System.schedule('Send Quotes to SAP CRM', cronExp, job);

Products are created in Informatica, and these products need


to be imported into Salesforce on a nightly basis? Explain
how you would achieve this integration?
1. Data Flow:
• Products are created in Informatica.
• A nightly batch job runs in Informatica to extract the newly created or
updated products.
• Informatica sends a REST API call to Salesforce to insert or update
the product records.
• Salesforce processes the incoming data and updates its product
records accordingly.

2. This is a Call-In: Informatica (external system) will call Salesforce to


perform operations (insert/update products).
3. Connected App Setup:
• In Salesforce, create a Connected App to enable OAuth
authentication.
• Obtain the Client ID and Client Secret for authentication.

4. OAuth Authentication:
Implement OAuth 2.0 user-agent flow in Informatica to obtain an access
token. This flow is simpler and reduces the need for server-side handling of
OAuth tokens.

5.REST API Endpoint:


By Smriti Sharan (sfdcamplified)
Informatica will use Salesforce's standard REST API to insert or update
product records. Salesforce's standard REST API endpoints, such as
/sobjects/Product2/, are designed for common CRUD (Create, Read,
Update, Delete) operations on Salesforce objects.
Informatica will send HTTP POST requests to the Salesforce REST API
/sobjects/Product2/ endpoint to insert or update product records.

Every night, Informatica runs a batch job to extract newly


created or updated products. These products need to be
automatically created or updated in Salesforce, and for each
product, a corresponding price book entry and inventory
record also need to be created or updated. How would you
achieve this integration?

When a product is created, a corresponding price book entry and inventory


record also need to be created or updated. We would have used custom
logic instead of standard REST API in following scenario.

1. Connected App Setup


• Create a Connected App in Salesforce to enable OAuth
authentication.
• Obtain the Client ID and Client Secret for authentication.

2. OAuth Authentication
• Implement OAuth 2.0 user-agent flow in Informatica to obtain an
access token.
• Use this access token to authenticate API requests to Salesforce.

3.Create the Custom REST API:


By Smriti Sharan (sfdcamplified)
• Define an Apex class with a @RestResource annotation to handle
the API requests.
• Implement the logic to create or update the product, price book entry,
and inventory record within this class.

@RestResource(urlMapping='/ProductIntegration/*')
global with sharing class ProductIntegration {
@HttpPost
global static void createOrUpdateProduct() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;

// Parse JSON request body


Map<String, Object> requestBody = (Map<String, Object>)
JSON.deserializeUntyped(req.requestBody.toString());
// Extract product data
// Insert or update product
// Create or update price book entry
// Create or update inventory record
// Set response
res.statusCode = 201;
res.responseBody = Blob.valueOf('{"message": "Product,
Price Book Entry, and Inventory created or updated successfully"}');
}
}

4. Informatica REST API Call


- Use Informatica to send HTTP POST requests to the custom REST API
endpoint in Salesforce to insert or update product records.

When to Use Custom REST API vs. Standard REST API


Standard REST API: Use for simple CRUD operations where no additional
logic or complex relationships are involved.
By Smriti Sharan (sfdcamplified)
Custom REST API: Use when you need to perform additional logic or
handle complex relationships like creating multiple related records (e.g.
product, price book entry, and inventory record).

You need to display the number of orders associated with an


account in Salesforce without actually storing the order data
in Salesforce. How to achieve this?
This can be achieved using Salesforce Connect and External Objects.

1. Data Flow
• Orders are stored in an external system.
• Salesforce needs to display these orders without storing them.
• Use Salesforce Connect to integrate and display external data as
External Objects in Salesforce.

2. Salesforce Connect Overview


Salesforce Connect allows you to access data stored in external systems
without importing the data into Salesforce. Use External Objects to
represent the data in Salesforce. The data remains in the external system
but is accessible within Salesforce.

3. Define External Data Source


1. Go to Setup in Salesforce.
2. In the Quick Find box, enter External Data Sources and select it.
3. Click New External Data Source
4. Fill in the required details
By Smriti Sharan (sfdcamplified)

4.Validate and Sync External Data Source


1.Click Validate and Sync

2. Select the tables or entities from the external system that you want to
sync (e.g: Orders).
3. Click Sync to create the External Objects in Salesforce.
By Smriti Sharan (sfdcamplified)

Configure External Objects


1. Go to Setup
2. In the Quick Find box, enter External Objects and select it.
3. Find the External Object created during the sync process (e.g., Orders).
4. Configure the fields and relationships as needed.
By Smriti Sharan (sfdcamplified)

Display Orders in Account Page


1.Create a Lookup Relationship field on the External Object to link it to the
Account object. It is Indirect Lookup Relationship. It links a child External
object to a parent Standard or Custom object.
Here an Order (External Child Object) associated with Account (Standard
Salesforce Parent Object).
By Smriti Sharan (sfdcamplified)
2. Go to Object Manager in Salesforce.
3. Select Account and then Page Layouts
4. Edit the page layout to include a related list for the External Object
(Orders).
5. Save the layout.

You are working on integrating Salesforce with SAP CRM.


Both Salesforce and SAP CRM manage quote records. The
integration needs to handle the following:
1. Real-time Updates: When a quote is updated in Salesforce,
the change should be sent instantly to SAP CRM.
2. Nightly Creations: New quotes created in Salesforce
should be sent to SAP CRM at the end of the day in a batch.
How will you achieve this scenario?
Here We need to focus on Real time updates and Nightly creation of
Quotes. This scenario will help us learn when to use which approach.

Real-time Updates: The trigger on the Quote object will use a future
method to handle callouts for real-time updates, ensuring the callout does
not block the main transaction.
Nightly Creation: Batch Apex handles new quote creations by collecting
all new quotes created during the day and sending them to SAP CRM in a
single batch, scheduled to run nightly.

1.Real-time Update Using Future Methods


When a quote is updated in Salesforce, a future method will be used to
make a callout to SAP CRM. This ensures the update is sent to SAP
CRM in real-time.
By Smriti Sharan (sfdcamplified)

1.Create an Apex trigger that listens for updates on the Quote object.
2. Define a future method to handle the callout to SAP CRM.

Apex Trigger:
Sample Code

trigger QuoteTrigger on Quote (after update) {


for (Quote q : Trigger.new) {
//quote status is changed
if (q.Status != Trigger.oldMap.get(q.Id).Status) {
QuoteCalloutService.updateQuoteInSAP(q);
}
}
}

Future Method
Sample Code

public class QuoteCalloutService {


@future(callout=true)
public static void updateQuoteInSAP(Set<Id> quoteIds) {
List<Quote> quotes = [SELECT Id, Name, Status,
CustomField1__c, CustomField2__c FROM Quote WHERE Id IN
:quoteIds];

for (Quote quote : quotes) {


// Prepare the data to be sent
String endpoint = 'xxx’;
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('POST');
By Smriti Sharan (sfdcamplified)
req.setHeader('Content-Type', 'application/json');
req.setBody(JSON.serialize(quote));

// Send the request


Http http = new Http();
HttpResponse res = http.send(req);

// Handle the response


if (res.getStatusCode() != 200) {
System.debug('Error: ' + res.getBody());
}
}
}
}

2. Nightly Creation Using Batch Apex


New quotes created in Salesforce during the day should be sent to SAP
CRM in a batch at the end of the day. This can be scheduled to run nightly.

1. Batch Apex Class: Create a Batch Apex class to collect and send new
quotes.
Sample Code

global class QuoteBatch implements Database.Batchable<SObject>{


global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator([SELECT Id, Name, Status FROM
Quote WHERE CreatedDate = TODAY]);
}

global void execute(Database.BatchableContext bc, List<Quote> scope)


{
for (Quote q : scope) {
// Callout logic to send each quote to SAP
QuoteCalloutService.createQuoteInSAP(q);
}
}
By Smriti Sharan (sfdcamplified)

global void finish(Database.BatchableContext bc) {


// Optional: Post-processing logic
}
}

2. Schedulable Class: Schedule the batch class to run nightly.

global class ScheduleQuoteBatch implements Schedulable {


global void execute(SchedulableContext sc) {
QuoteBatch qb = new QuoteBatch();
Database.executeBatch(qb);
}
}

Schedule this class to run nightly

System.schedule('Nightly Quote Sync', '0 0 23 * * ?', new


ScheduleQuoteBatch());

When a Quote record is updated in Salesforce, it should be


updated in SAP, Azure, and AWS. How will you achieve this
scenario?
Since this involves multiple systems, point-to-point integration is not
efficient. Instead, using Platform Events for a 1-to-many integration is the
ideal solution. This approach leverages the event-driven architecture of
Salesforce and ensures that all connected systems receive the necessary
updates in real-time.

1. Define the Platform Event:


• Create a Platform Event in Salesforce to capture the Quote updates.
• Add necessary fields to the Platform Event to hold the Quote data.
By Smriti Sharan (sfdcamplified)

2. Publish Platform Event:


Update the Quote trigger to publish the Platform Event whenever a Quote
record is updated.

3. Subscribe to Platform Event:


Set up subscribers for SAP, Azure, and AWS to listen to the Platform Event
and process the updates accordingly.

Step-by-Step Implementation:

1. Define the Platform Event


Go to Setup > Platform Events > New Platform Event and define the
QuoteUpdateEvent
By Smriti Sharan (sfdcamplified)

Create Custom Fields:


QuoteId__c , Name__c, Status__c

2. Publish Platform Event


Create an Apex Trigger on the Quote object to publish the
QuoteUpdateEvent whenever a Quote is updated.

trigger QuoteTrigger on Quote (after update) {


List<QuoteUpdateEvent__e> events = new
List<QuoteUpdateEvent__e>();

for (Quote q : Trigger.new) {


//when status is updated
if (q.Status != Trigger.oldMap.get(q.Id).Status) {
QuoteUpdateEvent__e event = new QuoteUpdateEvent__e(
QuoteId__c = q.Id,
Name__c = q.Name,
Status__c = q.Status,
By Smriti Sharan (sfdcamplified)
);
events.add(event);
}
}

if (!events.isEmpty()) {
EventBus.publish(events);
}
}

3. Subscribe to Platform Event


SAP, Azure, and AWS: Each of these systems needs to subscribe to the
QuoteUpdateEvent Platform Event to receive updates.

Whenever an account record is created, updated, or deleted


in Salesforce, the ERP system needs to be updated in real-
time. How to achieve this scenario?
We will use Salesforce Change Data Capture (CDC) for real-time updates.
Why Use CDC and Not Platform Event in this case:
CDC
• CDC is Specifically designed to capture changes in Salesforce data,
including creation, updates, and deletions of records without needing
custom logic.
• Retains change events for up to three days, providing a buffer for
systems to consume the events.
• Automatically includes all field changes in the event data, providing a
complete picture of what changed.
Platform Event
• Platform Events are general-purpose event messaging system
suitable not tailored specifically for data change tracking.
• Requires custom logic to capture changes and publish events, adding
complexity.
By Smriti Sharan (sfdcamplified)
• Typically designed for immediate consumption and may not retain
events as long as CDC.

Step-by-Step Implementation:
1. Enable Change Data Capture (CDC) in Salesforce
• Go to Setup in Salesforce.
• In the Quick Find box, type "Change Data Capture" and select it.
• Select the Account object and enable CDC for this object.

2. Subscribe to the Change Data Capture (CDC) Events in the ERP


System
• Develop a service in the ERP system that listens for CDC events
from Salesforce. It is an option to use the CometD library to subscribe
to the CDC events.
By Smriti Sharan (sfdcamplified)
Your company uses an external service to verify customer
email addresses. When a new Account record is created in
Salesforce, you need to automatically verify the email
address using this external service. The verification process
involves making a callout to the external service's API,
sending the account's email address, and receiving the
verification status and quality score. How to achieve this
scenario?
To achieve this, we will use Salesforce Flow to make an HTTP callout to
the external service's API whenever a new Account record is created.
The Flow will send the account's email address to the external service,
receive the verification response, and update the Account record with the
verification status.

Step by Step Implementation

1: Create a Permission Set


This will allow users to make HTTP callout from Salesforce.
1. Go to Setup:
2. Enter "Permission Sets" in the Quick Find box and select it.
3 Name it HTTP Callout Flow
5. Click "Save".
By Smriti Sharan (sfdcamplified)

2. Add a user to the Permission Set:


Click "Manage Assignments".
Click "Add Assignments".
Select your user and click "Assign".

3: Create an External Credential


1. Go to Setup:
Enter "External Credentials" in the Quick Find box and select it.
2. Click "New".
3. Fill in the details like Label, API Name, Authentication Protocol as
Custom (for free API without client or secret key)
4. Click "Save".
By Smriti Sharan (sfdcamplified)

4.Create a Named Credential


1. Go to Setup:
Enter "Named Credentials" in the Quick Find box and select it.
2. Click "New Named Credential".
3. Fill in the details like Label, Name, URL. Enter the URL of the external
service's API (https://api.abstractapi.com/)
By Smriti Sharan (sfdcamplified)

External Credential: Select the External Credential created earlier

5. Assign the Named Credential to the Permission Set


1. Go to Setup:
Enter "Permission Sets" in the Quick Find box and select the HTTP Callout
Flow Permission Set.
2. Click "External Credential Principal Access".
3. Click "Edit".
4. Select the External Credential and click "Save".

6.Create a Screen Flow

In the Flow Builder, click the "+" icon to add an element.


By Smriti Sharan (sfdcamplified)
Select "Action".

In the Action search box, type "HTTP Callout" and select "Create HTTP
Callout".

7. Configure the HTTP Callout


External Service Name, Named Credential
By Smriti Sharan (sfdcamplified)

HTTP Method: GET


URL Path: /v1/email/validate
Query Parameters:
- api_key (set to the API key obtained from the external service)
- email (set to the Account's email field)
By Smriti Sharan (sfdcamplified)

8. Provide Sample Response:


Copy the sample response from the external service's API documentation.
and paste it into the "Sample Response" field and click "Review".
By Smriti Sharan (sfdcamplified)

7: Add a Decision Element to Check Response Status

8: Add a Screen Element to Display the Response

9: Save and Activate the Flow


By Smriti Sharan (sfdcamplified)

My Name is Smriti Sharan. I am avid blogger and youtuber. Follow my


Blog and youtube to learn various aspect of Salesforce.
https://t.me/sfdcamplified feel free to join telegram group. Feel free to
provide feedback if you find any issue with solutioning.

You might also like