function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vswamidassvswamidass 

INVALID_NEW_PASSWORD using Apex setPassword

Hi,

I have the following method that calls setPassword: 

 

    public PageReference setPassword() {

        results = '';

        isActionSuccessful = false;

        ApexPages.Message myMsg;

            

        try {

       for (User u : getSelectedSobjects()) {

          System.setPassword(u.id,passwordString); 

       }

            results = 'Users updated successfully.';

            isActionSuccessful = true;

    myMsg = new ApexPages.Message(ApexPages.Severity.CONFIRM, results);        

        } catch (Exception e) {      

            results = e.getMessage();

    myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Error updating users: ' + results);            

        }      

   

        PageReference p = Page.SUMOAction;        

        return p;      

        

    }     

 

However, if the password violates the Org Password Policy, the resulting INVALID_NEW_PASSWORD Exception is not caught - I just see "An unexpected error has occurred. Your development organization has been notified." on the screen.  

Why is INVALID_NEW_PASSWORD not catchable?

PM_SFDCPM_SFDC

Did you find the solution to this problem. I want to catch this and compare it.

Please share your experience on this issue.