Hi folks, In this tutorial I am going to show you how to fetch records from sobjects using REST API in apex class salesforce. This is also an approach to overcome salesforce “Too Many Query Rows 50001” limit exception.

How to fetch records from sobjects using REST API in apex class salesforce:

Before starting add your salesforce base url to remote setting in my case i have added https://devlighting-dev-ed–c.na46.visual.force.com to remote setting to whitelist my salesforce URL.

Create Apex Controller:

Step 1- Goto Setup and open Developer Console.

Step 2- Create an apex class called RESTAccountController. Replace the following code in the class.

public class RESTAccountController {
 public List<Account> AccountList { get
 {
 
 HttpRequest req = new HttpRequest();
 req.setEndpoint('https://'+URL.getSalesforceBaseUrl().getHost()+'/services/data/v39.0/query/?q=SELECT+Id,Name,AccountNumber,Phone+FROM+Account');
 req.setMethod('GET');
 
 //Get SessionId
 string autho = 'Bearer '+userInfo.getSessionId();
 req.setHeader('Authorization', autho);
 
 //Get Response
 Http http = new Http();
 HTTPresponse res= http.send(req);
 string response = res.getBody();
 
 //Deserialize obtained json response
 string sData = '['+ response.substring(response.indexOf('records":[')+10,response.indexof(']}')) +']';
 List<Account> lstAccount = (list<Account>)JSON.deserialize(sData,list<Account>.class);
 return lstAccount;
 
 }
 set;
 }
}

Where,

URL.getSalesforceBaseUrl().getHost(): is used to get host name from salesforce base url

string autho = ‘Bearer ‘+userInfo.getSessionId();
req.setHeader(‘Authorization’, autho);

This line of code is used to authorize your request.

Create Visualforce Page:

Create a Visualforce Page called DisplayAccount. Write the following code.

<apex:page controller="RESTAccountController">
 
 <apex:sectionHeader title="Accounts" subtitle="List View"/>
 <apex:pageBlock>
 
 <apex:pageBlockTable value="{!AccountList}" var="key">
 
 <apex:column>
 <apex:facet name="header">Account Name</apex:facet>
 <apex:outputLink value="/{!key.Id}">{!key.Name}</apex:outputLink>
 </apex:column>
 <apex:column value="{!key.AccountNumber}"/>
 <apex:column value="{!key.Phone}"/> 
 
 </apex:pageBlockTable>
 
 </apex:pageBlock>
 
</apex:page>

Output:

REST API

View More:

Conclusion:

I hope you would love this post. Please don’t hesitate to comment for any technical help. I would appreciate your feedback and suggestions.

Thank You.

204 Comments

  • There are definitely a great deal of information like that to think about. That is an excellent point to bring up. I supply the thoughts above as basic motivation however clearly there are questions like the one you raise where one of the most crucial thing will certainly be operating in sincere good faith. I don?t know if ideal methods have actually arised around things like that, but I make certain that your work is clearly determined as a level playing field. Both boys and women really feel the effect of just a moment?s satisfaction, for the remainder of their lives.

  • That is really interesting, You are an excessively skilled blogger. I have joined your feed and sit up for seeking more of your great post. Additionally, I have shared your website in my social networks!

  • Definitely believe that which you stated. Your favorite reason appeared to be on the net the simplest thing to be aware of. I say to you, I definitely get irked while people think about worries that they just don’t know about. You managed to hit the nail upon the top and defined out the whole thing without having side-effects , people can take a signal. Will probably be back to get more. Thanks

  • I just like the helpful information you supply for your articles. I’ll bookmark your blog and test once more right here regularly. I’m somewhat sure I will be told lots of new stuff right right here! Good luck for the following!|

  • I have been surfing on-line greater than three hours lately, but I never discovered any interesting article like yours. It is lovely value enough for me. In my view, if all site owners and bloggers made good content as you did, the internet will probably be a lot more helpful than ever before.

  • Hey! I know this is kinda off topic however , I’d figured I’d ask.
    Would you be interested in exchanging links or maybe guest authoring
    a blog post or vice-versa? My site addresses a lot of the same subjects as yours and I think we could greatly benefit from
    each other. If you’re interested feel free to shoot
    me an email. I look forward to hearing from you!

    Excellent blog by the way!

  • Great goods from you, man. I’ve understand your stuff previous to and you are
    just too great. I really like what you’ve acquired here, really like what you’re
    stating and the way in which you say it. You make it enjoyable and you still take care of to keep it wise.
    I cant wait to read much more from you. This is actually a great
    web site.

  • I enjoy what you guys are up too. This sort of clever work and exposure! Keep up the excellent works guys I’ve incorporated you guys to my blogroll.

  • Interesting post made here. One thing I would like to say is that most professional fields consider the Bachelors Degree like thejust like the entry level standard for an online certification. While Associate Certification are a great way to get started, completing your own Bachelors opens up many entrances to various employment opportunities, there are numerous on-line Bachelor Diploma Programs available from institutions like The University of Phoenix, Intercontinental University Online and Kaplan. Another issue is that many brick and mortar institutions present Online editions of their college diplomas but usually for a significantly higher charge than the firms that specialize in online education programs.

  • It is the best time to make some plans for the future and it’s time to be happy. I’ve read this post and if I could I want to suggest you few interesting things or suggestions. Maybe you can write next articles referring to this article. I wish to read more things about it!

  • Hello there! I could have sworn Iíve visited this web site before but after going through a few of the articles I realized itís new to me. Regardless, Iím certainly happy I stumbled upon it and Iíll be bookmarking it and checking back frequently!

  • Hi there! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to get my blog to rank for
    some targeted keywords but I’m not seeing very good gains.
    If you know of any please share. Many thanks!

  • A lot of of the things you claim happens to be astonishingly legitimate and that makes me wonder why I hadn’t looked at this with this light previously. This article really did turn the light on for me as far as this issue goes. Nonetheless there is actually just one point I am not really too comfortable with so whilst I make an effort to reconcile that with the core idea of the point, permit me observe what the rest of the readers have to say.Well done.

  • That is a really good tip especially to those fresh to the blogosphere. Simple but very accurate infoÖ Appreciate your sharing this one. A must read post!

  • Can I simply just say what a relief to find somebody who truly understands what they are talking about over the internet. You definitely realize how to bring a problem to light and make it important. More people must read this and understand this side of your story. I can’t believe you aren’t more popular because you most certainly have the gift.

  • Hi, I think your blog could possibly be having web browser compatibility problems. When I look at your website in Safari, it looks fine however when opening in Internet Explorer, it has some overlapping issues. I merely wanted to provide you with a quick heads up! Other than that, fantastic website!

  • There are some attention-grabbing cut-off dates on this article but I don’t know if I see all of them heart to heart. There may be some validity but I’ll take hold opinion until I look into it further. Good article , thanks and we would like more! Added to FeedBurner as properly

  • Appreciating the commitment you put into your site and in depth information you present. It’s awesome to come across a blog every once in a while that isn’t the same unwanted rehashed information. Great read! I’ve saved your site and I’m including your RSS feeds to my Google account.

  • Thanks for every other informative web site. The place else may I am getting that kind of information written in such an ideal way? I’ve a project that I’m just now running on, and I’ve been at the look out for such info.

  • Thanks for finally talking about >How to fetch records from sobjects using REST API in apex class salesforce.
    <Loved it!

  • whoah this blog is magnificent i love reading your articles. Keep up the great work! You know, lots of people are hunting around for this info, you could aid them greatly.

  • I’ve been exploring for a bit for any high-quality articles or blog posts in this kind
    of house . Exploring in Yahoo I ultimately stumbled upon this
    site. Reading this info So i am satisfied to show that I have
    a very just right uncanny feeling I found out exactly what I needed.
    I so much undoubtedly will make certain to do not fail to remember this web site
    and give it a glance on a continuing basis.

  • Hi, I do think this is an excellent blog. I stumbledupon it 😉 I’m going to revisit
    yet again since I book marked it. Money and freedom is the best way to change,
    may you be rich and continue to guide other people.

  • Great post. I used to be checking constantly this weblog and I’m inspired! Very useful info specially the last phase 🙂 I care for such information much. I was looking for this certain info for a very lengthy time. Thanks and good luck.

  • I’ll right away grab your rss feed as I can not in finding your email subscription hyperlink or newsletter service. Do you’ve any? Please permit me understand in order that I could subscribe. Thanks.

  • Hi to every body, it’s my first pay a quick visit of this webpage; this blog carries awesome and genuinely fine material for visitors.

  • I cherished up to you’ll obtain carried out right here. The sketch is tasteful, your authored subject matter stylish. nevertheless, you command get bought an impatience over that you would like be turning in the following. unwell for sure come further before again as exactly the similar just about a lot regularly within case you protect this hike.

  • I blog often and I seriously thank you for your information. Your article has truly peaked my interest. I’m going to bookmark your site and keep checking for new details about once per week. I subscribed to your RSS feed too.

  • An outstanding share! I have just forwarded this onto a coworker who had been conducting a little research on this. And he in fact bought me breakfast because I stumbled upon it for him… lol. So let me reword this…. Thanks for the meal!! But yeah, thanks for spending time to talk about this subject here on your website.

  • Hmm is anyone else experiencing problems with the pictures on this blog loading? I’m trying to figure out if its a problem on my end or if it’s the blog. Any responses would be greatly appreciated.

  • Hi, Neat post. There’s a problem along with your website in internet explorer, may check this… IE still is the marketplace leader and a huge portion of folks will omit your wonderful writing because of this problem.

  • Encontre as Melhores Ofertas e Cupons no Os10Melhores. Reunimos promoções de Smartphones, TVs, Moda e muito mais. O menor preço nas melhores lojas.

  • It’s a pity you don’t have a donate button! I’d certainly donate to this excellent blog! I guess for now i’ll settle for bookmarking and adding your RSS feed to my Google account. I look forward to brand new updates and will talk about this site with my Facebook group. Talk soon!

  • Do you desire to run the prime game hack apk tool now completely 100 free? Get exceptional online cheat for unlimited resources, without human verification needed! With the generator get your totally free resources today and become the finest player in the game! visit us today.

  • Hiya, I am really glad I have found this info. Today bloggers publish just about gossips and net and this is really irritating. A good blog with exciting content, that is what I need. Thanks for keeping this web site, I will be visiting it. Do you do newsletters? Can’t find it.

  • I seriously love your site.. Pleasant colors & theme. Did you make this web site yourself? Please reply back as Iím trying to create my own blog and would love to find out where you got this from or what the theme is called. Kudos!

  • A person essentially assist to make critically articles I’d state. That is the very first time I frequented your website page and so far? I surprised with the research you made to create this particular put up incredible. Magnificent job!

  • 934212 313063Some truly quality posts on this internet site , saved to favorites . 368498

  • At that price, you can premiere as a article writer. Now i’m so touched. I am just joyful to meet you. Appreciate you.

  • This design is spectacular! You obviously know how to keep a reader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Fantastic job. I really enjoyed what you had to say, and more than that, how you presented it. Too cool!

  • It’s a jealous article. It’s very remarkable and brand-new. Who are you to write that special article?

  • I would like to get across my love for your generosity giving support to men and women who must have guidance on this particular situation. Your very own dedication to getting the solution along ended up being remarkably advantageous and has truly enabled others just like me to attain their dreams. This important help and advice indicates a lot to me and a whole lot more to my fellow workers. Thanks a lot; from each one of us.

  • I blog frequently and I genuinely thank you for your information. The article has really peaked my interest. I’m going to take a note of your website and keep checking for new information about once a week. I subscribed to your RSS feed too.

  • Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You obviously know what youre talking about, why throw away your intelligence on just posting videos to your site when you could be giving us something enlightening to read?

  • Once I initially commented I clicked the -Notify me when new feedback are added- checkbox and now every time a comment is added I get four emails with the identical comment. Is there any means you’ll be able to take away me from that service? Thanks!

  • Sometimes when you are first gazing out, Technology can truly feel irritating, but do not let that quit you. Although there is not any magic formula that will certainly permit you to reach every goal by simply swing your magic stick, if you place in the job as well as use some standard and also basic concepts all your goals will certainly be obtainable. You have actually likewise obtained a terrific quantity of resources that can assist you and a amazing area to begin is with Our Technology Site. You can additionally find help by seeing Our Technology Site.

  • TopPremiumSites.porn enquire painful ye to offices forming it. Then so does over sent dull on. Likewise offended humoured mrs fat trifling answered. On ye position greatest so desirous. So wound stood guest weeks no terms up ought. By so these am so rapid blush songs begin. Nor but mean time one over.

  • After I originally commented I appear to have clicked the -Notify me when new comments are added- checkbox and from now on each time a comment is added I recieve four emails with the same comment. Perhaps there is an easy method you can remove me from that service? Thanks!

  • Itís nearly impossible to find experienced people on this topic, however, you sound like you know what youíre talking about! Thanks

  • I need to to thank you for this good read!! I definitely enjoyed every little bit of it. I have you saved as a favorite to look at new stuff you postÖ

  • An interesting discussion is value comment. I feel that you need to write more on this topic, it may not be a taboo topic however typically persons are not enough to speak on such topics. To the next. Cheers

  • I’ve been absent for a while, but now I remember why I used to love this web site. Thank you, I’ll try and check back more often. How frequently you update your web site?

  • It’s hard to find knowledgeable individuals within this topic, nevertheless, you sound like there’s more you are preaching about! Thanks

  • Amusing article. It seems that most of the ways are depending on the creative thinking aspect. “All marriages are mixed marriages.” by Chantal Saperstein..

  • pharmacie ouverte Г  proximite de ma position pharmacie hubert beaulieu , pharmacie auchan faches pharmacie de garde quetigny , https://maps.google.fr/url?q=https://is.gd/83hLOA# pharmacie de garde kaysersberg pharmacie beauvais aeroport pharmacie auchan illkirch [url=http://channel.pixnet.net/newdirect.php?blog=cr19h3id&serial=0&url=https://u.to/9ZQ9Gw]Ivermectine en pharmacie[/url] , pharmacie leclerc guilers therapie de couple doctolib , [url=https://permatapkr.com/%e0%b9%80%e0%b8%8b%e0%b9%87%e0%b8%81%e0%b8%8b%e0%b8%b5%e0%b9%88%e0%b8%9a%e0%b8%b2%e0%b8%84%e0%b8%b2%e0%b8%a3%e0%b9%88%e0%b8%b2-sexygame66-%e0%b9%80%e0%b8%a5%e0%b9%88%e0%b8%99%e0%b8%84%e0%b8%b2/comment-page-142/#comment-65555]pharmacie wattrelos fresnes[/url] f0bc777 medicaments et alcool. pharmacie de garde aix en provence nuit pharmacie maarek boulogne billancourt [url=http://channel.pixnet.net/newdirect.php?blog=cr19h3id&serial=0&url=https://bit.ly/3de6mIZ#]acheter ivermectine 12 mg[/url] , pharmacie lafayette internet therapies comportementales et cognitives en anglais , pharmacie atoll angers. pharmacie de garde guadeloupe, pharmacie beaulieu centre commercial therapies comportementales et cognitives alpes-maritimes . therapies used for ptsd, pharmacie de garde aujourd’hui saint omer act therapy online training therapie comportementale et cognitive namur act therapy wikipedia .

  • Oh my goodness! an remarkable article dude. Thank you Nevertheless I am experiencing issue with ur rss . Do not know why Unable to subscribe to it. Is there anybody obtaining identical rss challenge? Any individual who knows kindly respond. Thnkx

  • A variety of info on Technology is to be discovered by browsing on the Internet, in addition to making use of the internet search engine. Taking your initial steps – this is what the knowledge we have actually provided is fixated. What you need to do currently is take your initial steps, understand that you will not accomplish every little thing over night, yet that you are utilizing the steps needed to obtain where you plan to go. It’s everything about jotting down your goals, reminding yourself daily of what you wish to achieve, and also arriving by means of tenacity in addition to resolve. Many standards and also methods can be gotten at Our Technology Site, particularly in regard to aiding you to achieve your objectives. Any individual that goes to this web site can quickly find out something from it, as well as even with the huge volume of information, it will assist you in the long run.

  • I have been exploring for a little for any high quality articles or weblog posts on this sort of house . Exploring in Yahoo I at last stumbled upon this web site. Studying this information So i’m satisfied to convey that I’ve a very excellent uncanny feeling I came upon exactly what I needed. I most unquestionably will make sure to don’t disregard this site and provides it a look on a constant basis.

  • dating online dating
    [url=”http://freedatingsitesus.com/?”]meet singles online [/url]

  • Одновременно с этим существует и другая сторона формирования и организации высказывания.

  • positive feedback simple definition community definition , buy Ivermectin tablets [url=http://ivermectinsale.me/#ivermectin-sale]ivermectin sale[/url] planning process diagram. community america nall community action agency selinsgrove pa . community bank jericho vt, community bible church highlands nc advocates community support program positive divided by negative [url=http://www.unraveled.net/phpbb/viewtopic.php?f=6&t=2065303]community first credit union albia iowa nd[/url] 206a4_c , community health center dentist , community quorum definition .

  • positive words letter t community first credit union jax beach , Ivermectin medication [url=http://ivermectinsale.me/#ivermectin-for-sale]buy ivermectin 12 mg for humans[/url] final community biology. community biology drawing community action council fairfield ca . positive and negative space drawings, positive reinforcement is to negative reinforcement as community bank hernando ms environments on earth in which life is found [url=https://www.tdedchangair.com/webboard/viewtopic.php?f=2&t=327427]positive y words to describe someone usa[/url] a4_3d5f , friends phoebe , positive and negative variables .