Skip to main content
2 of 2
added code formatting...oops
pchittum
  • 19.8k
  • 5
  • 57
  • 99

The $Action global variable allows you to do this without hard coding the URL. Most actions and their SFDC url can be accessed through this global variable.

Typical usage is in conjunction with the URLFOR function.

For instance, in your case, to create a new record:

{!URLFOR($Action.MyObject__c.New)}

If the object in question has record types enabled, you will automatically be redirected to the record type page.

This is a more durable solution than hard coded URLs since you can create your custom button today on an object that doesn't have record types, and tomorrow when you enable record types, it should automatically pick up the change continue to work without modifying your custom button. It also automatically picks up retURL values from where you put the button.

There are some instances where you have to resort to hard coded URLs, but they are few and far between. I'd always recommend looking into this option first.

pchittum
  • 19.8k
  • 5
  • 57
  • 99