0

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.

0

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:

<apex:pageMessage summary="You have ..." severity="warning" rendered="{! error }"/>

where you define and set an error property in yourcontroller:

public Boolean error {get; set;}

    ...
    error = pr == null;
    ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.