Salesforce
Rest Services are a powerful as well as convenient way to expose web services
from a organization. It uses simple HTTP methods like GET , POST etc. to access
and manipulate data. The data exchange format is in the form of JSON generally.
The following is a sample apex class which illustrates the POST method to post details and GET method to retrieve details from an outside application.
Sample Rest Apex Class:
The following is a sample apex class which illustrates the POST method to post details and GET method to retrieve details from an outside application.
Sample Rest Apex Class:
/*
The urlMapping acts as an accessible endpoint and adds to the full URL used to call this webservice from an external point
For example, something like "https://ap1.salesforce.com/services/apexrest/Account"
*/
@RestResource(urlMapping='/Account/*')
global with sharing class callAccount {
/*
HttpPost method is used to capture a HttpPost request has been sent to our rest apex class.
Used to retrieve data coming in the request body and performing corressponding actions
*/
@HttpPost
global static String doPost() {
/*
RestContext Class - Allows us to access the RestRequest and RestResponse objects in your Apex REST methods.
RestRequest class - Allows us to pass request data into our Apex RESTful Web service method.
RestResponse class - Allows us to pass or send back response data from our Apex RESTful web service method
*/
//Returns the RestRequest object for our Apex REST method.
RestRequest request = RestContext.request;
//Returns the RestResponse for our Apex REST method.
RestResponse response = RestContext.response;
//Access the request body with input data coming in the JSON format
String jSONRequestBody=request.requestBody.toString().trim();
//Deserializes the input JSON string into an Account object
Account accObj = (Account)JSON.deserializeStrict(jSONRequestBody,Account.class);
//insert the account object and return the account ID
insert accObj;
return accObj.Id;
}
/*
HttpGet method is used to capture a HttpGet request has been sent to our rest apex class.
Used to request data on the basis of a parameter sent in the URL
*/
@HttpGet
global static Account doGet() {
/*
RestContext Class - Allows us to access the RestRequest and RestResponse objects in your Apex REST methods.
RestRequest class - Allows us to pass request data into our Apex RESTful Web service method.
RestReponse class - Allows us to pass or send back response data from our Apex RESTful web service method
*/
//Returns the RestRequest object for our Apex REST method.
RestRequest request = RestContext.request;
//Returns the RestResponse for our Apex REST method.
RestResponse response = RestContext.response;
//Retrieve the parameter sent in the URL
String accountId = request.requestURI.substring(request.requestURI.lastIndexOf('/')+1);
//query the account on the basis of id sent and return the record
Account acc= [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId];
return acc;
}
}
Set up in salesforce org
Call webservice using cURL
1.
Go to Setup, click Create | Apps,
and in the Connected Apps section, click New to create a new
Connected App.
2.
Enter a Connected
App name.
3.
Enter the contact
email, as well as any other information appropriate to your application.
4.
Under Section
‘OAuth Settings’, mark the enable OAuth Settings checkbox and enter
a Callback URL for example: https://ap1.salesforce.com/services/oauth2/token
a.
Perform requests on your behalf at any time
(refresh_token)
b.
Provide access to your data via the Web
(web)
c.
Access and manage your data (API)
6.
Click
Save. The Consumer Key is created and displayed, and
a Consumer Secret is created (click the link to reveal it).
To call the rest apex class from
outside salesforce, we either need to set up cURL or a client/system capable of making http request. Here is an example showing how to use cURL to call the REST service.
FIRST we need to download the curl executable file (SSL enabled), preferably from http://curl.haxx.se/download.html (corresponding to the OS and the version) . cURL has some user friendly commands to call the rest service with OAuth authentication.
FIRST we need to download the curl executable file (SSL enabled), preferably from http://curl.haxx.se/download.html (corresponding to the OS and the version) . cURL has some user friendly commands to call the rest service with OAuth authentication.
1. Command to receive the authorization token
:
curl --form client_id=[Your client Id] --form client_secret=[Your client secret] --form grant_type=password --form username=[Your Username] --form password=[Your Password+Your Security Token] -k https://[Your salesforce instance].salesforce.com/services/oauth2/token
For
example :
curl --form client_id=3MVG9_7ddP9KqTzd_3A4dh9sZ4fpxuyOxHUCQ.GRu6EY7ETY2xFAGBrkv8BO17HmOR_X47cahreAbO7WjQgLd --form client_secret=2607521253690956513 --form grant_type=password --form username=test@gmail.com --form password=password1$RjzaF3v6HahniNEWpxUlUIoG -k https://cs10.salesforce.com/services/oauth2/token
2. Use cURL to call the webservice
a. Command to GET account details using the
authorization token received from the above command :
curl -X GET https://[Your salesforce instance].salesforce.com/services/apexrest/ [URI Mapping] /[account Id] -H "Authorization: OAuth [Your authorization token]" -k
For example :
curl -X GET https://ap1.salesforce.com/services/apexrest/Account/0019000000Nah1a -H "Authorization: OAuth 00D90000000kIy777RYAQGVLW60UaT.yKMONqfjztdq1__6SGL70qOVFtwvYwj_4oykw7_QgKOTbl6jhZDAaYgtTW0ZR9THihS29MwPHAEuyxFbM" -k
b. Command to POST and create account using
the authorization token received from the above command :
Suppose we use a JSON file with the following input:
{
“Name”:”testaccount”,
“Phone”:”1234567890”
}
curl https://[Your salesforce instance].salesforce.com/services/apexrest/ [URI Mapping] /[account Id] -H "Authorization: OAuth [Your authorization token]" -H "Content-Type: application/json" -d @[Name of JSON file] -k
For Example :
curl https://ap1.salesforce.com/services/apexrest/Account/ -H "Authorization:OAuth 00D90000000kIy777RYAQGVLW60UaT.yKMONqfjztdq1__6SGL70qOVFtwvYwj_4oykw7_QgKOTbl6jhZDAaYgtTW0ZR9THihS29MwPHAEuyxFbM" -H "Content-Type: application/json" -d @account.json -k
This demo demonstrates how to create/query account using simple HTTP calls. This example can be extended further to accomplish more complex tasks.
Further JSON support makes REST Webservices excellent way to integrate with External Systems including legacy systems. REST Webservices can be used to integrate two different Salesforce Org and let them talk seamlessly. In next part we will be covering How to use Rest Webservices to integrate two different Salesforce Orgs.
I really appreciate people who share their thoughts and knowledge with everyone. Thanks for sharing your blog.
ReplyDeletePHP web development company in Mumbai
Wonderful post, thanks for sharing. Attrait Solutions is the top web development company mumbai. It provide many services like development, SEO, SMO services and many more.
ReplyDeleteI was looking for Web Design Nagpur Jobs came across this blog . Good information provided.Thanks for sharing with us.
ReplyDeletevery nice blog more information our sites
ReplyDeleteC.R. Bearing & Bushes Perfect Sales Agra
Thanks for the article. It was really helpful and cut my turn around time.
ReplyDeleteHow to use Rest Webservices to integrate two different Salesforce Orgs.
ReplyDeletePlease pot this article.
Glad to read your post...Thanks for sharing such a nice information, its beneficial for me. I have you bookmarked to check out new stuff you post. Keep sharingWebsite Design Companies Bangalore | Web Designing Companies Bangalore
ReplyDeleteThank you for sharing the useful information...I have a getting the lots of information...
ReplyDeleteWebsite Development in Bangalore | Website Designing Bangalore
This comment has been removed by the author.
ReplyDeleteHi all,
ReplyDeleteI am unable to Pass more than 32 inpust parameter to @httpPost Please Help Me,Thanks in Advance
@RestResource(urlMapping='/Students/*')
global with sharing class Studnets {
@HttpPost
global static String doPost(Integer Max,String ConcurrentAsyncGetReportInstances,String ConcurrentSyncReportRuns,Integer Max1,
Integer Remaining,Integer Remaining1,String DailApiRequest,Integer DAPIRemaining,Integer DAPiMax,String Ant,Integer AntMax,
Integer AntRemaining,String App,Integer AppMax,Integer AppRemaining,String DataloaderBulk,Integer DMax,Integer DRemaining,String DPartner,
Integer DPMax,Integer DpRemaining,String FIde,Integer Fmax,Integer FRemaining,String SFMD,Integer SFMDMax,Integer SFMDRemaining,String SFTouch,Integer SFTMax,
Integer SFTRemaining,Integer SFOMax,String SFOutlook)
{
System.debug('Entering in to APIUSAGE__c');
APIUSAGE__c st = new APIUSAGE__c();
st.ConcurrentAsync__c=ConcurrentAsyncGetReportInstances;
st.ConcurrentSync__c=ConcurrentSyncReportRuns;
st.Async_Max__c=Max;
st.Max__c=Max1;
st.SyncRemaining__c=Remaining;
st.Async_Remaining__c=Remaining1;
st.DailyApiRequests__c=DailApiRequest;
st.DAPIRemaining__c=DAPIRemaining;
st.DAPiMax__c=DAPiMax;
st.Ant_Migration_Tool__c=Ant;
st.Ant_Max__c=AntMax;
st.Ant_Remaining__c=AntRemaining;
st.App_Name__c=App;
st.App_Max__c=AppMax;
st.App_Remaining__c=AppRemaining;
st.Dataloader_Bulk__c=DataloaderBulk;
st.DMax__c=DMax;
st.DRemaining__c=DRemaining;
st.Dataloader_Partner__c=DPartner;
st.DPMax__c=DPMax;
st.DpRemaining__c=DpRemaining;
st.ForceIDE__c=FIde;
st.FMax__c=Fmax;
st.FRemaining__c=FRemaining;
st.SFMD__c=SFMD;
st.SFMDMax__c=SFMDMax;
st.SFMDRemaining__c=SFMDRemaining;
st.SFTouch__c=SFTouch;
st.SFTMax__c=SFTMax;
st.SFTRemaining__c=SFTRemaining;
st.SFOMax__c=SFOMax;
st.SFOutlook__c=SFOutlook;
insert st;
return st.Id;
}
}
Hai Author, Very Good informative blog post,
ReplyDeleteThanks
Learn Salesforce.com developer courses online/classroom in Delhi from top training institutes and get Salesforcedeveloper certification. Get details on course fees @91-931OO96831!!
ReplyDelete
ReplyDeleteThe website is looking bit flashy and it catches the visitors eyes. A design is pretty simple .
office 2016 professional plus 64 bit
very nice article....keep sharing.....
ReplyDeletefor animal health products, visit - http://www.amorvet.com
animal feed supplements | veterinary product producer | animal health product manufacturers | herbal veterinary products
very informative post... keep updating..
ReplyDeletehttp://www.arosolchemicals.com
animal feed supplements | veterinary feed additives | Pig and swine feed additives | Poultry respiratory products | Herbal medicines for pets
Awesome,
ReplyDeleteThank you so much for sharing such an awesome blog...
Salesforce development Company
This comment has been removed by the author.
ReplyDelete
ReplyDeleteamazing
jobbörse Neunkirchen
i like your post.... as your post provide useful information to me...thanks for sharing... keep updating..
ReplyDeletehttp://www.arosolchemicals.com/products.htm
organic feed additives | veterinary feed additives | Pig and swine feed additives | Veterinary Product Manufacturer in India,Delhi | poultry feed supplements
Hi,
ReplyDeleteThanks for sharing a very interesting article about Salesforce REST Webservices - Part I. This is very useful information for online blog review readers. Keep it up such a nice posting like this.
From,
Maestro Infotech,
Web Design Company Bangalore
good post... as it provide useful information to me...
ReplyDeletehttp://www.amorvet.com/poultry.html
animal feed supplements | Veterinary drug companies | Pig and swine feed additives | Veterinary pharma companies | Poultry medicine companies
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletevery informative post... keep updating,....
ReplyDeletehttp://www.arosolchemicals.com/
veterinary product producers | veterinary products manufacturer in india,delhi | Veterinary pharma companies | Poultry respiratory product | animal health products manufacturers
very useful article.thanks for posting.
ReplyDeletemobile application development companies chennai | SEO company india
A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away.Web Design Services
ReplyDeleteThank you for sharing the useful information web design company in chennai
ReplyDeleteThank a ton for sharing this valuable information with us. I loved your article. salesforce consultant.
ReplyDeletethanks a lot for sharing the useful information...keep updating....
ReplyDeletehttp://aminorich.nl/
animal feed supplements | veterinary products producer | poultry feed supplements | cattle feed supplements
great and nice blog, thanks for sharing such a nice post with us, keep sharing!!
ReplyDeleteDevOps Online Training
great blog and innovative content......
ReplyDeleteSalesforce Training In Chennai
hiii author .... i like your post....very informative ....
ReplyDeleteanimal feed supplements | poultry feed supplements | cattle feed supplements | vitamins and minerals
Hi,
ReplyDeleteThanks for sharing a very interesting article about Salesforce REST Webservices - Part I. This is very useful information for online blog review readers. Keep it up such a nice posting like this.
Regards,
WondersMind,
Web Design Company Bangalore
Informative blog.. keep on updating
ReplyDeleteThank you for sharing info...
Software Training institute in hyderabad | Software Training course in hyderabad | Sales force Training institute in hyderabad
Assuredly beneficial bit of information published by you. Certainly this might be advantageous for numerous seekers. Keep on sharing this worthwhile articles. Professional Web design services are provided by W3BMINDS- Website designer in Lucknow.
ReplyDeleteWeb development Company | Web design company
This is an best post. It is Really very informative concept.I like it and help me to development very well.Thanks alot for this brief explanation and very nice information.sales force online training
ReplyDeleteคุณมีบทความดีๆ ขอให้คุณมีวันใหม่ที่ดี
ReplyDeleteThông tin mới nhất về cửa lưới chống muỗi
Siêu thị cửa chống muỗi
Hé mở thông tin cửa lưới chống muỗi xếp
Phòng chống muỗi cho biệt thư ở miền Nam
Những chia sẻ thú vị
DeleteBồn ngâm chân
máy ngâm chân
bồn massage chân
may mat xa chan
Hay lắm anh ơi
Deletehat methi
hạt methi
hạt methi ấn độ
thảo dược methi ấn độ
Bài viết hay
Deletehttps://forums.pokemmo.eu/index.php?/profile/131787-cualuoihm/
https://doremir.com/forums/profile/cualuoihm
https://www.wincert.net/forum/profile/100889-cualuoihm/
https://www.goodreads.com/user/show/104133368-cualuoihm
Hay
Deletelều xông hơi
lều xông hơi tại nhà
lều xông hơi giá rẻ
lều xông hơi sau sinh
Great, this article is quite awesome and I have bookmarked this page for my future reference. Keep blogging like this with the latest info.
ReplyDeleteVMware Training in Chennai
VMware Training in Velachery
Cloud Computing courses in Chennai
Cloud Training in Chennai
Azure Training in Chennai
Microsoft Azure Training in Chennai
AWS Certification in Chennai
DevOps course in Chennai
Cloud Computing Training in Chennai
Thanks, This is really important one, and information. Keep sharing on more information. Website Design Company in Bangalore | Web Designing Company in Bangalore | Website Development Company in Bangalore
ReplyDeleteHey Very Nice Blog!! Thanks For Sharing !!!
ReplyDeleteBest SEO Company in Varanasi
Best Digital Marketing Agency in Varanasi
Seo Services in Varanasi
This comment has been removed by the author.
ReplyDelete新信息,我真的很喜欢谢谢。
ReplyDeleteLều xông hơi khô
Túi xông hơi cá nhân
Lều xông hơi hồng ngoại
Mua lều xông hơi
Rất tuyệt vời
Deletethanh lý phòng net
màn hình máy tính 24 inch cũ
lắp đặt phòng net
giá card màn hình
chia sẻ quá hay
DeleteLều xông hơi – Ngồi chơi cũng giảm cân
Tôi rất thích
ReplyDeleteĐịa chỉ mua giảo cổ lam Hòa Bình tại thủ đô
Dấu hiệu bệnh tiểu đường
Triệu chứng bệnh tiểu đường
Tiệm bán hạt methi Hà Nội
Hạt methi Ấn Độ mua ở đâu Hải Dương
ReplyDeleteReally it is very useful for us..... the information that you have shared is really useful for everyone. If someone wants to know about Taxi Service App and Health Management Software I think this is the right place for you.
Car Rental Application | Taxi Software | Health and Safety software
Thanks this is really important information for us casino poker guru
ReplyDeleteGood valuable information... I have learned a lot from this blog.
ReplyDeleteAndroid game development company
Nice post. Uniqwebtech is the Affordable Digital marketing company IN USA.
ReplyDeleteok những gì bạn chia sẻ tôi quá thiuchs
ReplyDeleteXông hơi vào mùa hè giúp người già tăng cường sức khỏe
Xông hơi vào mùa hè giúp người già tăng cường sức khỏe
Xông hơi vào mùa hè giúp người già tăng cường sức khỏe
great postbombay basera
ReplyDeleteNhững gì bạn chi sẻ tôi rất `t``hichs
ReplyDeletecáo tuyết
cáo tuyết thái lan
Mua cáo tuyết
Bán cáo tuyết
bull pháp hà nội
Thanks for Very Nice Information.
ReplyDeleteDevops Training Institute in Hyderabad
Devops Training Institute in Ameerpet
Devops Online Training in Hyderabad
Devops Online Training in Ameerpet
Tôi thích bài viết này
ReplyDeletemáy tạo hương thơm trong phòng
máy xông tinh dầu bằng điện tphcm
máy xông hương
may xong huong tinh dau
máy đốt tinh dầu điện
ok hay lắm anh
ReplyDeletecase máy tính cũ
vga cũ hà nội
mua bán máy tính cũ hà nội
Lắp đặt phòng net trọn gói
I read your post. Great information! This information is useful for visitors. Thanks for sharing such a good information. Cheers!
ReplyDeleteVisit for Digital marketing services like online management company in Mumbai
| Social Media Marketing company in Delhi | online management company in Delhi
| Social Media Marketing company in Mumbai | Digital marketing company in Mumbai | Digital marketing company in Delhi | Digital marketing companies in Delhi | Digital marketing companies in Mumbai | Social Media Marketing companies in Delhi | Social Media Marketing companies in Mumbai
Very nice… i really enjoy to read your blog. Very useful information on it. Please keep posting and sharing.
ReplyDeleteDigital Marketing Agency in Jaipur
I have read this blog.Its very Usefull.Gp Rating
ReplyDeleteGp Rating Course
B.SC NAUTICAL SCIENCE Near me
stcw courses
Gp Rating Courses
AWS
ReplyDeleteMind Q Systems provides AWS training in Hyderabad & Bangalore.AWS training designed for students and professionals. Mind Q Provides 100% placement assistance with AWS training.
Mind Q Systems is a Software Training Institute in Hyderabad and Bangalore offering courses on Testing tools, selenium, java, oracle, Manual Testing, Angular, Python, SAP, Devops etc.to Job Seekers, Professionals, Business Owners, and Students. We have highly qualified trainers with years of real-time experience.
Very interesting post really check crypto market here
ReplyDeleteThank you for sharing about the service. Actually I am concerned about this matter. Website is a means of communication between users and customers. If you sell, the website is a great channel: Máy ép dầu thực vật Nanifood, Máy ép tinh dầu Nanifood, Máy ép dầu Nanifood, Máy lọc dầu Nanifood, Máy ép dầu, May ep dau, Máy lọc dầu, Máy ép tinh dầu, Máy ép dầu thực vật, Máy ép dầu gia đình, Máy ép dầu kinh doanh, Bán máy ép dầu thực vật, Giá máy ép dầu, Máy ép dầu lạc, Máy ép dầu lạc mini, ....................
ReplyDeleteBài viết quá hay anh ơi
ReplyDeleteSự thật về đông trùng hạ thảo Việt Nam bạn nên biết
https://dongtrunghathaonepa.com/
Giải mã bí mật đông trùng hạ thảo là gì?
Tác dụng đông trùng hạ thảo
Đông trùng hạ thảo
I am really happy to say it’s an interesting post to read. I learn new information from your article; you are doing a great job. Keep it up…
ReplyDeleteiClass Gyansetu in Gurgaon
ReplyDeleteTechforce services is a Salesforce Consulting Services in Australia Specialising in delivering end to end Salesforce solutions ,Consulting, Implementation DevOps partners in australia We deliver applications and services more rapidly and reliably, but it’s more than a methodology – it cuts to the very core.Salesforce Data Analytics let us help you become a data driven organisation and ensure your data is working hard for your business This includes implementi
Salesforce consulting companies
Salesforce Services
Staff augmentation companies
Salesforce integration companies
Salesforce Implementation services
Salesforce DevOps partners
Salesforce DevOps
Managed project services
Điều anh chia sẻ quá hay
ReplyDeletehttps://avanga.vn/khai-niem-than-so-hoc-la-gi/
Ý nghĩa số 2 trong biểu đồ ngày sinh
Ý nghĩa số 3 trong biểu đồ ngày sinh
Ý nghĩa con số chủ đạo 2 trong thần số học
Những gì anh mang đến thực sự quá hay
ReplyDeletemàn hình máy tính 2k
lắp đặt phòng net trọn gói
lắp đặt phòng net
lắp đặt phòng game
nicely written.
ReplyDeleteBest salesforce consulting services company and prime consulting partner
Text messages have become the most effective and reliable tool for marketers to send vital information right in front of the eyes of audiences. In addition to this, WhatsApp has equipped businesses to tap into the world of rich media communication and connect with audiences over the most popular messaging channel. Thus, business ventures who haven’t touched WhatsApp yet are heading to Salesforce WhatsApp integration in addition to SMS integration for Salesforce to reap WhatsApp benefits along with texts.
ReplyDeleteGood
ReplyDeletetư vấn điện
công ty tư vấn điện
nhiệt điện
Những chia sẻ quá thú vị
ReplyDeleteWhat is PP (Polypropylene)? Its Application In our Life
Learn more about FIBC bags
What is Flexo printing technology? Why did FIBC manufacturers choose this technology?
This blog contains too much information. Thank you for posting this and please keep sharing your good thoughts.
ReplyDeleteUpcoming projects in Sector 79 Noida
We are known as the best iPhone Insurance provider in India. You may connect with us to get the fast insurance services.
ReplyDeletekhá là hay
ReplyDeletebao fibc
bao jumbo 1000kg
công ty bao bì jumbo
This is really good blog information thanks for sharing. very informative.
ReplyDeleteWebsite designing company in Noida
Hay a
ReplyDeletepp jumbo bag scrap
type a fibc
Thanks For Sharing Such A Great Article, Please Read Our Article And Keep Them Up.
ReplyDeleteBrackish Water Desalination 150000 GPD R.O. System Djibouti
Wow, cool post. I'd like to write like this too - taking time and real hard work to make a great article... but I put things off too much and never seem to get started. Thanks though
ReplyDeleteWebsite design company Warsaw
Are you interested to grow your online business worldwide? If yes then you must join the best SEO Company in Ghaziabad that provides high-class SEO service.
ReplyDeleteReally awesome info
ReplyDeleteI recommend that css founder is the best company for website design and development. It is known as the best website designing company. Website design company Lublin
ReplyDeleteWow, cool post. I'd like to write like this too - taking time and real hard work to make a great article... but I put things off too much and never seem to get started. Thanks though Digital Marketing Company in bhandup
ReplyDelete
ReplyDelete1 BHK, 2 BHK Residential Property in Haridwar for Sale near Har ki Paurion Main Rishikesh Highway amidst the
scenic beauty of residential projects in Haridwar near Ganga . Ready to move flats for sale in Haridwar are
available with a bank loan facility
Need professional WordPress Web Design Services? We're experts in developing attractive mobile-friendly WordPress websites for businesses. Contact us today! https://just99marketing.com/wordpress-web-design
ReplyDeleteLive better with clean water. RO Membrane - Reverse Osmosis Element
ReplyDeleteKhá hay nha anh em ơi
ReplyDeleteThiết kế nội thất chung cư uy tín tại hà nội
Thiết kế nội thất chung cư cần lưu ý những gì?
Nice information
ReplyDeleteJava training institution in Hyderabad
This is nice and more informative, Thank you for sharing it!
ReplyDeleteJava Training in Hyderabad
Khá lắm a
ReplyDeletehạt methi mua ở đâu
mua hạt methi
hat methi
Your skills and efforts are truly appreciated. Keep up the great work! I wanted to take a moment to let you know that you can also good job with affordable website design work
ReplyDeleteThank you for sharing valuable insights on Salesforce REST Webservices! Your expertise shines through, offering clarity in a complex subject. As a Dubai-based website development and design agency, we're constantly seeking to enhance our understanding.
ReplyDelete