2

I have just started learning Lightning through trail head and have completed a basic Lightning component creation task but I am failing to understand as to how are the things working here. As I have started working on salesforce right from the beginning of my IT career, I know nothing about various JS frameworks.Thus, I looking for someone who can help me understand as to how are the things interacting in below code...

  1. Apex Controller Class ( MyContactListController.apxc )
public class MyContactListController {
 @AuraEnabled
 public static List<Contact> getContacts() {
     return [Select Id, Name, Email, Title, Phone From Contact];
 }
}

2.Lightning Component ( MyContactList.cmp )

<aura:component controller="MyContactListController">
 <aura:handler name="init" action="{!c.myAction}" value="{!this}" />
 <aura:attribute name="contacts" type="Contact[]" />

 <ul>
 <aura:iteration items="{!v.contacts}" var="contact">
 <li class="minli"> <h3>{!contact.Name}</h3> </li>
 </aura:iteration>
 </ul> 
</aura:component>

aura:handler name="init" action="{!c.myAction}" value="{!this}"

1. What is this here ?
2. Is 'init' a keyword ? If, so what does it do ? What are the other 
   keywords and there functionality ?

3.Lightning Controller( MyContactListController.js )

({
myAction : function(component, event, helper) {
    var action = component.get("c.getContacts");
    action.setCallback(this, function(data) {
    component.set("v.contacts", data.getReturnValue());
    });
    $A.enqueueAction(action);

}})

Although I will be happy to receive any kind of information on these, below are the few questions for which I am really very much desperate to find answers.

myAction : function(component, event, helper)

  A. What are these parameters?  
  B. What do they do ? 
  C. Are all/some of  these mandatory ? 
  D. How many other parameters can be passed in function ? 
  E. Where may I find the general definition of this function ? 

var action = component.get("c.getContacts");

 A. What is happening here ? - I presume that method from apex controller is
    getting called. If my understanding is right, 
 B. Where is the definition for 'c' here in c.getContacts ? - Is 'c' a 
    Keyword here ? If yes, so we mean that c will always link to controller 
    and we cannot declare a variable as c ? 
 C. Wouldn't action variable have all the values/records required? If so, 
    what is the purpose for writing further lines of code below this line ?

action.setCallback(this, function(data) { component.set("v.contacts", data.getReturnValue()); });

    1. What is this *setCallback* used for, when we already have all the
       values at var action ?
    2. What is *Data* here, where is it coming from and what does it what 
       does it holds(controller method's return) ?
    3. What does 'v' in *v.contacts* stands for ? If that is also keyword, 
       what are the other key words like such?

Any other information or source is equally appreciated.

closed as too broad by Mohith Shrivastava, Santanu Boral, Tushar Sharma, Ratan Paul, Martin Lezer May 12 '17 at 6:59

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • If you haven't already, I suggest you work through these Lightning Components Basics training modules. They are designed to guide you through these concepts. – Keith C May 11 '17 at 8:53
  • 5
    This is really too big to be one question. Consider breaking this question up in to multiple pieces. You'll get more concise answers that way. – sfdcfox May 11 '17 at 14:52
  • Hi @KeithC , I am starting on the exercise you suggested today, will ask if I still do not get the answer. – Rajeev May 12 '17 at 5:55
  • Hi @sfdcfox, yes you are right but all these questions are inter-related and having post them at once will not just help me understand the interaction well but will also be a good source for future lightening developers as well. Thus, I hope these are the minimum questions which could be answered to understand the very basic program. However one can choose to answer any number of questions asked. Answering all is not mandatory here. :) You would be doing a great answer even if you answer one out of all these. Thank you – Rajeev May 12 '17 at 5:58