0

I need connect an application with salesforce. This aplication will send data to the system, and salesforce work with them. In this case, in the third application, user choose products. When user finish, the information of this products (name, price, quantity, ..) are sending to SFDC, and thi products are inserted in the bbdd. I want to do a REST WebService, but I have doubts:

  • How is the user authenticated to salesforce? Do you need a token?
  • To which URL does the user connect to send the information? I have created a connected app, should I use the url specified in the callback?

Could you please give me an example to solve this?

Thanks.

I have an inicial code:

@RestResource(urlMapping='/products/*')
global without sharing class WB_Products{

    @HttpPost
    global static boolean createProducts(string nameProd, decimal price, string description) {
        boolean toRet = false;
        if(name != null && quantity != null && price != null){
            Product2 prod = new Product2();
            prod.Name = nameProd;
            prod.Price__c = price;
            prod.Description__c = description;
            insert prod;
            toRet = true;
        }
        return toRet;
    }   

}

1 Answer 1

4

How is the user authenticated to salesforce? Do you need a token?

You will need to utilize OAuth 2.0 to authenticate and yes you will need to get a token to be able to make a REST API call. Understanding Authentication documentation is a good place to start with

To which URL does the user connect to send the information? I have created a connected app, should I use the url specified in the callback?

Callback URL is used to receive the token sent from Salesforce. If I understand, you are asking how the external application will invoke your Apex REST API that you have written. Assuming that to be the case, once you get the token, the external app will need to invoke the API here using the format below. You can find more information on this on Apex REST Methods docs.

https://<instance-url>/services/apexrest/<namespace>/products/
2
  • The response from Salesforce that contains the access token should also contain an instance_url parameter that contains the "base" part of the web service endpoint (i.e. https://cs42.salesforce.com/). Using that instead of hard-coding in the third-party application will be a big help if you ever get moved to a new pod (or refresh a sandbox).
    – Derek F
    Commented Apr 3, 2019 at 17:03
  • 1
    Thanks Jayant, It's easier than I thought. Then I just need to get the token and send it;)
    – Rodolfo
    Commented Apr 5, 2019 at 8:34

You must log in to answer this question.

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