Thursday, July 7, 2016

Salesforce Rest Api

Force.com REST API provides you with a powerful Web services API that you can use to interact with Force.com.

Each resource in REST API is a named URI that’s used with an HTTP method: HEAD, GET, POST, PATCH, or DELETE. All resources are accessed using a generic interface over HTTP with a base URI that follows your Force.com or Database.com URI. REST API supports authentication using OAuth 2.0 and supports both JSON and XML (JSON is the default).

To test the Salesforce Rest API. login to workbench. Navigate to utilities-> Rest Explorer and follow below examples to create/update/upsert/delete records. 

 Create a record:
Url:https://instance.salesforce.com/services/data/vNN.N/sobjects/sObject
Method:POST
Request Body:field-value pairs
eg:
url:https://ap1.salesforce.com/services/data/v37.0/sobjects/case
Request Body:{
"Origin": "SMS Feedback",
"Subject": "134350/Feedback",
"Description": "Payment Type: Credit Card "
}

Update a Record
Url:https://instance.salesforce.com/services/data/vNN.N/sobjects/sObject/Id 
Method:PATCH 
Request Body:field-value pairs 
eg:
url:https://ap1.salesforce.com/services/data/v37.0/sobjects/case/500260000045ffRAAQ
Request Body:{
"Origin": "SMS Feedback",
"Subject": "134350/Feedback",
"Description": "Payment Type: Credit Card "
}


Upsert a Record
Url:https://instance.salesforce.com/services/data/vNN.N/sobjects/sObject/externalIdField/value Method:PATCH 
Request Body:field-value pairs 
eg:
url:https://ap1.salesforce.com/services/data/v37.0/sobjects/case/externalfield__c/54364
Request Body:{
"Origin": "SMS Feedback",
"Subject": "134350/Feedback",
"Description": "Payment Type: Credit Card "
}
Delete a Record
https://instance.salesforce.com/services/data/vNN.N/sobjects/sObject/Id Method:DELETE 
eg:
url:https://ap1.salesforce.com/services/data/v37.0/sobjects/case/500260000045fesAAA

5 comments :

  1. Thanks for the post:)
    Can you please provide some example to insert the list of records in Rest API

    ReplyDelete
  2. Hi Please use this example to insert bulk records. To insert bulk records you need to pass a array.
    [{
    "Origin": "SMS Feedback",
    "Subject": "134350/Feedback",
    "Description": "Payment Type: Credit Card "
    },{
    "Origin": "SMS Feedback",
    "Subject": "134350/Feedback",
    "Description": "Payment Type: Credit Card "
    }]

    ReplyDelete
  3. What is vNN.N in the URI

    ReplyDelete
  4. I really appreciate information shared above. It’s of great help.
    SalesForce online training

    ReplyDelete
  5. Best Casino Slots Games - Mapyro
    Free Slots at Mapyro. Search for: 7 사천 출장마사지 Great 통영 출장샵 Slot Games that are Fun to Play Try out your luck on 거제 출장마사지 all the 7 great 구리 출장마사지 slot games from the world's biggest 상주 출장샵 casinos in

    ReplyDelete

Labels

visualforce page ( 13 ) apex integration ( 5 ) apex trigger ( 4 ) csv file from vf page ( 4 ) javascript ( 4 ) csv visualforce page ( 3 ) Too many ( 2 ) call out ( 2 ) integration ( 2 ) rest api ( 2 ) salesforce rest api ( 2 ) salesforce to salesforce integration ( 2 ) sfdc rest api ( 2 ) trigger ( 2 ) 15 digit to 18 digit ( 1 ) DML rows in Apex ( 1 ) Date Conversion ( 1 ) Date/Time conversion ( 1 ) Deploy ( 1 ) Objects to Future Annotated Methods ( 1 ) SFDC limits ( 1 ) Sobject to Future Annotated Methods ( 1 ) Test Class ( 1 ) TimeZone Conversion ( 1 ) Too many dml rows ( 1 ) Too many future calls ( 1 ) annotations ( 1 ) apex code ( 1 ) closed opportunities ( 1 ) commit ( 1 ) convert ( 1 ) create records ( 1 ) csv create records ( 1 ) custom setting ( 1 ) deployment ( 1 ) deployment changeset ( 1 ) disable apex class ( 1 ) disable apex trigger ( 1 ) disable in production ( 1 ) document ( 1 ) download ( 1 ) field name ( 1 ) formula fields ( 1 ) iframe ( 1 ) inactive ( 1 ) intellisense ( 1 ) jsforce ( 1 ) limits ( 1 ) matrix report in vf page ( 1 ) multi select ( 1 ) multi select salesforce ( 1 ) multiselect ( 1 ) paypal ( 1 ) picklist ( 1 ) record type ( 1 ) rollback ( 1 ) salesforce limits ( 1 ) salesforce list ( 1 ) salesforce map ( 1 ) salesforce rest ( 1 ) salesforce set ( 1 ) salesforce1 ( 1 ) sandbox deployment ( 1 ) sfdc collection ( 1 ) sfdc list ( 1 ) sfdc map ( 1 ) sfdc rest ( 1 ) sfdc set ( 1 ) uncommitted ( 1 ) updated field ( 1 ) user ( 1 ) validation rule opportunity ( 1 ) validation rules opportunities ( 1 ) vf page ( 1 )

Ad