2

I am used to using PageReference in a method like so:

public PageReference transPage()
{
    PageReference newPage = page.PAGE_NAME;
    newPage.getParameters().put('ContactId', selContact.Id);
    newPage.getParameters().put('ContactName', selContact.Name);
    newPage.getParameters().put('AccountId', selContact.Account.Id);
    newPage.getParameters().put('AccountName', selContact.Account.Name); 
    return newPage;
}

I am looking to turn the method into a public void and include an if statement where if true will send to a new page but if false will send an error message.

The help is greatly appreciated in advance

2

Just return a null PageReference, this will simply refresh the page.

public PageReference transPage()
{
    PageReference newPage = page.PAGE_NAME;
    newPage.getParameters().put('ContactId', selContact.Id);
    newPage.getParameters().put('ContactName', selContact.Name);
    newPage.getParameters().put('AccountId', selContact.Account.Id);
    newPage.getParameters().put('AccountName', selContact.Account.Name); 

    if (errorCondition == true) {

        // Add error message to page here
        return null;

    } else {

        return newPage;
    }
}
1

You can do this by returning null instead.

public PageReference transPage()
{
  if (something)
    return null;

  PageReference newPage = page.PAGE_NAME;
  newPage.getParameters().put('ContactId', selContact.Id);
  newPage.getParameters().put('ContactName', selContact.Name);
  newPage.getParameters().put('AccountId', selContact.Account.Id);
  newPage.getParameters().put('AccountName', selContact.Account.Name); 
  return newPage;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.