I have a VF page that produces an Excel file based upon certain products underneath an Opportunity. How would I go about using a VF action to redirect back to the Opportunity standard screen if no matching products were found and display a custom error message?
I can redirect back but I can't figure out how to display an error, for example like using ApexPages.addMessage
Here's my action/redirect code from my extension so far: validOLIs
is a boolean which returns true if the product query returns 0.
//Action to highlight no OLIs were returned
public pageReference noValidOLIS(){
if(validOLIs){
return redirectError();
}
return null;
}
public PageReference redirectError(){
PageReference errorRef = new PageReference('/'+theOpp);
ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.FATAL,'No Products Found'));
return errorRef;
}
Edit: I've tried using addmessage and directing back to the standard page. I'm open to using java script if it can be used to intercept, but I'm not a js expert so would need some guidance.