Anablock Logo

Mastering Salesforce Integration: A Comprehensive Guide to APIs with Apex and Aura Component Examples

Himanshu Varshney profile picture
Himanshu Varshney
Senior Salesforce Developer
January 11, 2024

SFApexExampleApi

REST API

Purpose: Used for accessing resources in any format (XML, JSON, etc.) over HTTP with a wide range of functionalities.

Example in Apex:

HttpRequest req = new HttpRequest();
req.setEndpoint('https://yourinstance.salesforce.com/services/data/vXX.0/sobjects/Account/');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);

Example in Aura Components:

action.setParams({
  "request": req
});


SOAP API

Purpose: Primarily used for integrating with enterprise systems, supporting XML-based messaging.

Example in Apex: Apex does not natively consume SOAP; it's typically used on the external system to call into Salesforce.


Bulk API

Purpose: Optimized for loading large sets of data asynchronously. It's efficient for querying large datasets.

Example in Apex:

AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
                  TotalJobItems, CreatedBy.Email
                  FROM AsyncApexJob WHERE Id = :jobID];


Metadata API

Purpose: Used for managing customization and building tools that can manage the metadata model, not the data itself.

Example in Apex: Typically used via tools like ANT migration tool, not directly accessible in Apex.


Streaming API

Purpose: Useful for receiving notifications for changes to Salesforce data (in near real-time).

Example in Aura Components: Aura Components can subscribe to a channel to receive notifications.

$A.get("e.empApi:subscribe").setParams({
    channel: '/event/My_Event__e',
    replayId: -1
}).fire();


Tooling API

Purpose: Allows you to build custom development tools or apps for Salesforce platforms. It provides endpoints for describing, querying, and modifying your metadata.

Example in Apex:

HttpRequest req = new HttpRequest();
req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/vXX.0/tooling/query?q=Select+Id,Name+From+ApexClass');
req.setMethod('GET');


Chatter REST API

Purpose: Used for accessing Salesforce Chatter feeds and social data such as users, groups, followers, and files.

Example in Apex:

ConnectApi.FeedItem fi = ConnectApi.ChatterFeeds.postFeedItem(null, ConnectApi.FeedType.News, 'me', 'Hello World', null);


UI API

Purpose: Lets you build UI for viewing Salesforce data, loading records, and saving changes back to the server.

Example in Aura Components:

var action = component.get("c.getRecord");
action.setParams({ recordId : component.get("v.recordId") });


Analytics API

Purpose: Used for running reports and accessing analytics data.

Example in Apex: Not typically used directly in Apex; more for external systems.


Composite API

- **Purpose**: Allows you to combine multiple requests into a single call.
- **Example in Apex**:
  ```apex
  HttpRequest req = new HttpRequest();
  req.setEndpoint('https://yourinstance.salesforce.com/services/data/vXX.0/composite/');
  req.setMethod('POST');

Each API serves a specific purpose and offers different capabilities. Apex and Aura Components can leverage these APIs to create powerful, integrated Salesforce applications. The examples provided demonstrate basic usage and would need to be adapted to your specific requirements.

Share this article:
View all articles

Want to learn more about our healthcare solutions?

Discover how our AI technology can transform your healthcare practice.

Related Articles

The Best Platforms for Running Dental Ads in 2025 featured image
June 27, 2025
The dental advertising landscape has evolved dramatically, with 2025 presenting unprecedented opportunities for practices to connect with potential patients across diverse digital platforms. Gone are the days when Yellow Pages ads and local newspapers dominated practice marketing strategies.
How to Build Awareness Around Your Emergency Dental Services featured image
June 26, 2025
This blog post by Anablock explores proven strategies to increase visibility for your emergency dental services, from digital marketing tactics to community partnerships. Whether you're looking to expand your current emergency offerings or launch a new after-hours program, these insights will help you connect with patients in crisis while building sustainable practice growth.
From Zero to Fully Booked: A Digital Marketing Roadmap for Dentists featured image
June 25, 2025
In today's dental landscape, building a thriving practice requires more than clinical excellence, it demands a strategic digital marketing approach. With patients increasingly turning to online platforms to find, research, and book dental services, practices that master digital marketing gain a significant competitive advantage.