Pages

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  

12 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. 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
  5. Nice! Very useful information. Munafa Wala Loan agency in Jaipur provide loan at low interest rate Personal Loan Agency in jaipur

    ReplyDelete
  6. 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
  7. This comment has been removed by the author.

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. Thank you for this!! I really loved reading your blog. Nice! Very useful information. you want to run your business advertisements on Google search results Digital Marketing Comapny In Trichy

    ReplyDelete
  10. The average cost of basement waterproofing ranges between $2,000 and $10,000, but it can go higher for more extensive or complex projects. Waterproofing methods may include interior or exterior drainage systems, foundation crack repairs, installation of sump pumps, and applying waterproof coatings or sealants to walls and floors.

    ReplyDelete
  11. Investing in regular AC Coil Cleaning: is a wise decision to ensure efficient cooling, reduce energy costs, and prolong the lifespan of your AC system

    ReplyDelete
  12. Great Information sharing .. I am very happy to read this article.
    Azure Certification Training course

    ReplyDelete