1

I tried searching the differences between making callouts from LWC javascript controller or from Apex Class.

Simple scenario is displaying an array of data in a datatable in a LWC. Are there any differences? Can you provide information on this topic?

1 Answer 1

3

Making directly from javascript is possible, but in my experience a lot of times you will run into issues because of CORS policies.

The main difference though is that javascript runs directly in the user's browser, so callouts from javascript don't go through salesforce's servers. This can mainly be important if your users are on a vpn and need to access a resource that is not accessible outside the vpn. In that case a callout from apex is not possible.

In most cases though, web services are secured to not be accessible from other websites than they were explicitly designed for. They use CORS policies to make sure you can't call them from the frontend. In that case you have to make the callout from a server, which will usually be apex, but could also be a heroku or similar service that you call from your javascript controller.

1
  • Thanks a lot man!
    – DevelBase2
    Commented Mar 11, 2022 at 14:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .