I have created a simple PHP contact form in my website and I want to save the data into Salesforce.

I thought it would be really simpler.

  • I have looked into the SOAP API but it looked over kill for my simple use case.
  • I tried to install Salesforce Suite module for Drupal, but for what ever reason the authentication process didn't worked.
  • I finally been able from scratch to authenticate with OAuth and made some requests to the REST API.

It worked but after some time the access token expires.

So I'm thinking if it is the best/simplest way to do it?

I just want to push my data to Salesforce when the user submits the form.

  • 2
    your approach is correct. calling salesforce webservice through REST is best approach where you can frame the input to the api in json format which is light weight. for session expires, use refresh token option which will solve your problem...
    – Bforce
    Feb 6, 2014 at 18:52

2 Answers 2


I recommend you look at Web To Lead. It doesn't require code, API, etc., and the data lands as a record in your org's Lead Object.


Yes, as commented by Baskaran, REST is one of the simplest approach for pushing data into salesforce.I would also recommend "Email Service", if you are just trying to do a minimal update/insert.

I see that you mentioned that are running into "access token" expiry issues. We use to get the token, for every new request we make to salesforce; so that we don't run into that issue. Here is the sample where we create HTTP request from a java application,

    protected ClientHttpRequest createRequest(URI url, HttpMethod method) throws IOException {
    HttpClient httpClient = new HttpClient();
    HostConfiguration hostConfiguration = new HostConfiguration();
    hostConfiguration.setProxy(proxyHost, proxyPort);
    ClientHttpRequestFactory requestFactory = new CommonsClientHttpRequestFactory(httpClient);
    ClientHttpRequest sfdcServiceRequest;
    try {
        URI authServiceUri = new URI(sfdcAuthServiceUrl + "?grant_type=" + sfdcGrantType
                + "&client_id=" + sfdcClientId + "&client_secret=" + sfdcClientSecret + "&username="
                + sfdcAuthServiceId + "&password=" + sfdcAuthServicePassword + "&format=xml");

        ClientHttpRequest authServiceRequest = requestFactory.createRequest(authServiceUri, HttpMethod.POST);

        ClientHttpResponse authServiceResponse = authServiceRequest.execute();
        Source src = new StreamSource(authServiceResponse.getBody());
        String sfdcInstanceUrl = "";
        String sfdcAccessToken = "";
        OAuth authResponse = (OAuth) marshaller.unmarshal(src);
        sfdcInstanceUrl = authResponse.getInstanceUrl();
        sfdcAccessToken = authResponse.getAccessToken();

        URI sfdcServiceUri = new URI(sfdcInstanceUrl + url.getPath());
        sfdcServiceRequest = requestFactory.createRequest(sfdcServiceUri, HttpMethod.POST);
        sfdcServiceRequest.getHeaders().add(sfdcAuthHeaderKey, sfdcAuthPrefix + sfdcAccessToken);
        return new RequestWrapper(sfdcServiceRequest);
    } catch (Throwable e) {
        this.logger.error("Error: " + e.getMessage());
        throw new IOException(e.getMessage());

You must log in to answer this question.

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