function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
inbox outbox 7inbox outbox 7 

Hi, a silly question in regards to process integration. Can we do a SOAP or REST callout from an apex controller class?

 1. Can we do a SOAP or REST callout from an apex controller class?
If so, how can we do it? Is it from within the @AuraEnabled method?

To give you guys more context, I have some more information below:
Salesforce Lightning—Lightning component or page initiates a synchronous Apex SOAP or REST callout.
Salesforce Classic—A custom Visualforce page or button initiates a synchronous Apex SOAP callout.

A user-initiated action on a Visualforce page or Lightning page then calls an Apex controller action that then executes this proxy Apex class to perform the remote call.


This is a followup question:
2. What about fetch API and fetch() method of Javascript, can't we do a request and response from the client side controller (JS file) itself instead of calling a proxy apex class?
 
AnkaiahAnkaiah (Salesforce Developers) 
Hi,

Refer the below example.
https://www.accidentalcodersf.com/2020/06/lwc-http-callouts-apex-controller.html

Thanks!!