• Pratik Kumar
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies

After creation of components dynamically using $A.createComponent() and pushing it to the desired div, component.find("<aura:ID of component>").get("v.value"), where the component used is a 'lightining:input' and aura:ID has already been defined, is showing error message as 'cannot read property get of undefined'. PFB the code snippet:

 

$A.createComponents([
            ["lightning:input",
             {"aura:ID" : 'fName',
              "name" : 'fName',
              "label" : 'First Name'}],
            ["lightning:input",
             {"aura:ID" : "lName",
              "name" : 'lName',
              "label" : 'Last Name'}],
            ["lightning:input",
             {"aura:ID" : 'mAddress',
              "name" : 'mAddress',
              "label" : 'Mailing Address'}]
        ],function(newDynDiv, status, errorMessage){
            if (status === "SUCCESS"){
                var target = component.find("conForm");
                var body = target.get("v.body");
                body.push(newDynDiv[0], newDynDiv[1], newDynDiv[2]);
                
                target.set("v.body", body); // working fine till here and components are getting added to desired location.
                
                       

           var fVal = component.find("fName").get(v.value); // This shows the error 'cannot read property get of undefined'

            }
            else if (status === "INCOMPLETE") {
                
                alert("No response from server or client is offline.")
                
                // Show offline error
                
            }
            
                else if (status === "ERROR") {
                    
                    alert("Error: " + errorMessage);
                    
                    // Show error message
                    
                }
            
        });

Can I have a variable, specifically a Map, that retains its value globally throughout all transactions until and unless it is modified through apex or flows or triggers?
On executing the following code, an error message pops up saying, 'System.ListException: Before Insert or Update list must not have two identically equal elements'


String n;
Account tempac = new Account();
List<Account> ac = new List<Account>();
for (Integer i = 0; i < 10; i++){
    n = 'TryAccount' + i;
    tempac.Name = n;
    ac.add(tempac);
    System.debug('Account Contect is::: ' +ac[i]); //Checkpoint 1
}

//System.debug('This is the result:::: ' +ac); // Checkpoint 2
insert ac;


Checkpoint 1 outputs value as expected i.e. TryAccount0, TryAccount1 and so on
But
Checkpoint 2 gives all identical valuses as the output i.e. TryAccount9, TryAccount9, TryAccount9, and so on.
On executing the following code, an error message pops up saying, 'System.ListException: Before Insert or Update list must not have two identically equal elements'


String n;
Account tempac = new Account();
List<Account> ac = new List<Account>();
for (Integer i = 0; i < 10; i++){
    n = 'TryAccount' + i;
    tempac.Name = n;
    ac.add(tempac);
    System.debug('Account Contect is::: ' +ac[i]); //Checkpoint 1
}

//System.debug('This is the result:::: ' +ac); // Checkpoint 2
insert ac;


Checkpoint 1 outputs value as expected i.e. TryAccount0, TryAccount1 and so on
But
Checkpoint 2 gives all identical valuses as the output i.e. TryAccount9, TryAccount9, TryAccount9, and so on.