• IntroAmmy
  • NEWBIE
  • 30 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 3
    Replies
Is there any way to accept dd/mm/yyyy format date in lightning component

date field 
               <lightning:input aura:id="birthdate" label="DOB="{!v.leadObj.HealthCloudGA__BirthDate__c}"
                                type="date"  displayDatePicker="true" 
                                 required="true" onchange="{!c.changeDate}" format="mm/dd/yyyy" dateStyle="short" />

I also checked with format="dd/mm/yyyy" its not working it only accepting mm/dd/yyyy
tried also datestyle attribute in component as short but accepting same mm/dd/yyyy

.js
where i am calulating age based on DOB

var birthday = component.find("birthdate").get("v.value");
if(birthday !=null ||  birthday!=undefined)
        {
            var optimizedBirthday = birthday;
        }
        else{
            alert("Enter correct date format");
        }
        
        // it will accept two types of format yyyy-mm-dd and yyyy/mm/dd
        //var optimizedBirthday = birthday.replace(/-/g, "/");
        //set date based on birthday at 01:00:00 hours GMT+0100 (CET)
        var myBirthday = new Date(optimizedBirthday);
        // set current day on 01:00:00 hours GMT+0100 (CET)
        var currentDate = new Date().toJSON().slice(0,10)+' 01:00:00';
        // calculate age comparing current date and borthday
        var myAge = ~~((Date.now(currentDate) - myBirthday) / (31557600000));
        // alert(myAge);

Thanks,
I have created a lightning component to insert lead record in Lead object
Need to write test class for that , i am totally new in test class.
Can someone please help me to write a test class 

attaching my js code and Apex controller

InsertLeadRecordsController.js

({
    save : function(component, event, helper) {  
        var birthday = component.find("birthdate").get("v.value");
        var picl;
        //alert("picl");
        if(component.get("v.FieldsToShow")==true){
            picl = component.find("pic").get("v.value");
        //alert("picl");
        if (picl==='choose'){
            picl='';
            component.set('v.leadObj.BIIB_Relationship_With_Patient__c','');
        }
        }
        if(component.get("v.FieldsToShow")==false){
            component.set('v.leadObj.BIIB_Relationship_With_Patient__c','');
        }
        
        var reqfield1 = component.find("doccrm");
        var reqfield2 = component.find("docname");
        var reqfield3 = component.find("ck");
        var reqfield5 = component.find("fname");
        
        reqfield1.showHelpMessageIfInvalid();
        reqfield2.showHelpMessageIfInvalid();
        reqfield3.showHelpMessageIfInvalid();
        reqfield5.showHelpMessageIfInvalid();
        
        if(!reqfield1.checkValidity() || !reqfield2.checkValidity() || !reqfield3.checkValidity() || !reqfield5.checkValidity() ) {
            // Optional message if you want
            alert("Please fill out the required field."); 
            return; // Don't continue past this point
        }
        
        //To Check Email
        var emailField = component.find("email");
        var emailFieldValue = emailField.get("v.value");
        // Store Regular Expression
        var regExpEmailformat = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        
        if(!$A.util.isEmpty(emailFieldValue)){   
            if(emailFieldValue.match(regExpEmailformat))
            {
                emailField.set("v.errors", [{message: null}]);
                $A.util.removeClass(emailField, 'slds-has-error');                
            }else
            {
                $A.util.addClass(emailField, 'slds-has-error');
                emailField.set("v.errors", [{message: "Please Enter a Valid Email Address"}]);               
            }
        }
        
        if($A.util.isEmpty(component.find("lname").get("v.value"))){
            //component.set("v.hasError", true);
            alert('Last Name is required');
            return false;
        }
        
        if($A.util.isEmpty(component.find("email").get("v.value"))){
            //component.set("v.hasError", true);
            alert('Email is required');
            return false;
        }
        if($A.util.isEmpty(component.find("phone").get("v.value"))){
            //component.set("v.hasError", true);
            alert('Phone is required');
            return false;
        }
        if($A.util.isEmpty(component.find("birthdate").get("v.value"))){
            //component.set("v.hasError", true);
            alert('Birth Date is required');
            return false;
        }
        
        // it will accept two types of format yyyy-mm-dd and yyyy/mm/dd
        var optimizedBirthday = birthday.replace(/-/g, "/");
        //set date based on birthday at 01:00:00 hours GMT+0100 (CET)
        var myBirthday = new Date(optimizedBirthday);
        // set current day on 01:00:00 hours GMT+0100 (CET)
        var currentDate = new Date().toJSON().slice(0,10)+' 01:00:00';
        // calculate age comparing current date and borthday
        var myAge = ~~((Date.now(currentDate) - myBirthday) / (31557600000));
        alert(myAge);
        //var today = $A.localizationService.formatDate(Date.now(currentDate), "YYYY-MM-DD");
        var dateValue = component.get("v.leadObj.HealthCloudGA__BirthDate__c");
        if(dateValue >= currentDate){
            alert('You can not enter grater than today!');
            return false; 
        }

        if(component.get("v.FieldsToShow")==true){

        if (myAge<18 && component.find("Fulname").get("v.value")== undefined) 
        {        
            alert("Full Name Responsible is required");
            return false;  
        }
        if (myAge<18 && component.find("cpfname").get("v.value")== undefined) 
        {        
            alert("CPF Of The Person In charge is required");
            return false;  
        }

        if (myAge<18 && picl==='')
        {
            alert('Please fill the Relationship With Patient');
            return false; 
        }
        if (myAge<18 &&component.find("ck1").get("v.value")== undefined)
        {
            alert('Please Select Declaration Of Legal Responsibility');
            return false; 
        }
        }
        
        if(component.get("v.FieldsToShow1")==true){
            
            if (myAge>18 && component.find("cpfpatient").get("v.value")== undefined) 
            {        
                alert("CPF Patient is required");
                return false;  
            }
        }
    
        
        var action = component.get("c.saveLead");
        action.setParams({"leadObj":component.get("v.leadObj")});
        action.setCallback(this,function(result){
            var state = result.getState();
            if(state === 'SUCCESS'){
                // component.set("v.isShow",false);
                var leadId = result.getReturnValue();
                alert('leadId'+leadId);
                //component.reinit();
                //component.find('form').value = '';
                // component.find("FirstName").set("v.value", '');
                // component.find("birthdate").set("v.value", '');
                //alert('leadId'+leadId);
                
                window.location.href = 'https://hcdev2021-latamchatbot.cs90.force.com/Thankyoupage';
            }
  
        });

        $A.enqueueAction(action);
    },
    doInit: function(cmp) {
        var pickvar = cmp.get("c.getPickListValuesIntoList");
        pickvar.setCallback(this, function(response) {
            var state = response.getState();
            if(state === 'SUCCESS'){
                var list = response.getReturnValue();
                cmp.set("v.picvalue", list);
            }
            else if(state === 'ERROR'){
                //var list = response.getReturnValue();
                //component.set("v.picvalue", list);
                alert('ERROR OCCURED.');
            }
        })
        $A.enqueueAction(pickvar);
        
    },
    
    changeDate : function(component, event, helper) {
        var birthday = component.find("birthdate").get("v.value");
        var optimizedBirthday = birthday.replace(/-/g, "/");
        //set date based on birthday at 01:00:00 hours GMT+0100 (CET)
        var myBirthday = new Date(optimizedBirthday);
        // set current day on 01:00:00 hours GMT+0100 (CET)
        var currentDate = new Date().toJSON().slice(0,10)+' 01:00:00';
        // calculate age comparing current date and borthday
        var myAge = ~~((Date.now(currentDate) - myBirthday) / (31557600000));
        alert(myAge);
        
        if(myAge < 18){
            component.set("v.FieldsToShow",true);    
        }
        else if(myAge > 18){
            component.set("v.FieldsToShow",false);    
        }
        
         if(myAge > 18){
         component.set("v.FieldsToShow1",true);    
        }
         else if(myAge < 18){
         component.set("v.FieldsToShow1",false);    
        }
        
    },
    
    
    handleCheck : function(component, event, helper) {
        var newCheckBoxValue = component.find("ck").get("v.checked");
        component.set('v.leadObj.BIIB_Consent__c',newCheckBoxValue);
        console.log(newCheckBoxValue);
    },
    handleCheck1 : function(component, event, helper) {
        var newCheckBoxValue1 = component.find("ck1").get("v.checked");
        component.set('v.leadObj.BIIB_Declaration_Of_Legal_Responsibility__c',newCheckBoxValue1);
        console.log(newCheckBoxValue1);
    }
})



Apex class(WebToLeadController)

public class WebToLeadController{

@AuraEnabled
public static Id saveLead(Lead leadObj){
System.debug('@' +leadObj);
try{
   insert leadObj;
   }
   catch(exception e){
   AuraHandledException ex = new AuraHandledException(e.getMessage());
    ex.setMessage(e.getMessage());
    throw ex;
   }
   return leadObj.id;
   
}
@AuraEnabled
     
    public static List<String> getPickListValuesIntoList(){
        List<String> pickListValuesList = new List<String>();
        Schema.DescribeFieldResult fieldResult = Lead.BIIB_Relationship_With_Patient__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry pickListVal : ple){
            pickListValuesList.add(pickListVal.getLabel());
            System.debug('Values in Rating are: '+pickListValuesList);
        }     
        return pickListValuesList;
    
    }
}
 
I have created lightning component and 6 fields there, one date field is also there
how can we do that if age is more than 18 years then 2 fields shoud be hide.
Can please someone help me on that...

Thanks in advance
I have created a VF page , can we make it responsive so that it will open in mobile device as user friendly.
menas n need to scroll page left/right side on mobile
How can i throw error msg via apex if i have a field name birthdate in vf page and if birthdate is less than 18 years it throw error while i am saving record ..
Can somenone please help.

Thanks,
 
How can we enable more(like i have 3-4 more record type for account but can see only 2) record type in account dropdown while converting a lead to account
I believe this is someting related to access but i am not sure,
can someone help on this ..User-added image
I have created a lightning component to insert lead record in Lead object
Need to write test class for that , i am totally new in test class.
Can someone please help me to write a test class 

attaching my js code and Apex controller

InsertLeadRecordsController.js

({
    save : function(component, event, helper) {  
        var birthday = component.find("birthdate").get("v.value");
        var picl;
        //alert("picl");
        if(component.get("v.FieldsToShow")==true){
            picl = component.find("pic").get("v.value");
        //alert("picl");
        if (picl==='choose'){
            picl='';
            component.set('v.leadObj.BIIB_Relationship_With_Patient__c','');
        }
        }
        if(component.get("v.FieldsToShow")==false){
            component.set('v.leadObj.BIIB_Relationship_With_Patient__c','');
        }
        
        var reqfield1 = component.find("doccrm");
        var reqfield2 = component.find("docname");
        var reqfield3 = component.find("ck");
        var reqfield5 = component.find("fname");
        
        reqfield1.showHelpMessageIfInvalid();
        reqfield2.showHelpMessageIfInvalid();
        reqfield3.showHelpMessageIfInvalid();
        reqfield5.showHelpMessageIfInvalid();
        
        if(!reqfield1.checkValidity() || !reqfield2.checkValidity() || !reqfield3.checkValidity() || !reqfield5.checkValidity() ) {
            // Optional message if you want
            alert("Please fill out the required field."); 
            return; // Don't continue past this point
        }
        
        //To Check Email
        var emailField = component.find("email");
        var emailFieldValue = emailField.get("v.value");
        // Store Regular Expression
        var regExpEmailformat = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        
        if(!$A.util.isEmpty(emailFieldValue)){   
            if(emailFieldValue.match(regExpEmailformat))
            {
                emailField.set("v.errors", [{message: null}]);
                $A.util.removeClass(emailField, 'slds-has-error');                
            }else
            {
                $A.util.addClass(emailField, 'slds-has-error');
                emailField.set("v.errors", [{message: "Please Enter a Valid Email Address"}]);               
            }
        }
        
        if($A.util.isEmpty(component.find("lname").get("v.value"))){
            //component.set("v.hasError", true);
            alert('Last Name is required');
            return false;
        }
        
        if($A.util.isEmpty(component.find("email").get("v.value"))){
            //component.set("v.hasError", true);
            alert('Email is required');
            return false;
        }
        if($A.util.isEmpty(component.find("phone").get("v.value"))){
            //component.set("v.hasError", true);
            alert('Phone is required');
            return false;
        }
        if($A.util.isEmpty(component.find("birthdate").get("v.value"))){
            //component.set("v.hasError", true);
            alert('Birth Date is required');
            return false;
        }
        
        // it will accept two types of format yyyy-mm-dd and yyyy/mm/dd
        var optimizedBirthday = birthday.replace(/-/g, "/");
        //set date based on birthday at 01:00:00 hours GMT+0100 (CET)
        var myBirthday = new Date(optimizedBirthday);
        // set current day on 01:00:00 hours GMT+0100 (CET)
        var currentDate = new Date().toJSON().slice(0,10)+' 01:00:00';
        // calculate age comparing current date and borthday
        var myAge = ~~((Date.now(currentDate) - myBirthday) / (31557600000));
        alert(myAge);
        //var today = $A.localizationService.formatDate(Date.now(currentDate), "YYYY-MM-DD");
        var dateValue = component.get("v.leadObj.HealthCloudGA__BirthDate__c");
        if(dateValue >= currentDate){
            alert('You can not enter grater than today!');
            return false; 
        }

        if(component.get("v.FieldsToShow")==true){

        if (myAge<18 && component.find("Fulname").get("v.value")== undefined) 
        {        
            alert("Full Name Responsible is required");
            return false;  
        }
        if (myAge<18 && component.find("cpfname").get("v.value")== undefined) 
        {        
            alert("CPF Of The Person In charge is required");
            return false;  
        }

        if (myAge<18 && picl==='')
        {
            alert('Please fill the Relationship With Patient');
            return false; 
        }
        if (myAge<18 &&component.find("ck1").get("v.value")== undefined)
        {
            alert('Please Select Declaration Of Legal Responsibility');
            return false; 
        }
        }
        
        if(component.get("v.FieldsToShow1")==true){
            
            if (myAge>18 && component.find("cpfpatient").get("v.value")== undefined) 
            {        
                alert("CPF Patient is required");
                return false;  
            }
        }
    
        
        var action = component.get("c.saveLead");
        action.setParams({"leadObj":component.get("v.leadObj")});
        action.setCallback(this,function(result){
            var state = result.getState();
            if(state === 'SUCCESS'){
                // component.set("v.isShow",false);
                var leadId = result.getReturnValue();
                alert('leadId'+leadId);
                //component.reinit();
                //component.find('form').value = '';
                // component.find("FirstName").set("v.value", '');
                // component.find("birthdate").set("v.value", '');
                //alert('leadId'+leadId);
                
                window.location.href = 'https://hcdev2021-latamchatbot.cs90.force.com/Thankyoupage';
            }
  
        });

        $A.enqueueAction(action);
    },
    doInit: function(cmp) {
        var pickvar = cmp.get("c.getPickListValuesIntoList");
        pickvar.setCallback(this, function(response) {
            var state = response.getState();
            if(state === 'SUCCESS'){
                var list = response.getReturnValue();
                cmp.set("v.picvalue", list);
            }
            else if(state === 'ERROR'){
                //var list = response.getReturnValue();
                //component.set("v.picvalue", list);
                alert('ERROR OCCURED.');
            }
        })
        $A.enqueueAction(pickvar);
        
    },
    
    changeDate : function(component, event, helper) {
        var birthday = component.find("birthdate").get("v.value");
        var optimizedBirthday = birthday.replace(/-/g, "/");
        //set date based on birthday at 01:00:00 hours GMT+0100 (CET)
        var myBirthday = new Date(optimizedBirthday);
        // set current day on 01:00:00 hours GMT+0100 (CET)
        var currentDate = new Date().toJSON().slice(0,10)+' 01:00:00';
        // calculate age comparing current date and borthday
        var myAge = ~~((Date.now(currentDate) - myBirthday) / (31557600000));
        alert(myAge);
        
        if(myAge < 18){
            component.set("v.FieldsToShow",true);    
        }
        else if(myAge > 18){
            component.set("v.FieldsToShow",false);    
        }
        
         if(myAge > 18){
         component.set("v.FieldsToShow1",true);    
        }
         else if(myAge < 18){
         component.set("v.FieldsToShow1",false);    
        }
        
    },
    
    
    handleCheck : function(component, event, helper) {
        var newCheckBoxValue = component.find("ck").get("v.checked");
        component.set('v.leadObj.BIIB_Consent__c',newCheckBoxValue);
        console.log(newCheckBoxValue);
    },
    handleCheck1 : function(component, event, helper) {
        var newCheckBoxValue1 = component.find("ck1").get("v.checked");
        component.set('v.leadObj.BIIB_Declaration_Of_Legal_Responsibility__c',newCheckBoxValue1);
        console.log(newCheckBoxValue1);
    }
})



Apex class(WebToLeadController)

public class WebToLeadController{

@AuraEnabled
public static Id saveLead(Lead leadObj){
System.debug('@' +leadObj);
try{
   insert leadObj;
   }
   catch(exception e){
   AuraHandledException ex = new AuraHandledException(e.getMessage());
    ex.setMessage(e.getMessage());
    throw ex;
   }
   return leadObj.id;
   
}
@AuraEnabled
     
    public static List<String> getPickListValuesIntoList(){
        List<String> pickListValuesList = new List<String>();
        Schema.DescribeFieldResult fieldResult = Lead.BIIB_Relationship_With_Patient__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry pickListVal : ple){
            pickListValuesList.add(pickListVal.getLabel());
            System.debug('Values in Rating are: '+pickListValuesList);
        }     
        return pickListValuesList;
    
    }
}
 
I have created lightning component and 6 fields there, one date field is also there
how can we do that if age is more than 18 years then 2 fields shoud be hide.
Can please someone help me on that...

Thanks in advance
How can i throw error msg via apex if i have a field name birthdate in vf page and if birthdate is less than 18 years it throw error while i am saving record ..
Can somenone please help.

Thanks,