I want to show the error message on Javascript alert popup.Is it possible?
I have a custom detail button which calls below page and creates a related record.If related record exists then I want to show an error message saying Related record exists
public class MyController
{
public void MyActionMethod()
{
// Checks if record exists else throw below error message
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Related record exists.');
ApexPages.addMessage(myMsg);
}
}
<apex:page controller="MyController" action="{!MyActionMethod}">
<!-- rest of page -->
<script>
function onControllerReturn() {
alert('{!message}')
}
</script>
</page>