0

I'm trying to implement this forgot username component. And the Apex Controller code works when I test in the builder. But if I test it without logging in it errors out.

global with sharing class ForgotUsernameController {
@AuraEnabled
global static User fetchUser(String emailAddress) {
    List < User > listUsers = [ SELECT Id, Username, IsActive FROM User WHERE Email =: emailAddress ];
    if ( listUsers.size() > 0 ) {
        User usr = listUsers[0];
        return usr;
    } else {
        User noUser = new User();
        noUser.Username = 'No user found with that email';
        return noUser;
    }
}    

In the controller... the response is ERROR outside of login, it's SUCCESS inside.

({
findUser : function(component, event, helper) {
    component.set("v.searchBool", true);
    var action = component.get("c.fetchUser");
    action.setParams({
        emailAddress : component.get("v.email")
    });
    action.setCallback(this, function(response){
        var state = response.getState();
        console.dir(response); // this response is ERROR
        if (state === "SUCCESS") {

            if(response.getReturnValue() == "null")
            {
                component.set("v.userRecord", "No user found!");
            } else {
                component.set("v.userRecord", response.getReturnValue());
            }
        }
    });
    $A.enqueueAction(action);
},

})

0

The apex class requires permissions from the Guest User Profile. The Guest User Profile is under Community Builder -> Settings -> General -> Guest User Profile.

| improve this answer | |

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.