rest api passing the variables to apex method -- w3web.net

How to call an external REST API to get data from API and passing the variables from REST API to apex method in Salesforce using Apex REST Post Methods | How to pass variables from REST API to Apex in Salesforce

648 views

Hey guys, today in this post we are going to learn about How to call an external REST API to get data from API and passing the variables from REST API to apex method and inserting a record into custom object in Salesforce using Apex REST Post Methods.

This example we are passing the variables from REST API to apex method and putting the value into custom object’s fields that is returns from API Using Apex REST post method.

To access the external REST API, First we need to Adding the Remote Site Settings

Follow the Steps:-

Setup ➡ Remote Site Settings ➡ Remote Site Name ➡ Enter the URL for the remote site

Files we used in this post example

restApiPostMethodCmp.cmp Lightning Component It is used to get data from API and passing the variables from REST API to apex method in salesforce.
restApiPostMethodCmpController.js JavaScript Controller File It is hold Javascript calloutCtrl function.
restApiPostMethodCmpHelper.js JavaScript Controller Helper File It is hold Javascript Helper getResponse function to get data from API calling through apex class method.
restApiPostMethodCmpCtrl.apxc

Apex Class Controller It is used to get data from API and passing the variables from REST API to apex method through Rest Apex class method.
Custom Object

Object Name:- Pan_Verification__c
Object’s Fields Name:- API_Name__c, Application_Number__c, Success_Status__c, Process_Status__c, Pan_Number__c, DOB__c, User_Name__c

Final Output

rest api get method example in salesforce -- w3web.net

 

Other related post that would you like to learn in Salesforce

 

Find the below steps:-

Create Lightning Component

Step 1:- Create Lightning Component : restApiPostMethodCmp.cmp

From Developer Console >> File >> New >> Lightning Component

restApiPostMethodCmp.cmp [Lightning Component File]

Create Component JavaScript Controller

Step 2:- Create Lightning Component : restApiPostMethodCmpController.js

From Developer Console ➡ File ➡ New ➡ Lightning Component ➡ JavaScript Controller

restApiPostMethodCmpController.js [JavaScript Controller]

Create Component JavaScript Helper

Step 4:- Create Lightning Component : restApiPostMethodCmpHelper.js

From Developer Console ➡ File ➡ New ➡ Lightning Component ➡ JavaScript Helper

restApiPostMethodCmpHelper.js [JavaScript Helper File]

Create Apex Class Controller

Step 5:- Create Apex Class : restApiPostMethodCmpCtrl.apxc

From Developer Console ➡ File ➡ New ➡ Apex Class

restApiPostMethodCmpCtrl.apxc [Apex Class Controller]

Create Lightning Application

Step 1:- Create Lightning Application : restApiPostMethodApp.app

From Developer Console ➡ File ➡ New ➡ Lightning Application

restApiPostMethodApp.app [Component Application File]

rest api get method example in salesforce -- w3web.net

 

Further post that would you like to learn in Salesforce

 

 

 

FAQ (Frequently Asked Questions)

How do you call an API in Salesforce?

To call third-party APIs from your component's JavaScript code, add the API endpoint as a CSP Trusted Site. To call Salesforce APIs, make the API calls from your component's Apex controller. Use a named credential to authenticate to Salesforce.

How do you call an external service from Salesforce?

Connect your Salesforce org to an external API using zero lines of code. Use declarative tools and OpenAPI specifications to describe the external API functionality, and External Services creates invocable actions within Salesforce. Use the invocable actions to create a flow that interacts with the external API source.

Can we call API from trigger in Salesforce?

The trigger will make a REST API call to Salesforce and will insert/update the record in the 'Account' object in Salesforce.

Related Topics | You May Also Like

  • Your reaction of the article ▾
 

Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

3 thoughts on “How to call an external REST API to get data from API and passing the variables from REST API to apex method in Salesforce using Apex REST Post Methods | How to pass variables from REST API to Apex in Salesforce”

Leave a Comment