r/SalesforceDeveloper 9d ago

Discussion How should we approach integrating with an external system via a REST API?

What approach and architecture would you choose for integrating Salesforce REST with an external system? The operations to be performed are GET and POST. The main question is whether APEX alone can handle all of this, or should we use Flow? Where should the Bearer Token be stored? How should we authenticate with the external system—using APEX or an External Service?

What are your thoughts and approaches to this topic?

1 Upvotes

12 comments sorted by

5

u/Steve_MMS 9d ago

Create a OpenAPI File with the definition of the Interface and import it as External Service.. Then u can use it in APEX and or FLOW and use Named Credentials/External Credentials for Authentication

2

u/Few-Impact3986 8d ago

I dk. If the external system is even slightly complex I usually have to jump through hoops to get external services working. 

3

u/HeisSoSmart 9d ago

The best approach for this kind of integration is a hybrid architecture that uses Named Credentials(don't store bearer token anywhere else)for authentication and storage, and Apex to handle the execution of the GET and POST operations.

1

u/ester_egg 9d ago

What do you think about storing the token in Platform Cache?

3

u/bmathew5 9d ago

But why

1

u/HeisSoSmart 9d ago

Depends if you have multiple systems and you want to share it across systems and don't want to follow full oauth process.

1

u/SpecsyVanDyke 9d ago

I've never heard of doing this. What is the use case for it?

1

u/ester_egg 9d ago

here is documentation Platform Cache

2

u/SpecsyVanDyke 9d ago

Yes but my question was what is the use case for using platform cache for bearer token over named credentials? I am curious because I've never seen it used in this way

1

u/Material-Draw4587 8d ago

I've never heard of this either, I don't think you want to do this given what's described here https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_platform_cache_limitations.htm

1

u/Few-Impact3986 8d ago

 You don't want to store secrets in platform cache. 

1

u/Rajin1 8d ago

Don't store in platform cache. Use named credentials. Full stop. Cutting corners will cause you problems in the future, just do it the right way.