", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000A80veSAB", "datePublished": "2016-01-30T14:28:38.000Z", "author": { "@type": "Person", "name": "Nitin Indora", "url": "https://trailblazers.salesforce.com/profileView?u=0053000000B0oGbAAJ", "affiliation": { "@type": "Organization", "name": "IBM" } } } ] } } Skip to main content
2 réponses
  1. 30 janv. 2016, 14:28
    ApexPages.Message is designed to work with the Visualforce managed elements for displaying such messages (apex:pageMessages and apex:messages). You wouldn't use these methods to show a popup in JavaScript, unless you were using an advanced programming technique, such as a lightbox. For a simple alert, you want pure text, not rendered HTML code that you'd have to parse/strip. This means that a @RemoteAction would be more appropriate, although this doesn't let you get to the page state.

     

    If you want to return a simple message, the traditional means of doing so is to expose that message through a rendered element. Consider the following:

     

    <apex:inputHidden value="{!lastMessage}" id="lastMessage" /> <apex:actionFunction action="{!myActionMethod}" reRender="lastMessage" onComplete="getLastMessage()" status="statusElement" /> <script> function getLastMessage() { var msg = document.getElementById("{!$Component.lastMessage}"); if(msg.value) alert(msg.value); } </script>
0/9000