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
Dave Miller.ax1920Dave Miller.ax1920 

sObject API Id

I wish to derive the sObject API Id for a given sObject type.

Not the record type Id or the object Id.

 

The Id that would e.g. show the Custom Object detail page.

Or more specifically, the value that one should feed to recordtypeselect.jsp as the "ent" parameter.

 

And I don't want code, I want the {!MyObject__c.xyz} format that I can put in the javascript for a custom button.

 

 

Is this possible.

 

(Strictly all I want to do is relabel the New button on a related list on a view page but that seems impossible, so I'm making a custom button to put on said list)

GlynAGlynA

Use this as your OnClick JavaScript code in the "New MyObject" list button:

 

navigateToUrl("/XXX/e?retURL=%2F{!Account.Id}",'RELATED_LIST','MyObject__c');

You have to replace the 'XXX' with the 3-digit key prefix for the MyObject__c object.  To find the key prefix, go to any detail page for your object and look at the URL.  The first 3 characters of the ID are the key prefix.  So if the URL is:

 

https://<your instance>.salesforce.com/a0oJ000000Fe0nf

 

then the key prefix is 'a0o'.

 

You will also need to replace 'Account' with the sObject type of the object whose related list the button is on.  This allows the page to return to the originating record if you cancel your "New MyObject" operation.

 

Note:  This is the basic form.  There are ways to prepopulate fields (in particular, the lookup back to the parent object), but that's more complex.  If this works for you and you need the additional functionality, let me know.

 

If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!

-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator

Dave Miller.ax1920Dave Miller.ax1920
Well, the JS generated by SF seems to use that function so I presume it is in scope.
Can you tell me where you found documentation on it?
Is it a SF js function or the one from flash ?

Eitherway, it doesn't help me at all.
I need a value that goes in the parameters of the initial url, as detailed above.

Just looking at the js that SF generate in the page right now, full of interesting features...
Dave Miller.ax1920Dave Miller.ax1920

Just to confirm, my object has record types so I need to use a url like

/setup/ui/recordtypeselect.jsp?ent=

and thus need the value for 'ent'.

If it was in a controller I suspect I'd probably be chasing down getSObjecTYe() or ... Describe or such.

Dave Miller.ax1920Dave Miller.ax1920

FYI it seems my answer is very much like

 

navigateToUrl('{!URLFOR($Action.RFP_Request__c.New,null)}');

 

 

GlynAGlynA

Cool!  I was just about to try to find the answer to the recordType question; but if you've found the solution, I'll move on to other things.  Thank you for teaching me something I didn't know.  I'm going to do more research into $Action to see what else I've been missing!

 

Good luck with the project!

 

-Glyn

Dave Miller.ax1920Dave Miller.ax1920

FYI My next exercise appears to be how to get the magicnumber for "CF{magicnumber)_lkid" for the field that would get the Id of the thing I've just come from.

 

And all so they customer can have a New button with different text on it!!

GlynAGlynA

To find that number, go to the custom field detail page (Setup | Create | Object | MyObject__c | MyField__c) and look at the URL.  The thing that looks like an ID is your magic number.

 

-Glyn

 

Dave Miller.ax1920Dave Miller.ax1920
...which is fine until I deploy the button & object and then a different dev org has a different number??
GlynAGlynA

We haven't seen that problem in orgs that are all related - a production org and all of its sandboxes have the same id for the same field. You can confirm this by finding the ID in your production org and comparing it to your sandbox (and other sandboxes if possible).  Now it might be a problem if you're working in a DE org and intend to move the code into another org family.  Then, you will have to change the ID before deploying.

 

-Glyn