You need to sign in to do that
Don't have an account?

Insert data into Salesforce
Hello, I'm just starting to use Salesforce.
Let's say I've got a website with a form to insert a Contact. After the contact is inserted on my web, I want to send a JSON to Salesforce so this Contact is inserted on the Contact Object.
I don't quite understand what I need on my website to communicate with Salesforce.
Thanks!!
Let's say I've got a website with a form to insert a Contact. After the contact is inserted on my web, I want to send a JSON to Salesforce so this Contact is inserted on the Contact Object.
I don't quite understand what I need on my website to communicate with Salesforce.
Thanks!!
SALESFORCE:
@RestResource(urlMapping='/contacts/v1')
global with sharing class{
@HttpPost
global static void createContact(String fname, string lname){
Contact c = new contact(firstname=fname, lastname=lname);
insert c; //creates a contacts
}
}
}
in website
authenticate salesforce and invoke this endpoint
Thanks,
NForce
All Answers
# Create an endpoint in salesforce(Rest resource with put method) which receives input from website
# Authenticate salesforce in the website logic and hit endpoint with the contact data.
Thanks,
The only difference would be that I need to insert this data, right?
My class was:
public class AnimalLocator {
public static String getAnimalNameById (Integer id) {
String retName;
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/' + id);
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
// Deserializes the JSON string into collections of primitive data types.
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
// Cast the values in the 'animals' key as a list
Map<String,Object> animal = (Map<String,Object>)results.get('animal');
retName = (String)animal.get('name');
}
return retName;
}
}
SALESFORCE:
@RestResource(urlMapping='/contacts/v1')
global with sharing class{
@HttpPost
global static void createContact(String fname, string lname){
Contact c = new contact(firstname=fname, lastname=lname);
insert c; //creates a contacts
}
}
}
in website
authenticate salesforce and invoke this endpoint
Thanks,
NForce
I created this class:
@RestResource(urlMapping='/Contact')
global with sharing class AccountPostTest {
@HttpPost
global static ID createContact(String firstName, String lastName, String phoneNumber, String email) {
Contact c = new Contact();
c.FirstName = firstName;
c.LastName = lastName;
c.Phone = phoneNumber;
c.Email = email;
insert c;
return c.Id;
}
}
Then I go to https://workbench.developerforce.com/restExplorer.php and send a contact like this:
{
"firstName" : "myName",
"lastName" : "myLastName",
"phoneNumber" : "1234567",
"email" : "myName@company.com"
}
This works perfectly. But what changes do I have to do if I want this to be done in a website?
For example I have a form, I press submit and I get this JSON. I want it to be redirect to my class so I can insert it.
Any ideas?
Thanks again
On click of submit button on the website, build the logic to send info to this endpoint.
Thanks.
NForce