Tuesday, 21 June 2016

Salesforce Developer forum | Force.com Discussion Boards

 Salesforce Developer forum is one of the best place to learn and share your knowledge with others.
URL:- https://developer.salesforce.com/forums


Please share your knowledge on Salesforce Developer forum and help other. I am 100% sure you will learn new things as well.

I spend a lot of my time on the Salesforce developer forum to help other. My Name on developer forum is "Amit Chaudhary 8" .

Thursday, 2 June 2016

Insert | Update | Delete record by Rest API | Workbench | Standard Rest API | Rest Explorer


In this blog we will learn how to insert, update or delete a record by Rest API without any code.

1) Create a record

Method :- Post
URL:- /services/data/v36.0/sobjects/Account/
Request Body :- 

1{
  "Name" : "Account from Rest API",
  "phone" : "1111111111",
  "website" : "www.salesforce1.com",
  "numberOfEmployees" : "100",
  "industry" : "Banking"
}



Response 
1{ "id" : "0019000001hE8apAAC", "success" : true, "errors" : [ ] }



2) Update a record

Method :- Patch
URL:- /services/data/v36.0/sobjects/Account/0019000001hE8apAAC
Request Body :- 

1{
  "Name" : "Account from Rest API",
  "phone" : "222222"
}



Response :-
 1HTTP/1.1 204 No Content







3) Delete a record

Method :- Delete
URL:- /services/data/v36.0/sobjects/Account/0019000001hE8apAAC

Response 
 1HTTP/1.1 204 No Content



4) Retrieve a record

Method :- Get
URL:- /services/data/v36.0/sobjects/Account/0019000001hE8af
Response 
 1{ "attributes" : { "type" : "Account", "url" : "/services/data/v36.0/sobjects/Account/0019000001hE8afAAC" }, "Id" : "0019000001hE8afAAC", "IsDeleted" : false, "MasterRecordId" : null, "Name" : "Express Logistics and Transport", "Type" : null, "ParentId" : null, "BillingStreet" : null, "BillingCity" : null, "BillingState" : null, "BillingPostalCode" : null, "BillingCountry" : null, "BillingLatitude" : null, "BillingLongitude" : null, "BillingGeocodeAccuracy" : null, "BillingAddress" : null, "ShippingStreet" : null, "ShippingCity" : null, "ShippingState" : null, "ShippingPostalCode" : null, "ShippingCountry" : null, "ShippingLatitude" : null, "ShippingLongitude" : null, "ShippingGeocodeAccuracy" : null, "ShippingAddress" : null, "Phone" : "1111111111", "Fax" : null, "AccountNumber" : null, "Website" : "www.salesforce1.com", "PhotoUrl" : "/services/images/photo/0019000001hE8afAAC", "Sic" : null, "Industry" : "Banking", "AnnualRevenue" : null, "NumberOfEmployees" : 100, "Ownership" : null, "TickerSymbol" : null, "Description" : null, "Rating" : null, "Site" : null, "OwnerId" : "00590000003XIfkAAG", "CreatedDate" : "2016-06-02T13:04:35.000+0000", "CreatedById" : "00590000003XIfkAAG", "LastModifiedDate" : "2016-06-02T13:04:35.000+0000", "LastModifiedById" : "00590000003XIfkAAG", "SystemModstamp" : "2016-06-02T13:04:35.000+0000", "LastActivityDate" : null, "LastViewedDate" : "2016-06-02T13:14:38.000+0000", "LastReferencedDate" : "2016-06-02T13:14:38.000+0000", "IsPartner" : false, "IsCustomerPortal" : false, "Jigsaw" : null, "JigsawCompanyId" : null, "CleanStatus" : "Pending", "AccountSource" : null, "DunsNumber" : null, "Tradestyle" : null, "NaicsCode" : null, "NaicsDesc" : null, "YearStarted" : null, "SicDesc" : null, "DandbCompanyId" : null, "CustomerPriority__c" : null, "SLA__c" : null, "Active__c" : null, "NumberofLocations__c" : null, "UpsellOpportunity__c" : null, "SLASerialNumber__c" : null, "SLAExpirationDate__c" : null, "Accountant__c" : null, "First_Level_Approval__c" : false, "Final_Approval__c" : false, "Old_Account_ID__c" : null, "Demo__c" : null, "SumOfOppAmount__c" : null }



5) Create multiple record

Method :- post
URL:- /services/data/v34.0/composite/tree/Account/
Request Body :- 

1{
"records" :[{
    "attributes" : {"type" : "Account", "referenceId" : "ref1"},
    "name" : "SampleAccount1",
    "phone" : "1111111111",
    "website" : "www.salesforce1.com",
    "numberOfEmployees" : "100",
    "industry" : "Banking"  
    },{
    "attributes" : {"type" : "Account", "referenceId" : "ref2"},
    "name" : "SampleAccount2",
    "phone" : "2222222222",
    "website" : "www.salesforce2.com",
    "numberOfEmployees" : "250",
    "industry" : "Banking"
    },{
    "attributes" : {"type" : "Account", "referenceId" : "ref3"},
    "name" : "SampleAccount3",
    "phone" : "3333333333",
    "website" : "www.salesforce3.com",
    "numberOfEmployees" : "52000",
    "industry" : "Banking"
    },{
    "attributes" : {"type" : "Account", "referenceId" : "ref4"},
    "name" : "SampleAccount4",
    "phone" : "4444444444",
    "website" : "www.salesforce4.com",
    "numberOfEmployees" : "2500",
    "industry" : "Banking"
    }]
}



Response :-
 1{ "hasErrors" : false, "results" : [ { "referenceId" : "ref1", "id" : "0019000001hE8gOAAS" }, { "referenceId" : "ref2", "id" : "0019000001hE8gPAAS" }, { "referenceId" : "ref3", "id" : "0019000001hE8gQAAS" }, { "referenceId" : "ref4", "id" : "0019000001hE8gRAAS" } ] }



6) Update multiple record.
Method :- post
URL:- /services/data/v34.0/composite/batch
Request Body :- 

1{
"batchRequests" : [
    {
        "method" : "PATCH",
        "url" : "v34.0/sobjects/account/0019000001hE8gOAAS",
        "richInput" : { "name" : "SampleAccount1",
                        "phone" : "1111111117",
                        "website" : "www.salesforce1.com",
                        "numberOfEmployees" : "100",
                        "industry" : "Banking"
                        }
    },
   
    {
        "method" : "PATCH",
        "url" : "v34.0/sobjects/account/0019000001hE8gPAAS",
        "richInput" : { "name" : "SampleAccount2",
                        "phone" : "2222222227",
                        "website" : "www.salesforce1.com",
                        "numberOfEmployees" : "100",
                        "industry" : "Banking"
                        }
    }
    ]
}



Response :-
 1{ "hasErrors" : false, "results" : [ { "statusCode" : 204, "result" : null }, { "statusCode" : 204, "result" : null } ] }



NOTE:- Please replace id in URL according to your org

Please check below post for more information
1) https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_what_is_rest_api.htm



Let us know if this will help you

<<PREVIOUS       NEXT>>


Thanks
Amit Chaudhary

Wednesday, 1 June 2016

REST Explorer | Using Workbench | Execute API from Workbench



The best way to test your web-service is workbench. The browser based workbench does not require OAuth as long as your browser session is active.

How to open REST Explorer

1) Log in to your developer organization.

2) Open a new browser tab and navigate to https://workbench.developerforce.com/login.php. and login after click on i agree button.

 3) Then Open REST Explorer. Click Utilities | REST Explorer.
 

4) If you want to see REST Explorer service then use below URL and click on execute button

URL:- /services/data/v36.0
Method :- Get


How to Use REST Explorer

Some Useful URL :-

1) To get Sobject detail :-  /services/data/v36.0/sobjects

Sample  URL to  Get Account object detail
URL:- /services/data/v36.0/sobjects/account/describe


 
2)  To query :- /services/data/v36.0/query

Sample URL to get any record
URL:- /services/data/v36.0/query?q=SELECT+id,name,profile.name+FROM+user+WHERE+username='amit.salesforce21@gmail.com'


3) Execute Apex Rest API
Please check below post for more information
http://amitsalesforce.blogspot.in/2016/04/rest-api-in-salesforce-execute-rest-api.html

URL:- services/apexrest/APIURL


Please check below post for workbench
1) https://developer.salesforce.com/page/Workbench

Please let us know if this will help you

<<PREVIOUS       NEXT>>





Thanks
Amit Chaudhary