Sunday, 16 February 2014

How to auto-Populate the lookup field from other object.(URL-Hacking in Salesforce).

Hi Guys ... Hows Apex and Visualforce Doing ?? :P

So Last week I was working URL hacking ..I mean to say Override the functionality of new custom button . Some people says that It is "URL hacking". Any ways, whatever it is . So lets get started. 

If you have a query to Auto populate the lookup field from  other object . Let me create an senario for you.
So  Lets say I have three objects testContact ,TestApp and TestURL.

Note : There is no master detail relation between the two. Also it never depends whether there is relation between it or not . 

Any ways lets move ahead. Now there are two fields in each object . TestApp has a look up of TestContact one . My objective is to Auto Popoulate the lookup of TestApp  from detail page of TestContact. Follow these steps :-



  1. First create a lookup of testContact on testApp.
  2. Edit, the page layout of TestContact and in its related list add testApp.
  3. Now , create the lookup relationship of TestApp and TestContact on TestURL.
  4. Edit, the page Layout of testApp and add the TestUrl on its related list.


Now , Lets move ahead. have you ever worked on buttons and Links section under an custom object . let me guide you if not .
Remember: We will try to auto populate the lookup of TestContact on TestUrl. This should be auto populated when trying to make a new testUrl record from TestApp page layout.

Now, Click on the object of TestUrl edit it. Go to the Buttons,links and action section. Click on NewButton or Link.
Am goint to attach screen shots :- 

1.  





Now, in this as you can see that I have created the new button with name Newurl. From behaviour field choose choose Display in existing window and sidebar. Content Source should be URL.


2. Now , go to the testApp object from there try to create a new record for TestUrl.
  


Now , try  to copy the part as indicated in Picture. First copy the link marked in in the URL. and save somewhere in notepad. and then the id of Field as indicted by the inspect element . It is the id of field which will be using to append in URL.

3.
Now , go to the object agaiin where we were making the new button and paste the link and id there as shown below.:-



4. Now , add the field from selectfield Type  section from where you can . now here is a twist that we have to add the TestContact name which is there in TestApp. so we will select TestApp. as object.  And from Insert Field section insert TestContact Name and testApp name and assign their respective Ids which you copied earlier from inspect element.





Now save it finally , But you mut be thinking Y this ret& URL working their. Well, I ll explain it later .


Now , go to testApp page layout and replace this New button with NewURL . and save it .
Now try to create new record You will find that all the lookup fields are auto populated .

But now again try to create the new record , but this time try to cancel it . You will find that it will take you to the home page . so to avoid this we have to append the return url .



Thanks For Reading

Gud day!

Contact : ankushsalesforce@gmail.com
Cheers!!

No comments:

Post a Comment

oAuth Use Case -  Headless API Explained in the Easiest way Wondering why? and When we use the Headless API flow Use case example: Imagine a...