Wednesday, June 28, 2017

How to find Salesforce API version of your Org in Apex

Sometimes it is required to find out current API version of your Org (Sandbox/Dev Org/Production) in order to perform some operations like making HTTP request to SFDC URI which contains api version.

As of now, I was not able to find any method in apex through which I can get my org current api version So I have created utility class which uses Tooling API to get all version related to org and returning latest/current api version like 39.0,40.0 etc.

Below is complete code for this.


You can run below scripts in developer console to get current API version after saving above class in your org.

Decimal currentAPIVersion = UtilityClassForSFDC.findAPIVersionOfOrg();
system.debug('***************currentAPIVersion:'+currentAPIVersion);

After running you may get "Unauthorized endpoint url". Just add your SFDC base URL in remote site setting to avoid this exception.

Hope this will help!!!
Looking forward for your comments and suggestions..


More Blogs>>: 
USING DATABASE.UPSERT WITH EXTERNAL ID  
DYNAMIC APEX IN SALESFORCE  
SOQL INJECTION IN SOQL  
CUSTOM METADATA AND CUSTOM SETTINGS IMPLEMENTATION TRICKS  
SMART TABLE USING ANGULARJS IN VISUALFORCE PAGE  
REST API TUTORIAL FOR SALESFORCE  
VISUALFORCE COMPONENT FOR RECORD STATUS BAR  
FETCHING FILE FROM EXTERNAL/PUBLIC URL AND STORING IT IN SALESFORCE  

11 comments:

  1. Hi There,

    This is indeed great! But I think perhaps you are generally referring How to find Salesforce API version of your Org in Apex which is getting unsustainable.

    I have an apex datatable returning some User fields from a list in my apex class. I would like to include a column "This Month's Sales" which would return the total $ of opps closed won this month. I can run the SOQL in my class but I'm not sure how to get the correct result per user into the table, i.e. how to put it into the correct row and column in my table. Can I attach this $amount to each user without creating a custom field?

    I am so grateful for your blog. Really looking forward to read more.

    Kind Regards,
    Preethi.

    ReplyDelete
  2. Thank you for this!! Works great for building callouts in my org :)

    ReplyDelete
  3. You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you. csgo high tier accounts

    ReplyDelete
  4. CSGO Medal Accounts have high steam levels and good coins, badges, and medals. The steam level of these accounts ranges from 10 to 500. You don't need to pay more for these steam-level accounts. If you buy level-up sets, it will have cost more than the price of these VIP csgo accounts. CSGO High Tier Prime Accounts From WayToSmurf

    ReplyDelete
  5. Buy Valorant Smurf Accounts from the best gaming marketplace. Valorantatsmurfshop provides best valorant ranked accounts:
    You can find three types of valorant accounts
    NA Region Valorant Accounts
    EU Region Valorant Accounts
    SEA Region Valorant Accounts

    ReplyDelete
  6. PUBG Mobile is littered with vehicles, but most are abandoned and too damaged to be drivable. Learn the visual profiles of the drivable vehicles so you don't waste time. pubg mobile accounts

    ReplyDelete
  7. HOW I GO MY DESIRED XMAS LOAN AMOUNT $520,000.00 FROM A RELIABLE AND TRUSTED LOAN COMPANY LAST WEEK. Email for immediate response: drbenjaminfinance@gmail.com

    Hello everyone, Am here to testify of how i got my loan from BENJAMIN LOAN FINANCE(drbenjaminfinance@gmail.com) I don't know if you are in need of an urgent loan to pay bills, start business or build a house, they offer all kinds of loan. So feel free to contact Dr.Benjamin Scarlet Owen he holds all of the information about how to obtain money quickly and painlessly via Email: drbenjaminfinance@gmail.com

    and consider all your financial problems tackled and solved. Share this to help a soul right now, Thanks


    ReplyDelete
  8. Nice! Very useful information. Munafa Wala Loan agency in Jaipur provide loan at low interest rate Personal Loan Agency in jaipur

    ReplyDelete
  9. Nice article! I found many useful information in your blog, it was awesome to read, thanks for sharing this great content, keep sharing.. Cheap Resume Writing Service

    ReplyDelete
  10. I really loved reading your blog. It was very well authored and easy to understand. Unlike additional blogs I have read which are really not that good. I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he enjoyed it as well!Resume and Linkedin Profile Services

    ReplyDelete
  11. I'm also visiting this site regularly, this web site is really nice and the users are genuinely sharing good thoughts.
    Brand Booster Ltd

    ReplyDelete