Friday, February 14, 2025

Salesforce Integration Interview Questions on REST API Part-8

1) What is the difference between @HttpPatch and @HttpPut annotations in Salesforce?

@HttpPatch is used to partially update a resource, meaning it modifies only specific fields of the resource without replacing it entirely.

@HttpPut is used to fully replace or update the entire resource with the provided data, meaning it requires the full object to be replaced.

2) What is the purpose of the @RestResource annotation in Salesforce?

The @RestResource annotation is used at the class level to expose an Apex class as a REST resource. It is required for creating custom RESTful services in Salesforce, allowing external applications to interact with Salesforce data via HTTP requests. The urlMapping parameter defines the URL pattern for the resource.

3) What are different Apex REST annotations in Salesforce?

1. @RestResource
This annotation is used at the class level to expose an Apex class as a REST resource. The class must be defined as global, and the urlMapping parameter specifies the URL pattern to access the resource.

2. @HttpDelete
This annotation is used to delete a specified resource via a DELETE request. It marks the method as handling HTTP DELETE operations.

3. @HttpGet
This annotation is used to retrieve a specified resource via a GET request. The method marked with @HttpGet is responsible for fetching data from Salesforce.

4. @HttpPatch
This annotation is used to partially update a resource. It modifies only specific parts of the resource, as specified by the incoming request.

5. @HttpPost
This annotation is used to create a new resource in Salesforce via a POST request. It is commonly used to create new records.

6. @HttpPut
This annotation is used to either create or fully update a resource. It replaces the entire resource with the data received in the request.

4) What is the RestRequest class in Salesforce, and what are some of its key methods?

The RestRequest class in Salesforce is used to access incoming requests in Apex REST web services. It provides several methods to handle different aspects of an HTTP request. Some key methods include:

headers: Returns the headers received by the request (Map<String, String>).
httpMethod: Returns the HTTP method used for the request (String), such as GET, POST, DELETE, etc.
params: Returns the parameters received by the request (Map<String, String>).
remoteAddress: Returns the IP address of the client making the request (String).
requestBody: Returns or sets the body of the request (Blob).
requestURI: Returns or sets everything after the host in the HTTP request string (String).
resourcePath: Returns the REST resource path for the request (String).

5) What is the RestResponse class in Salesforce, and what are some of its key methods?

The RestResponse class in Salesforce is used to pass data from an Apex RESTful web service method to the HTTP response. It has several key methods:

responseBody: Returns or sets the body of the response (Blob).
headers: Returns the headers to be sent in the response (Map<String, String>).
statusCode: Returns or sets the HTTP status code for the response (Integer). Common status codes include 200 (OK), 201 (Created), 400 (Bad Request), etc.

For example, if you want to change the default status code of a RESTful service response, you can modify the statusCode property of the RestResponse class, like setting it to 201 (Created) instead of 200 (OK).

6) What is the purpose of the @HttpGet annotation in Salesforce, and how is it used in Apex?

The @HttpGet annotation in Salesforce is used to expose an Apex method as a RESTful GET service. This annotation allows external systems to retrieve data from Salesforce by making an HTTP GET request to the defined URL. The method must be defined as global static within a class annotated with @RestResource. For example, a method annotated with @HttpGet can fetch records like an Account based on an ID provided in the request URL.

7) Can you provide an example of how the @HttpGet annotation works in a Salesforce Apex class?

Here's an example of how the @HttpGet annotation works in an Apex class:

@RestResource(urlMapping='/getAccountOnExternalIdtofetchsinglerecord/*')
global with sharing class getAccounttoSingleRecord {
    @HttpGet
    global static Account fetchAccount() {
        RestRequest req = RestContext.request;
        string accId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account obj = [SELECT Id, Name FROM Account WHERE Id = :accId];
        return obj;
    }
}

In this example, the @HttpGet annotation allows the fetchAccount() method to be called when an HTTP GET request is made to the URL /services/apexrest/getAccountOnExternalIdtofetchsinglerecord/{accountId}. The method fetches the Account record based on the ID from the URL and returns the record in JSON format.

8) Can you explain how Salesforce handles multiple HTTP methods in a single Apex class, and what restriction exists regarding their usage?

In Salesforce, a single Apex class can expose multiple HTTP methods (GET, DELETE, POST, PUT, PATCH) through different annotated methods. However, each method can only be annotated with one of these HTTP methods—only one method per HTTP method type is allowed in a class. For example, you can have one method annotated with @HttpGet, another with @HttpPost, and so on, but you cannot have multiple methods using the same annotation (e.g., two @HttpGet methods in the same class). This ensures each HTTP action is uniquely handled by its corresponding method.

9) How can you use the @HttpGet annotation with parameters in the URL in Salesforce?

In Salesforce, the @HttpGet annotation can be used to define a web service that handles GET requests. If parameters are passed in the URL, you can use the params variable of the RestRequest class. The params variable returns a Map<String, String> that contains the parameters received by the request.

For example, if you want to create a web service that fetches a Contact record based on email and phone as parameters, you would use the following code:

@RestResource(urlMapping='/getContactFromEmailAndPhone/*')
global with sharing class getContactRecord {

    @Httpget
    global static Contact fetchContact() {
        Contact obj = new Contact();
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        
        Map<String, String> requestParam = req.params;
        String conEmail = requestParam.get('email');
        String conPhone = requestParam.get('phone');
        
        obj = [SELECT id, lastname, email, phone FROM Contact WHERE email = :conEmail AND phone = :conPhone];
        
        res.statusCode = 201;  // Modify HTTP status code to be returned to the external system
        return obj;
    }
}

This web service can be accessed using a URL like /services/apexrest/getContactFromEmailAndPhone?email=testemail2@gmail.com&phone=123. The parameters email and phone are retrieved from the URL and used to query the Contact record.

10) What are named credentials in Salesforce and how do they improve security when integrating with external services?

Named credentials in Salesforce provide a secure and declarative way to store and manage the authentication details (like usernames, passwords, or OAuth tokens) required for HTTP callouts to external systems. They allow developers to specify the endpoint URL and authentication parameters in one definition, simplifying the setup of authenticated callouts. Named credentials eliminate the need for remote site settings and ensure credentials are stored encrypted, enhancing security. They also make maintaining integrations easier—if an endpoint URL changes, only the named credential needs to be updated, and all related callouts remain functional without modifying the Apex code.

Gain a deep understanding of Salesforce integration, from creating and configuring Connected Apps to mastering advanced topics like OAuth flows, SAML-based Single Sign-On, and Streaming APIs. Our PDF course combines practical examples, real-time scenarios, and integration patterns to equip professionals with the skills needed to streamline processes and enhance productivity. Tailored for those with 2–8 years of experience, it’s your guide to unlocking seamless connectivity between Salesforce and other systems.

Link to course : Mastering Salesforce Integration

Friday, February 7, 2025

Salesforce Integration Interview Questions Platform Event Limits Part-7

1) What is the High-Volume Platform Event Hourly Publishing Allocation?

It specifies the maximum number of platform events that can be published in one hour. The limit is 250,000 events per hour for Performance and Unlimited Editions.

2) What is the High-Volume Platform Event and Change Event Daily Delivery Allocation?

It defines the total number of platform and change events that can be delivered to subscribers in a 24-hour period. The limit is 50,000 deliveries per day for Performance and Unlimited Editions.

3) What publishing methods count toward the hourly publishing limit?

Publishing methods include:

  • Apex
  • Pub/Sub API
  • REST API
  • SOAP API
  • Bulk API
  • Flows
  • Process Builder processes
4) Which delivery methods count toward the daily delivery limit?

Delivery methods include:

  • Pub/Sub API
  • CometD
  • empApi Lightning component
  • Event relays
5) Which actions are excluded from the daily delivery allocation?

The following actions don’t count toward the delivery limit:

  • Apex triggers
  • Flows
  • Process Builder processes
6) How is the hourly publishing usage calculated?

Each published event counts as one unit against the hourly publishing limit, regardless of the publishing method. For example, publishing 1,000 events in an hour counts as 1,000 against the limit.

7) How is the daily delivery usage calculated?

Each event delivered to a subscriber is counted separately. For instance: Publishing 1,000 events to 10 subscribers counts as 10,000 deliveries (1,000 × 10).

8) What happens if you exceed the hourly publishing limit?

Events published beyond the limit will fail. Organizations must monitor and optimize their event publishing to stay within the allowed limits.

9) What is the purpose of the Platform Event Add-On License?

The add-on increases event delivery and publishing limits, providing flexibility during usage spikes. It enables organizations to handle higher volumes of platform event usage.

10) What are the primary benefits of the add-on license?
  • Increased Daily Delivery Allocation: Adds 100,000 events per day (3 million per month).
  • Enhanced Hourly Publishing Allocation: Adds 25,000 events per hour.
  • Flexibility for Usage Spikes: Allows for temporary exceedance of daily delivery limits.
11) How does the add-on affect daily event delivery limits?

With the add-on:

  • The daily delivery allocation increases to 150,000 events (50,000 included + 100,000 from the add-on).
  • The monthly entitlement reaches 3 million events.
12) How does the add-on affect hourly publishing limits?

It increases the hourly publishing limit by 25,000 events, resulting in a total of 275,000 events per hour for Performance and Unlimited Editions.

13) What steps should an organization take to maximize its event delivery capabilities?

  • Monitor and optimize event usage.
  • Purchase the add-on license if higher limits are required.
  • Contact Salesforce for guidance on best practices.

Gain a deep understanding of Salesforce integration, from creating and configuring Connected Apps to mastering advanced topics like OAuth flows, SAML-based Single Sign-On, and Streaming APIs. Our PDF course combines practical examples, real-time scenarios, and integration patterns to equip professionals with the skills needed to streamline processes and enhance productivity. Tailored for those with 2–8 years of experience, it’s your guide to unlocking seamless connectivity between Salesforce and other systems.

Link to course : Mastering Salesforce Integration

Saturday, February 1, 2025

Salesforce Integration Interview Questions Change Data Capture Part-6

 1) What is Change Data Capture (CDC)?

Change Data Capture is a streaming product in Salesforce that enables real-time integration with external systems. It notifies subscribed systems of data changes like record creation, updates, deletions, and undeletions, helping keep external systems in sync without periodic data exports or repeated API calls.

2) What types of objects support CDC?

CDC is available for all custom objects and a subset of standard objects. Each object has an associated ChangeEvent object, named <ObjectName>ChangeEvent for standard objects and <ObjectName>__ChangeEvent for custom objects.

3) Can CDC events be queried or modified?

No, ChangeEvent objects don’t support CRUD operations or queries. They are used to capture and publish changes but cannot be directly manipulated.

4) How does CDC handle security for fields in change events?

CDC respects field-level security, delivering only the fields a user has access to. However, it ignores record-level sharing settings and doesn’t include derived fields (e.g., formula fields) except for roll-up summary fields.

5) What fields are excluded in CDC event messages?

Excluded fields include:

  • IsDeleted
  • SystemModStamp
  • Formulae Fields (except roll-up summary fields).

6) What are the steps to enable Change Data Capture?

  1. Navigate to Setup > Change Data Capture in Salesforce.
  2. Select the desired custom and standard objects from the Available Entities list.
  3. You can enable up to five entities by default. For more, purchase an add-on license.
  4. Save the settings.

7) Provide an example of subscribing to CDC events using the Workbench.

  1. Open Workbench > Queries > Streaming Push Topics.
  2. Click Generic Subscriptions and enter /Data/AccountChangeEvent.
  3. Click Subscribe to establish the connection.

Updates to the Account record will trigger notifications visible in the Workbench.

8) What happens if you need different subscribers to receive specific event types?

Use custom channels to group and isolate change events for different subscribers. This ensures that each subscriber receives only the events they need.

9) What are the licensing constraints for CDC?

  • Default: Up to 5 entities.
  • Add-on license: Select up to 10 entities per channel and increase delivery allocations. After selecting the first 10 entities, you can add more.

Gain a deep understanding of Salesforce integration, from creating and configuring Connected Apps to mastering advanced topics like OAuth flows, SAML-based Single Sign-On, and Streaming APIs. Our PDF course combines practical examples, real-time scenarios, and integration patterns to equip professionals with the skills needed to streamline processes and enhance productivity. Tailored for those with 2–8 years of experience, it’s your guide to unlocking seamless connectivity between Salesforce and other systems.

Link to course : Mastering Salesforce Integration

Friday, January 24, 2025

Salesforce Integration Interview Questions Platform Event Part-5

 1) How can you publish a platform event using Apex?

You can publish a platform event using the EventBus.publish() method in Apex. Here's how:

  • Create an instance of the platform event object and populate its fields.
  • Use EventBus.publish() to publish the event, which returns a Database.SaveResult.
  • Check isSuccess() on the result to determine whether the event was published successfully.
TestEvent__e event = new TestEvent__e(
    Customer_Country__c = 'India',
    Customer_State__c = 'Maharashtra',
    Government_Customer__c = true
);
Database.SaveResult result = EventBus.publish(event);
if (result.isSuccess()) {
    System.debug('Platform event published successfully.');
} else {
    for (Database.Error error : result.getErrors()) {
        System.debug('Error: ' + error.getMessage());
    }
}

2) What is the difference between ReplayId and EventUuid in platform events?

  • ReplayId: A system-assigned field that identifies the position of an event in the event stream. It isn’t guaranteed to be unique, especially during Salesforce maintenance activities.
  • EventUuid: A universally unique identifier (UUID) introduced in API version 52.0 and later. It is always unique and should be used to identify a platform event message.

  • Example of Retrieving EventUuid:

    Database.SaveResult result = EventBus.publish(event);
    if (result.isSuccess()) {
        System.debug('UUID=' + EventBus.getOperationId(result));
    }

    Using EventUuid ensures the identification of an event message across different scenarios, including maintenance activities.

    3) What are the Apex governor limits for platform event triggers?

    Although platform event triggers run asynchronously, the synchronous limits apply to platform event triggers. This is because Asynchronous limits are for long-lived processes, such as Batch Apex and future methods. Synchronous limits are for short-lived processes that execute quickly and platform event triggers are short-lived processes that execute in batches rather quickly.

    Because a platform event trigger runs in a separate transaction from the one that fired it, governor limits are reset, and the trigger gets its own set of limits.

    4) How can you configure the user and batch size for a platform event trigger?

    You can override the default running user and batch size of a platform event trigger using PlatformEventSubscriberConfig via Tooling API or Metadata API.
    • Default Configuration: Runs as the Automated Process user with a batch size of 2,000.
    • Custom Configuration: Specify a custom user and a batch size between 1 and 2,000. Smaller batch sizes help avoid hitting governor limits.
    5) How to create and manipulate PlatformEventSubscriberConfig?

    We can create PlatformEventSubscriberConfig from workbench as shown below. To add a configuration, perform a POST request to this endpoint.

    Salesforce Integration Interview Questions Platform Event


    Also, you can query retrieve the configurations in your org with SOQL. If querying from the Developer Console Query Editor, ensure you select Use Tooling API. This example query retrieves all configurations set up in your Salesforce org.

    SELECT Id,DeveloperName,BatchSize,PlatformEventConsumerId,UserId FROM PlatformEventSubscriberConfig

    To get or manipulate a configuration, use this endpoint with the ID of your PlatformEventSubscriberConfig record appended.

    /services/data/v60.0/tooling/sobjects/PlatformEventSubscriberConfig/<ID>

    You can also,

    ·         Delete a specific configuration with a DELETE request.

    ·         Update a specific configuration with a PATCH request. For this request, include the PlatformEventSubscriberConfig definition in the request body.

    6How do you subscribe to platform events using CometD?

    To subscribe to platform events, use the channel name /event/Event_Name__e in a CometD client. For example, to subscribe to a TestEvent__e platform event, use the channel /event/TestEvent__e. The CometD client receives real-time event notifications in JSON format.

    7) How can you encrypt platform event messages in the event bus?

    To encrypt platform event messages:

    1. Create an event bus tenant secret in the Key Management page in Setup.
    2. Enable encryption for platform events on the Encryption Policy page.
      Without Shield Encryption, messages are stored in clear text in the event bus.
    8) How can you monitor platform event usage?

    Use the PlatformEventUsageMetric object to monitor event publishing and delivery usage. Example queries:

    To retrieve the usage of platform events:

    Events Delivered (April 26, 2024, 11:00 to April 27, 2024, 11:00):

    SELECT Name, StartDate, EndDate, Value 

    FROM PlatformEventUsageMetric 

    WHERE Name='PLATFORM_EVENTS_DELIVERED' 

    AND StartDate=2024-04-26T11:00:00.000Z 

    AND EndDate=2024-04-27T11:00:00.000Z

    Events Published (April 26, 2024, 11:00 to April 27, 2024, 11:00):

    SELECT Name, StartDate, EndDate, Value 
    FROM PlatformEventUsageMetric 
    WHERE Name='PLATFORM_EVENTS_PUBLISHED' 
    AND StartDate=2024-04-26T11:00:00.000Z 
    AND EndDate=2024-04-27T11:00:00.000Z

    Publishing Methods: Apex, APIs (Pub/Sub API), Flows, and Process Builder.

    Subscription Methods: CometD, Pub/Sub API, empApi Lightning components, and event relays.

    Note: Delivery metrics exclude event deliveries to Apex triggers, flows, and processes.

    Gain a deep understanding of Salesforce integration, from creating and configuring Connected Apps to mastering advanced topics like OAuth flows, SAML-based Single Sign-On, and Streaming APIs. Our PDF course combines practical examples, real-time scenarios, and integration patterns to equip professionals with the skills needed to streamline processes and enhance productivity. Tailored for those with 2–8 years of experience, it’s your guide to unlocking seamless connectivity between Salesforce and other systems.

    Link to course : Mastering Salesforce Integration

    Friday, January 17, 2025

    Salesforce Integration Interview Questions Platform Event Part-4

    1) What is the purpose of Salesforce Streaming API?

    The Salesforce Streaming API enables real-time data updates using push technology and an event-driven architecture. It operates on an event-based model, allowing applications to subscribe to events and receive updates as they occur in near real-time.

    2) What types of events are supported by the Salesforce Streaming API, and in which scenarios should it be used?

    Types of Events Supported:

    1. Generic Events: Legacy, for custom notifications.
    2. PushTopics: Legacy, for changes in Salesforce records based on SOQL queries.
    3. Change Data Capture (CDC): For tracking changes to Salesforce data records in real-time.
    4. Platform Events: For high-volume, custom business event notifications.

    When to Use the Streaming API:
    Use Streaming API when real-time data updates are required to synchronize external systems with Salesforce data, such as in applications that react immediately to changes in data or business processes.

    Note: PushTopics and generic events are legacy products with limited support. For new implementations, use Change Data Capture instead of PushTopics and Platform Events instead of generic events.

    3) What are platform events in Salesforce?

    Platform events are secure and scalable messages used to enable real-time communication between Salesforce and external apps, as well as within Salesforce itself, using an event-driven messaging architecture.

    4) What is the Event Bus in Salesforce?

    The event bus is a temporary storage system where platform event messages are published. Events on the bus can be retrieved using a CometD client, and each event contains a ReplayId field to identify its position in the stream.

    5) What are standard platform events, and how can they be used?

    Standard platform events, such as AssetTokenEvent and BatchApexErrorEvent, are predefined by Salesforce for specific purposes like monitoring authentication or reporting errors. Custom platform events can also be defined and published using Apex, Process Builder, Flow Builder, or APIs, and subscribed to via triggers or external apps.

    6) How are platform events published in Salesforce?

    Platform events can be published:

    • Immediately: Messages are sent as soon as they are generated and cannot be rolled back.
    • After Commit: Messages are sent only after a transaction is committed, and they support rollback using setSavepoint() and rollback().

    7) What are high-volume platform events, and how are they different from standard-volume events?

    High-volume platform events, introduced in API version 45.0, allow for better scalability and can handle millions of events. They are always published asynchronously for efficient processing. Standard-volume events are no longer available for new definitions but are supported for existing implementations.

    8) What is the retention period for platform event messages on the event bus?

    • High-Volume Events: Retained for 72 hours (3 days).
    • Standard-Volume Events: Retained for 24 hours (1 day).

    9) What is the ReplayId field in platform event messages?

    The ReplayId field is a system-generated, opaque identifier for an event in the stream. It helps subscribers retrieve missed events during resubscription within the retention window. Replay IDs are not guaranteed to be unique.

    Gain a deep understanding of Salesforce integration, from creating and configuring Connected Apps to mastering advanced topics like OAuth flows, SAML-based Single Sign-On, and Streaming APIs. Our PDF course combines practical examples, real-time scenarios, and integration patterns to equip professionals with the skills needed to streamline processes and enhance productivity. Tailored for those with 2–8 years of experience, it’s your guide to unlocking seamless connectivity between Salesforce and other systems.

    Link to course : Mastering Salesforce Integration