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
ShaunCShaunC 

List Button - Force record selection before redirect to VF

I have a List Button placed on a related list which redirects to a VF page. The controller behind the VF page retrieves the list of selected options and the user then performs some operation on those options.

I would like to prevent the redirect to the VF page if the user has not selected any records. I've tried changing the button to a Onclick Javascript and I can detect whether or not there are any options selected, but I'm unable to then Submit their selection and redirect to the VF page. More precisely, I can submit and redirect to the VF page, but the selected options aren't recieved by the controller.

 

Is there a way to do this?

 

Here is the javascript on my List button

 

records = {!GETRECORDIDS($ObjectType.Job_Applicant__c)};

if (records.length < 1) {
  alert('Please select one or more options first.');
} else {
  this.form.action = '/apex/MyVFPage';
  this.form.submit();
}

 Appreciate any suggestions. Cheers.

 

ShaunCShaunC

An update to the above. I can get it to work, but I have to hardcode the link to the VF page, ie:

 

 

records = {!GETRECORDIDS($ObjectType.Job_Applicant__c)};

if (records.length < 1) {
  alert('Please select one or more options first.');
} else {
  this.form.action = 'https://c.ap1.visual.force.com/apex/MyVFPage?retURL={!Position__c.Id}&wrapMassAction=1&scontrolCaching=1&id={!Position__c.Id}';
  this.form.submit();
}

 

Is there a function that will give me the full path to the VF page? ie. https://c.ap1.visual.force.com/apex/MyVFPage

Or is the c.ap1.visual.force.com something that will never change?

 

rscottrscott

Try this:

 

{!$Page.MyVFPage}