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
Cloud EliteCloud Elite 

What is needed to integration a website to salesforce ?

Hello all, 

I need some help to understanf the dependency and feasibility of integratng a website to salesforce. Here is my use case that I need help with: 

We have a system (act as a front end) for users to review status of their contacts based on region. each region will show a number of contacts that the user can create a request against all of them for processing based on the region. One request to be submitted, when the request is completed and submitted, we want to send the request to salesforce to create the request and assign the contacts to that request in salesforce (Salesforce was populated with the contacts from the front end system manually). 

Now, we have in Salesforce the contact object and Request object, the request object will capture the request information filled on the front end page. We also have a junction object between contact and Request object called Request members so that we can assign as many contacts to relate to the request record, this object is called Request members. 

Now, what integration method is applicable here that will allow me to first insert a request record, capture the record id, and then use that ID to related the Request members to it and the contacts eventually ? 

I need to be able to present in salesforce that there is one request for these 10 contacts, and type of that request was region. 

Should i use rest api ? How it will work ? please provide the logical sequence for this type of integration. 
 
Best Answer chosen by Cloud Elite
Alain CabonAlain Cabon
It is best to code a working solution with a simple example ( ie: get the contacts by the firstname/lastname and external Id). 

The passing parameters are always in the URL.

How to Read REST API GET Parameters in Apex
https://www.salesforcecodecrack.com/2018/12/how-to-read-rest-api-get-parameters.html

The language is important ( pyton or java . ).
@RestResource(urlMapping='/getContactdetails/*')
global class RESTServiceDemoClass {
    
    @HttpGet
    global static list<Contact> getContactList() {
        String strAccId = '';
        String strLeadSource = '';
        list<Contact> lstCons;
        RestRequest restReq = RestContext.request;
        RestResponse restRes = RestContext.response;
        // Reading parametrs from URL
        strAccId = restReq.params.get('accountId');
        strLeadSource = restReq.params.get('leadSource');
        if(!String.isBlank(strAccId) && !String.isBlank(strLeadSource)) {
            lstCons = [Select Id, Name, Email FROM Contact WHERE AccountId =:strAccId AND LeadSource =: strLeadSource];
        }
        return lstCons;
    }
}

URL: /services/apexrest/getContactdetails?accountId=Accountd&leadSource=Web
Rest Method: GET

RestRequest restReq = RestContext.request;
strAccId = restReq.params.get('accountId');
strLeadSource = restReq.params.get('leadSource');

GET + URL: /services/apexrest/getContactdetails  will search for a method with urlMapping='/getContactdetails/* and an annotation @HttpGet ( here getContactList() without parameters ) but that is the annotation that is important.
 

All Answers

Alain CabonAlain Cabon
@Cloud Elite

Expose Your Apex Class as a Web Service (easy with some annotations and JSON messages):
https://trailhead.salesforce.com/content/learn/modules/apex_integration_services/apex_integration_webservices

The problem is that the REST calls in the examples are done with the workbench (PHP) and curl that are specific applications for the session authentication mechanisms that you need to do from the code of your website (main problem).

"Apex REST supports OAuth 2.0 and session authentication mechanisms. In simple terms, this means that we use industry standards to keep your application and data safe. Fortunately, you can use Workbench to make testing easier. Workbench is a powerful, web-based suite of tools for administrators and developers to interact with orgs via Lightning Platform APIs. With Workbench, you use session authentication as you log in with your username and password to Salesforce. And you use the REST Explorer to call your REST service."

What is the language of your website?
Cloud EliteCloud Elite
Hi Alain, 

I believe it is either python or Java. 

If we look at this just from an architecture standpoint, what components i will need and how we will ensure that the data on the website (that came from another system) matches what is in salesforce ? 

Can I say that we need to send a rest call to salesforce that will contact the request information, related contacts and their external IDs (from the other system)  then expose a rest apex the recieve that message, then create one request record, populate the request info on it, then search for the contacts in the system based on the external ids provided (assume that salesforce has custom field who has the same value), then create Request members records and assign to the Request record created earlier. Can this be managed in the apex ?  will I be able to search contacts based on the external id  ? and finally what do I need to update the website (front end) with any updates to the request ?  
Alain CabonAlain Cabon
It is best to code a working solution with a simple example ( ie: get the contacts by the firstname/lastname and external Id). 

The passing parameters are always in the URL.

How to Read REST API GET Parameters in Apex
https://www.salesforcecodecrack.com/2018/12/how-to-read-rest-api-get-parameters.html

The language is important ( pyton or java . ).
@RestResource(urlMapping='/getContactdetails/*')
global class RESTServiceDemoClass {
    
    @HttpGet
    global static list<Contact> getContactList() {
        String strAccId = '';
        String strLeadSource = '';
        list<Contact> lstCons;
        RestRequest restReq = RestContext.request;
        RestResponse restRes = RestContext.response;
        // Reading parametrs from URL
        strAccId = restReq.params.get('accountId');
        strLeadSource = restReq.params.get('leadSource');
        if(!String.isBlank(strAccId) && !String.isBlank(strLeadSource)) {
            lstCons = [Select Id, Name, Email FROM Contact WHERE AccountId =:strAccId AND LeadSource =: strLeadSource];
        }
        return lstCons;
    }
}

URL: /services/apexrest/getContactdetails?accountId=Accountd&leadSource=Web
Rest Method: GET

RestRequest restReq = RestContext.request;
strAccId = restReq.params.get('accountId');
strLeadSource = restReq.params.get('leadSource');

GET + URL: /services/apexrest/getContactdetails  will search for a method with urlMapping='/getContactdetails/* and an annotation @HttpGet ( here getContactList() without parameters ) but that is the annotation that is important.
 
This was selected as the best answer
Alain CabonAlain Cabon
The passing parameters are always in the URL for a GET but there is also POST (different for the parameters).

A method with urlMapping='/getContactdetails/* for the class and an annotation @HttpGet for the method itself.
Cloud EliteCloud Elite
thank you much for the info