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

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 lightning component.

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 lightning component.

Related Topics | You May Also Like

Hi, This is Vijay 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.

2 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