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
Dhruv Khattar 8Dhruv Khattar 8 

Authorized URL for Apex Class?

I want to create a schedulable APEX class that fetches data from an external system using their REST API. For the other system, the developer needs to create an app, and enter an authorized URL for my "app".

How does one get a URL to my Apex class that his app can redirect to?

Thanks for your help!

BP SinghBP Singh
If I understand your question correctly, you want a third party system to be able to interact with your Apex.

This can be achieved via Apex REST API or Apex SOAP API:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_web_services.htm

For authorization, please refer here:
https://developer.salesforce.com/docs/atlas.en-us.208.0.api_rest.meta/api_rest/quickstart_oauth.htm

You may choose either mechanism i.e. OAuth 2.0 or Session ID.
Laxman Vattam 26Laxman Vattam 26
For calling external REST service from Salesforce, you can refer the sample code here: 
https://yoursalesforceguide.blogspot.com/2016/12/calling-external-rest-service-from.html

Call back URL is important only when another website is interacting wtih Salesforce. In your case, you can just redirect to http://localhost:8080
Dhruv Khattar 8Dhruv Khattar 8

@Laxman

I DO have an external system/website that I need to fetch data from. I need to request an authentication token to make data requests from that system. The external website needs a redirect URI to my application (APEX class) to be able to send that authentication token to it. Wondering what that redirect URI is for my apex class (or how I obtain it).

Tle link that BP Singh shared is the flip-side of my situation (i.e. the app that's being configured on the external service) and I need to provide the callback URI for that application.

BP SinghBP Singh
Dhruv,

As I mentioned in my previous comment, you need to make use of either Apex REST API or Apex SOAP API to expose a URL for your apex class so that external system can invoke it.

Let me explain with a quick high level template for Apex REST API,

@RestResource(urlMapping='/TestCallbackUri/*')
global class ApexRESTMyExample {
@HttpPost
global static void myPostTestMethod(String s1, String s2) {
//ToDo: Business Logic 
}
 
@HttpGet
global static String myGetTestMethod() {
//ToDo: Business Logic 
}
}

URI for this will be: https://yourinstance.salesforce.com/services/apexrest/TestCallbackUri
POST request will invoke method myPostTestMethod
GET request will invoke method myGetTestMethod

Hope this helps.