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
Mariem MejrissiMariem Mejrissi 

login page in salesforce lightning

I have to create the login page with User name and password in lightning 

I have created the fields, but I have this error when I enter invalid password or username.

This page has an error. You might just need to refresh it. Error in $A.getCallback() [Cannot read property 'login__c' of null] Callback failed: apex://LoginController/ACTION$getressource Failing descriptor: {markup://c:login}

Can you please help me in this.

Login controller.js
({
    doInit : function(component, event, helper) {
        
    },
    
 
    loginPage : function(component, event, helper) {
         var userid = component.get("v.Empiduser"); 
        var pass= component.get("v.Empidpwd");
        
        var action = component.get("c.getressource");
        
            action.setParams({
              username:userid,
              userpassw:pass
        });
    
         action.setCallback(this,function(response){  
           if($A.util.isEmpty(userid ) || $A.util.isUndefined(userid )){
            alert('Please Enter User Name!');
          return ;
        }   
          if($A.util.isEmpty(pass) || $A.util.isUndefined(pass)){
            alert('Please Enter Password!');
           return;
        } 
        var login= response.getReturnValue().login__c ;
          var password= response.getReturnValue().password__c;
         var role= response.getReturnValue().Role__c;
             
          
             if (login==userid && password==pass &&role=="Scrum Master")
              {
           const myEvent = component.getEvent('firstEvent');
            myEvent.setParams({ username: userid });
            myEvent.fire();
              }
             else if ((login==userid && password==pass &&role=="Developer"))
             {
                 const myEvent = component.getEvent('firstEvent');
            myEvent.setParams({ username: userid });
            myEvent.fire();
             }
             else if ((login==userid && password==pass &&role=="Product Owner"))
             {
                 const myEvent = component.getEvent('firstEvent');
            myEvent.setParams({ username: userid });
            myEvent.fire();
             }
             
             else 
             {
                 
                 alert("echec");
             }
         
          });
         $A.enqueueAction(action);
        
      
    },   
         
    
   
})
class Apex

public class LoginController {
    @auraEnabled
    public static Ressource__c getressource(String username,String userpassw ){
       return ([SELECT login__c,Name,password__c,Role__c,Tel__c FROM Ressource__c where login__c=:username and password__c=: userpassw]);
    }
 
    
}
Regards,
Mariem 
Alain CabonAlain Cabon

response.getReturnValue() should be null.

var login= response.getReturnValue().login__c ;

You should test the states of the response (above all SUCCESS and ERROR ) because there is an error.
 
       
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                
               console.log("From server: " + response.getReturnValue());
             
            }
            else if (state === "INCOMPLETE") {
                console.log('incomplete');
            }
            else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                 errors[0].message);
                    }
                } else {
                    console.log("Unknown error");
                }
            }
        });
       $A.enqueueAction(action);

The messages of the console.log are seen in the Chrome DevTools.

When you want to see logged messages or run JavaScript, press Command+Option+J (Mac) or Control+Shift+J (Windows, Linux, Chrome OS) to jump straight into the Console panel.

https://developers.google.com/web/tools/chrome-devtools
 
Caleb Kuester 27Caleb Kuester 27

Here is the offending line:

var login= response.getReturnValue().login__c ;

If there is an error, then getReturnValue() is not going to return an object with the login__c field, so it's like you're trying to open the door of a rock. Rock doesn't have a door, so there will be problems.

The previous guy should get the best answer.

shane buchshane buch
From Setup, enter Lightning Components in the Quick Find box, then select Lightning Components under Develop.
From the list of components, click the one you want to customize. ...
On the Lightning component detail page, click Developer Console https://www.tellpopeyes.us/