Salesforce Interview Questions & Answers Book is now available!

Grab Now

Tips

How to get Salesforce Org Instance name dynamically?

You might come across a requirement where you have to get the instance name of the organisation.

By Teja, ex-Salesforce engineer · Updated July 5, 2019 · 1 min read

You might come across a requirement where you have to get the instance name of the organisation.

In that case we can make use of one of the setup object in Salesforce and get access to the instance name.

This is how the query is gonna look like to get the instance name.

String instanceName = [SELECT InstanceName FROM Organization LIMIT 1].InstanceName;

Learn it by building it

Every course, every code repository, the discussion group and certificates of completion — one subscription.

Keep me in the loop!

Email me when a new episode is published (promise, I will not spam you)

You're signing up to receive emails from Salesforce Casts