You need to sign in to do that
Don't have an account?

How to create a avlidation to override the new button on a custom related list
Hi,
I have a related list with a "new" button that currently takes the user to a custom VisualForce page when the button is clicked. The user now wants me to perform a validation to determine if they should be taken to the custom VisualForce page or an error message should be displayed. Any and all help with this issue is appreciated.
Thanks,
Vibrate
Hi,
Where in the Custom Controller class do I put the validation logic? Do I need to create some type of event sink for the button click? I need to do this validaion when the button is clicked.
Thanks,
Vibrate
Samba,
Could you kindly point me to an example of how to do that?
Thanks,
Vibrate
Hi Vibrate,
For example:
<script>
function red()
{
alert();
}
</script>
<apex:commandbutton onclick="red();"/>
If you still have not solved this problem, you can send your sandbox username and password to my email. You know, If it just take a little time, I will do it. Otherwise, you need to pay me a little money.
Thanks,
Samba
Samba,
Thanks for helping we with this issue. However, using your suggested solution would require that I create a custom button and loose the functionalities I get by using the OOB related list. I am not sure I want to code all the stuff I would get by using the related list OOB functionality. I was hoping I could override the OOB on-click event of that button and do the validation before sending the user an error message or to the next VisualForce page.
Thanks,
Vibrate
Hi Vibrate,
Create a List Button on the Child Object (the object whose list is displayed in related list).
Select
Display Type List Button
Behavior Execute JavaScript
Content Source OnClick JavaScript
var acc = '{!Account.Account_Total_Amount__c}'; alert(acc); if(acc == 700) { alert('error'); } else { window.location = 'apex/YourVisualforcePage'; }
Here in example I have assumed the Parent Object as Account and related list of Contacts.
So create the above button on Contact Object.
It will check the value of a field on Parent Account object and conditionally redirect to your Visualforce Page.
Puneet,
Thanks for taking the time to help with this issue. I have one quick question for you. When you create the new related list records do they list on the VisualForce page you made the call from and are you able to utilized the edit and delete links for the related list items?
Thanks,
Vibrate
Hi Vibrate,
The button I have created is for standard detail page in the Related List Section of child object.
I believe you are calling are currently calling a visualforce page by click of a button in the related list and you wanted to check some condition before the page can be called?
Correct me if I am wrong.
Puneet,
Thanks for the help. I really appreciate you taking the time to help me with this. I am having an issue of getting back to the calling page when I try to use this code: "window.location = 'apex/YourVisualforcePage';" Do I need to pass a page/object reference of a page/object that has not yet been created? And how do I get the reference of the initial page/object when I am ready to come back? Please remember when the user clicks the button the new object would not have been created. Thanks agan for all the help.
Thanks,,
Vibarate
I'm a bit confused.
You will have to change the logic of Visualforce page 'YourVisualforcePage' so that when the related record is saved, you are redirected back to parent object detail page.
You will have to use PageReference for it.
Refer:
http://boards.developerforce.com/t5/Visualforce-Development/URL-redirection-after-saving/td-p/438067