function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VibrateVibrate 

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

Rahul_sgRahul_sg
That VF page should have a custom controller class. In that class you can put some apex validations and display the error msg using <apex:pageMessages />
VibrateVibrate

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

sambasamba
Hi Vibrate, You can add the validation on the onclick event or background code. Thanks, Samba
VibrateVibrate

Samba,

 

Could you kindly point me to an example of how to do that?

 

Thanks,

Vibrate

sambasamba

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

 

 

 

VibrateVibrate

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

puneet28puneet28

Hi 

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';
}

 

VibrateVibrate

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

puneet28puneet28

Hi 

VibrateVibrate

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

puneet28puneet28

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