I have a standard Object (ServiceContract) which has a Master-Detail relation with ContractLineItem (also a standard object). ContractLineItem further has a master-Detail relation with a custom object – TransactionLineItem.
When i click on "New Transaction Line Item" button on contract line item page layout, another page opens where you can create a new TransactionLineItem record. On that page, there is a lookup to ServiceContract and ContractLineItem. I want these two autopopulated.
Can anyone give any suggestion. I know the simplest way is to put a custom button (which uses javascript) for "New Transaction Line Item" and use URL hacking. But it involves a bit of hardcoding. Is there a way to be able to do this without any kind of hardcoding? So that when we push it all into production, i don't have to change anything.
Best Answer
Solution 1: URL Hacking without JS
URL hacking doesn't require you to use javascript. I created a short video to explain the way URL hacking works a couple of years ago.
The simplest way is to use URL hacking in your live system and refresh your sandbox. The field ids for fields in live and sandbox systems are the same after a refresh.
However, this doesn't answer your question. Therefore there is solution 2.
Solution 2: Apex and Tooling API
As proposed by Andy you can use the Tooling API to get field Ids from Salesforce. He is using APEX and a Tooling API wrapper to query the required field ids:
In the most scenarios this kind of "hack" seems to be a bit too complicated compared to standard URL hacks...
Implementation outline for Solution 2
Create a new button which opens the new visualforce page.
Don't forget to write a test class. Don't forget to mock all call outs. (callouts are not available during test)
Before implementing 1-6 please consider the following aspects: