In a salesforce if there is relationship between two objects whether it’s a master detail detail relationship or look up relationship , you can create a new record for the child object from the related list section of the master object and that new record already have at least one filled field which would be the Name of the master object, for an example let say if we create a new contact record from account related list section then the name of the account will prepopulated in the contact record but lets take a scenario where you want a custom button and on that button the new window should pop up with prepopulated values in the fields to achieve such functionality you need to do a URL hacking to understand Salesforce URL , Please see below how actually a URL looks like.
Salesforce URL structure
Below is the URL structure of our example that i talked above this is how it would be look like if we create a new contact through account related list.https://ap1.salesforce.com/003/e?retURL=%2F0019000000NynCn&accid=0019000000NynCn
|https://ap1.salesforce.com||It is salesforce instance|
|/003/e?||003 here referring to the contact object which would open in edit mode.|
|retURL=||This keyword hold the ID of record where it should return when user click on cancel button|
|%2F0019000000NynCn||ID of the record where browser redirect user after clicking on cancel button or also this ID also used in lookup field of contact record|
|&accid||Standard lookup Name of Account Field in Contact|
The above explained the URL structure of the salesforce now from the above information we can pass the values of any particular field via URL, Now assume there is one more field in the contact object, let say it is Department and we want to pre populated the value in Department field so to do that we need to append the field ID with its value in URL structure using special character &, to append the field ID we should know first from where we can get ID of the field , so see the below post on how to get ID of the field in salesforce.
If you have gone through the above link then for standard object we have to use inspect element to get the ID of the field , once we have our ID we can append it to the URL , see below URL structure .https://ap1.salesforce.com/003/e?retURL=%2F0019000000NynCn&accid=0019000000NynCn&con6=this is test department
Here &con6=this is test department is the text that we have added to our URL structure,con6 is the field ID and ‘this is test department’ is the value that should going to be be pre populated in the Department field,Now copy the your URL structure that you have created and paste it on the location box of the browser and then hit enter,you will able to see pre populated fields see below image.
This is simple explanation how we can use URL hacking to pre populated the values in the field now we would see how we associate this URL with a button and on button click the value get prepopulated in the next record.
Adding button over detail page of a parent object
Go to that object(Account in our case) property and from there create a new custom button and in the custom button add the URL structure which is shown you above but without the salesforce instance , see below image.
As you can see in the above image that we have changed few things first I remove the hardcore value of the ID instead of that I have taken account.ID which get replace each time by the ID of the account record and one more change I did that I removed the salesforce instance, after saving your button you need to add to the layout and then go to detail page of any account record and click on the button and you will see the same functionality as we are seeing earlier by URL with hardcore values,
Now you have added a new button over the detail page of the account record, if you want the button on the related list of the contact then you need to create the button of type list in contact object, see below image for more details.
Adding button over related list of child object
We have just seen on how to add the button over the detail page of the record and to do it we created the new button in the parent object(Account), if we want to that our button should appeared in the related list of the contact object(child) then we need to create the new button over the child object(contact), see below picture on how to create a new button over the child object.
After adding a new button we need to change the layout so the button should available for the related list, see the below picture which explain what we need to change in the search layout.
After clicking on the List View, we would see all available button which we need to drag it to the selected button and then finally need to click on save, see below picture for more details.
Now our button is available to added over the salesforce related list of contact object and to do that we are required to drag the button from account page layout, see below the picture.
That’s it, now finally click on save button and our button would appear on the related list of contact object.
That’s all for today post I hope you like my this post if you have any query or suggestion then please leave a comment below in the comment section and don’t forget to subscribe to my blog and social networking pages.