-1

What is the easiest way to have a HTTP call from a JavaScript to create records in Salesforce?

I have almost no experience with API connections, but with apps from the app store such as formassembly etc.

How easy is it to set up a connection to have a JavaScript being able to perform a HTTP call?

Thanks a lot in advance for any advice, even if it is a developer, who would be able to assist here.

OK, thx for all your comments so far, i will be more detailed about what we are trying to achieve:

I have a enterprise org and i have a customer, who is familiar with javascript and he wants to create records in a custom object via http call. So i think, it needs to have a rest api call, right? But i have no clue, what to do to make it possible for him to create these records. He is definitely familiar with javascript and coding of a http call, but what in detail do i need to prepare to make him able to setup such calls?

PS: i will definitely do a trailhead and a developer course to be able to do such things and more, but the request is actually kinda urgent.

  • 1
    Easiest way to get javascript to talk to salesforce would be to use connection.js, to set up a script to run queries or call apex web services. – battery.cord Apr 11 '18 at 19:20
  • 2
    Id also recommend making an edit to your question to include exactly what you're trying to do, and in what context (visualforce page, external site, lightning component, etc). – battery.cord Apr 11 '18 at 19:21
  • 1
    If you can provide exactly what the requirements are, we can assist better. – the_phantom Apr 11 '18 at 19:24
  • 1
    Using ForceTk library is an option but as I asked please provide more info. github.com/developerforce/Force.com-JavaScript-REST-Toolkit – the_phantom Apr 11 '18 at 19:45
  • @battery.cord edited ;) – Ralf Wittenberger Apr 11 '18 at 22:45
1

We have used Jsforce to interact with Salesforce from Javascript. Since it needs authentication token, you would want to get session token from currently logged in user and use that.

Second thing you need to keep in mind is API usage. Since that library uses Rest APIs, each invocation is counted towards your daily API limit. Check the API limit and usage in your org to make sure that is not a problem.

1

Start by taking a look at REST API Developer Guide

Then look at this previous questions: How to call a Salesforce REST URL from Lightning Component?

1

Let's make few assumptions first before I answer this question.

  1. Your client wants to use JS to create records in Salesforce org. Not sure why using JS with Http is such a hard requirement. Anyway, we will proceed ahead with this assumption.
  2. You are using either Classic or Lightning. The best way to use JS can differ based on the context. For example, in Classic, you can use Visualforce page or a JS Custom Button to initiate JS calls OR you can use Lightning Component.

Solutions:

  1. Visualforce page: The most simplest way to create Salesforce records using JavaScript in VF page will be to use Salesforce Ajax Toolkit. There are various API calls defined in this library that can be used to perform CRUD operations on Salesforce records. For example, to create sObject records, you can simply use sforce.connection.create API call using this toolkit. This library uses SOAP API behind the scenes to connect with Salesforce and you do not need to write any custom authentication logic. It is ideal for scenarious where you need to create up to 200 records in one go. The same library can also be used in Custom Buttons to create records.
  2. Using external JS libraries: As datasert mentioned, you can use libraries like JSForce OR ForceTK. There can be other libraries as well.
  3. You can also use Visualforce Remote Objects. It is an efficient method for building Web apps with Visualforce, especially for creating pages for use in the Salesforce app or working with JavaScript libraries such as jQuery or AngularJS. Visualforce Remote Objects are proxy objects that enable basic DML operations on sObjects directly from JavaScript.
  4. You can also use Javascript remoting in conjunction with Apex to perform simple or complex DML operations.
  5. Using Lightning Component is preferred if you are using Lightning experience. You can create custom lightning components and leverage its JS Controller and Helper with Apex to create complex business logic.

Therefore, you can see that there are ways to use JS in Salesforce to create records in Salesforce. I do not see why using HTTP calls is absolutely needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.