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
GaryP.ax988GaryP.ax988 

Display custom message on standard page?

I have a custom button on the standard Case details page.  The button calls a visualforce page which autoruns some Apex Code..    The code gathers some data and makes an outbound WS call..   It then returns to the current Case Details page..  

 

This code works fine: 

 

        PageReference pageRef = new PageReference('/' + theId);
        pageRef.setRedirect(true);
        return pageRef;

 

when I trie to include a message via this code just before the page ref it doesn't display..  
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO, 'Eligibility Determination Submitted');
        ApexPages.addMessage(myMsg);

 

Do you know if the Case details page includes the Apex:Message tag?   I would think it does but I can't decide if I'm doing my Apex code wrong or if the page just doesn't display messages..  
thanks!!!
Gary

 

mtbclimbermtbclimber
You can not publish anything other than errors (from triggers) into a standard page.

You must use a Visualforce page if you want to do this. You have a couple of options, one of which might "look" like what you want.

1) redirect to a page with just the message on it, sit therefor a few seconds and auto-redirect to the standard page
2) show your own detail page with the message using the apex:detail component on it.

Hope that helps.
GaryP.ax988GaryP.ax988

Thanks..  I just tried a custom page (to display in case of an error) with this code: 

 

 

            if (item.Verification_Status__c != 'Verified') {
            	// not all items verified.. 
		        ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Not all items verified');
        		ApexPages.addMessage(errorMsg);
		        PageReference pageRef = Page.VerificationErrorPage;
		        pageRef.setRedirect(true);
        		return pageRef;
            }

 

 

The custom page is basically the default custom page with the added apex:messages tag in it like this: 

 

<apex:page >
  <apex:messages />
  <h1>Congratulations</h1>
  This is your new Page
</apex:page>

 

 

But all I see displayed on the new page is the congrats message.. no error message..    This feels like very beginner stuff so I am definitely just doing something dumb here..  :-) 

 

thanks!

 

mtbclimbermtbclimber

Remove this line or just set the value to false:

 

 

pageRef.setRedirect(true);