How can I add custom error message and remove the error message thrown by Site.login in visualforce page?
Im having trouble removing the error message thrown by Site.login that says "Error: Your login attempt has failed. Make sure the username and password are correct."
I need to replace it to another custom error message. I used apex messages but still the Site.login error occurs.
Class:
private PageReference getLoginDetails() {
String startUrl = System.currentPageReference().getParameters().get('startURL');
//return Site.login(username,password, OrganizationSettings__c.getInstance().PortalEmailURL__c +'/'+'dashboard');
// return Site.login(username,password, startUrl);
PageReference pr = Site.login(username,password, startUrl);
if(pr == null ){
//return null;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info, '* You\'ve entered an incorrect username and/or password. Please re-enter your log-in information.'));
}
return pr;
}
VF Page:
<!--** START // DISPLAY ERROR MSG**-->
<apex:pageBlock >
<apex:outputPanel styleClass="errorMsg"><apex:pageMessages id="showmsg"></apex:pageMessages></apex:outputPanel>
</apex:pageBlock>
<!--** END // DISPLAY ERROR MSG**-->
Output:
Error: Your login attempt has failed. Make sure the username and
password are correct.
You've entered an incorrect username and/or password. Please re-enter your log-in information.
Best Answer
Its frustrating that the messages that
apex:pageMessages
presents can't be cleared out and replaced. So you are stuck with not including that tag in your page and instead using your own logic and the apex:pageMessage tag:where you define and set an
error
property in yourcontroller: