I would like to know how to be able to display a warning message in a page.
I have created my own custom visual force page:
<apex:page standardController="Lead" extensions="LeadToMerchConvertController">
<apex:form >
<apex:pageBlock >
<apex:pageMessages >
</apex:pageMessages>
</apex:pageBlock>
</apex:form>
</apex:page>
and in the LeadToMerchConvertController I added the following piece of code.
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.WARNING,'There is an existing Merchant: ' + buildAccountTemplate() + ' for this Lead: ' + buildLeadTemplate());
ApexPages.addMessage(myMsg);
The problem is that the above code is placed inside the constructor:
public LeadToMerchConvertController(ApexPages.StandardController controller) {
objLead = (Lead)controller.getRecord();
// System.debug('objLead ' + objLead.Id);
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.WARNING,'There is an existing Merchant: ' + buildAccountTemplate() + ' for this Lead: ' + buildLeadTemplate());
ApexPages.addMessage(myMsg);
}
and if I move the code outside the constructor the warning message disappear from the page.
What I would like to know is it possible to move and use the code outside the constructor and how to make the warning message visible again when the code is outside the constructor?
I will strongly appreciate if you can also, give additional examples/code of how to display warning message in salesforce.
Regards,
Dilyan