Skip to main content

Posts

Showing posts with the label sandbox extension name

How to get sandbox name in apex?

As we all know sandbox username looks like " behera@mycompany.com.dev  " dev- is the sandbox name, How can we get it this dynamically ? Use below code :- if( UserInfo.getUserName().substringAfterLast('.com') != null)                     contact.Email = contactInfo.Email+'.'+ UserInfo.getUserName().substringAfterLast('.') ;                 else                     contact.Email = contactInfo.Email; } UserInfo.getUserName().substringAfterLast('.') - will give you sandbox name. UserInfo.getUserName().substringAfterLast('.com') will tell you whether anything is there after " .com ". if not there that means we are in production otherwise in sandbox.  We can also used same method to identify type of org like prod or non prod. There is another approach for this.  Organization org = [select id,IsSandbox fro...