function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pathworkspathworks 

How to use the organization ID in a formula field?

I need to use a formula field to build a hyperlink, part of which must be the current user's organization id.  Something like this:  HYPERLINK("urlhere/instance/" & {!OrgId}).
 
In both the Simple and Advanced formula editors, there is no choice for OrgId as a field.  It is also not available as a function.  I get an error if I try to include it using {!OrgId} or any other syntax I can think of.
 
Less important, but also odd: I don't see an equivalent of the API 7.0 Server URL either.  I just see GETSESSIONID().   Seems you should have access to the same fields as when defining a custom link.  or web tab.  I need to use the session id to go back and validate a single-sign-on request, and am currently having to hard-code na1.ambientsoftware.com, which is not a good thing.
 
- Dan
 
DevAngelDevAngel
Hi pathworks,

You will need to use the getsessionid field to pass the session id to your server, then parse the referrer url to get the salesforce.com instance the customer is homed on and use that for the soap endpoint. 

ie: if the referrer url is https://na3.salesforce.com/003000000l3kk or something like that, you will need to turn that into https://na3.salesforce.com/services/Soap/u/7.0.

With the session id and ther endpoint url, you can now make a query against the organization object to obtain the org id.
pathworkspathworks

Thanks, that makes sense.  My one concern, besides the amount of code and the extra servlet it will take on our side, is the performance implications.  The net result of all this is just to display an image based on a third party service's data, for a composite application.  This solution means that the client browser has to make a request of our service, we have to then authenticate them and get user info from salesforce.com, then have to look up in the data based on the organization id in our database, and then return the data to the browser.  I'll have to see how much latency the extra round trip to salesforce.com costs us - seems like it might be a noticeable delay.

I'd like to suggest an enhancement to include the server url and organization id as available fields, and whatever else is needed to bring it to parity with custom tabs and s-controls.

Dan

 

pathworkspathworks
 
I sat down to code up this solution, where the destination of a URL is a custom servlet that determine the organization ID from the session, using the API.  After coding it all up, I find that it is now not useful to me for the following reason:
 
Error: GETSESSIONID() may not appear in an argument to IMAGE()
 
Above I wrote that I wanted to do this from a HYPERLINK() formula, where you apparently can use GETSESSIONID().  I also need to do this urgently from an IMAGE() formula.  Why can you not use the GETSESSIONID() formula there?
 
Example:
 
IMAGE("http://localhost:8080/myservlet?sessionid=" & GETSESSIONID(), "image")
 
Results in the above error.  Please help!  I need the URL destination of an image in a formula field to include the organization id.  Organization id is not available, so I tried to use the session id, which doesn't work either.  My only solution at present is to have users of the Appexchange offering manually type in the organization id by themselves when configuring the custom field; a very poor solution indeed.
 
Thanks in advance,
Dan
 
Dr WhoDr Who
To answer you first question "How to use the organization ID field in a formula?" try using "$Organization.Id" (without the quotes)