1

I want to push data from a website developed in .net to salesforce. I have heard of Rest Api.But dont know how to implement that.

  • The .Net website provides a Rest API.So in this case it would be like API talks to another API.Can i use salesforce SOAP API in this case? – Adyasha Jul 20 '17 at 9:32
4

If you have not gone through this Apex Web services Trailhead, then it is the best time to complete that.

You need to create your Apex Class as a Web Service

@RestResource(urlMapping='/Cases/*')
global with sharing class CaseManager {

    @HttpPost
    global static ID createCase(String subject, String status,
        String origin, String priority) {
        Case thisCase = new Case(
            Subject=subject,
            Status=status,
            Origin=origin,
            Priority=priority);
        insert thisCase;
        return thisCase.Id;
    }   

    @HttpPut
    global static ID upsertCase(String subject, String status,
        String origin, String priority, String id) {
        Case thisCase = new Case(
                Id=id,
                Subject=subject,
                Status=status,
                Origin=origin,
                Priority=priority);
        // Match case by Id, if present.
        // Otherwise, create new case.
        upsert thisCase;
        // Return the case ID.
        return thisCase.Id;
    }

    @HttpPatch
    global static ID updateCaseFields() {
        RestRequest request = RestContext.request;
        String caseId = request.requestURI.substring(
            request.requestURI.lastIndexOf('/')+1);
        Case thisCase = [SELECT Id FROM Case WHERE Id = :caseId];
        // Deserialize the JSON string into name-value pairs
        Map<String, Object> params = (Map<String, Object>)JSON.deserializeUntyped(request.requestbody.tostring());
        // Iterate through each parameter field and value
        for(String fieldName : params.keySet()) {
            // Set the field and value on the Case sObject
            thisCase.put(fieldName, params.get(fieldName));
        }
        update thisCase;
        return thisCase.Id;
    }    

}
| improve this answer | |
1

There is the Force.com Toolkits for .NET that provides a .NET wrapper around the existing Salesforce REST API. If you are just performing basic CRUD operations in Salesforce you won't need to create any custom Apex services.

It can help you with the authentication requirements and then making the async calls.

There are walkthroughs on using this Nuget package in the Nothing But .Net series of blog posts.

Another alternative is to use the SOAP based API's, such as the Partner API.

The right tool for the job will depend on the type and volume of data you are pushing to Salesforce and what you are comfortable programming against.

| improve this answer | |

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.