Wednesday, 13 January 2021

Visualforce

 1. What is Visualforce?

Ans: Visualforce is a tag based Markup Language, it is used to design salesforce web pages.

*  We will go for visualforce page when there is requirement to extend the layout and whenever we want customize page for editing and creating records.

* Developers use visualforce to create a visualforce page definition, Page definition consists of two primary elements.

1.Visualforce Markup

     Visualforce Markup consists of  Visualforce Tags, HTML, Javascript, or any other web-enabled code embedded within a single <apex:page>  tag, the markup defines the user interface components that shuold be included on the page and the way they should appear.

2. Visualforce Controller

    Visualforce controller is a set of instructions that specify what happens when a user interacts with the components specified in associated markup, such as when user clicks on button or link.

2. What are types of controllers available in Visualforce?

  • Standard Controller
  • Standard List Controller
  • Standard Set Controller
  • Custom Controller
  • Extension Controller
3. What is Standard Controller?
Ans:  Standard Controller consists of the same functionality and logic that is used for a Standard Salesforce page. 
  • Functionalities like Save, Cancel, Edit, Delete and Quick Save
  • Standard Controller always defaultly works with User mode
  • We can define any sObject as Standard controller in Visualforce Page.
  • If we want to access the data from sObject we should give {!object.FieldName}
* To associate a Standard controller with a Visualforce Page, use StandardController on the <apex:page> tag
        
        <apex:page  StandardController = "Object API Name" >

4. What is Standard List Controller?
Ans:  Standard List Controller enables us to create visualforce page that can display or act on a set of records.
  •  Using Standard List Controller is similar to Standard controller
  • First define StandardController attribute on <apex:page>  tag and add one more attribute recordSetVar on the same tag.
            <apex:page  StandardController = "Account"   recordSetVar ="acc" >
  • We will go for pagination using this Standard List Controller
  • Pagination: It is the process of displaying large number of records and displaying the records on multiple pages within Salesforce. In order to control the number of records displayed on each page, we use pagination.
  • By default this list controller returns only 20 records on the page.
  • If we want customize this functionality then we will go for Extension controller
5. What is StandardSetController?
Ans: We can use standard set controllers provided by salesforce to implement paginaation in visualforce. It is very easy to implement pagination using standard set controller.
    We can navigate through pages, move directly to first, last page or to next or previous pages using standard set controller. We can also decide how many records should be displayed in every page.

Eg: Assume that we have 100 records and we need to display only 10 records per page. This can be achieved through pagination.
* Pagination can be done in two ways
  • Using StandardSetController
<apex:page StandardController = "Account"   recordSetVar = "acc" Extension = "AccountController">

</apex:page>

Class: public class AccountController{
           public AccountController(ApexPages.StandardSetController  controller){
             controller.setPageSize(10);
   }
}
  • Using Limit and Offset keywords in SOQL query.
    SELECT Id,Name FROM Account ORDER BY ASC LIMIT 10  OFFSET 1

Methods: First(),Last, Next, Previous, getListViewOptions(), getPageNumber(), getPageSize(), getRecords(), getResultSize(), setPageNumber(pageNumber), setPageSize(pageSize)

6. What is Custom Controller?
Ans: A custom controller is class written in apex  that implements all of the pages logic, without leveraging a standardController. If we define Custom controller, we can define new navigation elements or behaviour.
  • Custom Controller by default runs in System mode
  • We have setter and getter methods in apex class.
  • Set  : The set method is used to pass values from Visualforce page to the controller.
  • Get : The get method is used to pass data from Apex code to Visualforce page.
            <apex:page controller = "ContactController" >
            </apex:page>
 
7. What is Extension Controller?
Ans: A Extension Controller is a class written in Apex that is used to extend the functionality or overrides the behaviour in a Standard or Custom Controller such as Save, Edit, Delete etc.

8. What is View state?
Ans: In a Visualforce page, whenever we use form tag then view state will be created for the page.
  • All the variables which we use in controller/extension classes and expresssions which are declared on the page will occupy the space in view state.
  • Maximum size of view state is 175KB.
9. How to reduce View State?
Ans: 
  • Minimize number of forms in a page i.e <apex:form>
  • Declare variables as transiant to reduce view state
  • Use custom objects and custom settings to store large quantities to Read-Only data
  • Use SOQL to retrieve only the data that is needed to page
  • Refactor pages to make its view stateless 
10. What is difference between rendered, rerender, renderAs and contentType?
Ans:
  • rendered : It accepts true or false. If it is true then component will display on the page, if it is false then it won't display on the page.
  • rerender  : To refresh certain area of a page based on component id.
  • renderAs : Used in page tag, we can diaplay VF page in PDF format if we renderAs = "PDF".
  • contentType : Used in page tag, we can download VF page in MS Word/Excel etc. based on the input to contentType.

Sunday, 10 January 2021

Test Class

 1. What is Test Class in Salesforce?

Ans: A Test class is an Apex class that tests our logic written in apex class or in trigger. Actually test class ensures that our code is working as per our expectation or not.

  • After developing an apex class or apex trigger we should write the unit tests and ensure that we are able to execute atleast 75% of the lines of code.
  • When we are moving code from Sandbox to Production, if code coverage is less than 75% deployment will fail.
  • If we want to write a test class, the class must use @isTest annotation.
  • Inside test class we can have only  test methods.
  • The method should be annotated  with @isTest or testMethod keyword.
  • Test method always should be Static and return type is Void.
  • And Access modifier should be Private or Public 
Syntax: 
    @isTest
public class MyTestClass
  {

        @isTest
public static void method1()
                 {
                                            
                                              }
    }

2. What is @testSetup?

Ans: testSetup is used to create common test records that are available for all test methods in the class.

Let say we have dml operations like insert, update, delete. For every dml operation we need to create test data, instead of creating sample data for all dml operations we can create one sample data and that data should be kept in testSetup Method.

The data which is in testSetup Method can have access and used in all the test methods that are in test class.

If a test class contains a test setup method, the testing framework executes the test setup method first, before any test method in the class.

** If we want to create data to group of methods in Test class we use @testSetup.

3. What is @seeAllData?

Ans: By default test class cannot recognize the existing data in the database.

* If we mention @isTest(seeAllData=true) then test class can recognize the existing data in the database.

* When we need data from database in Test class then we will go for seeAllData=true.

4. What is the purpose of Test.startTest() and Test.stoptest()?

Ans: Test.startTest()  and Test.stopTest() maintains the fresh set of governer limits.

* Whenever we are trying to test asynchronous operations there is a possibility of  hitting governer limits. To resolve this issue we can use Test.startTest() and Test.stopTest() methods in Asynchronous operations

* Each method in test class is allowed to call Test.startTest() and Test.stopTest() only once.  

* To execute asynchronous methods synchronously we can call those methods from inside of  Test.startTest()  and  Test.stopTest().

5. What are assert statements?

Ans: To compare Actual Value and Expected Value we use assert statements.

* We need atleast one assert statement in a test class.

   Types of Assert Statements:

  • System.assert(condition, msg) : Asserts that the specified condition is true, If it is not error is returned that causes code execution to halt.
  • System.assertEquals(expected, actual, msg) : Assert that the first two arguments are the same. If they are not same then it throws error msg.
  • System.assertNotEquals(expected, actual, msg) : Assert that the first two arguments are different. If they are same then error msg is displayed.
6. What is the purose of @TestVisible?
Ans:  Sometimes in test classes we need to access a variable from Apex class, if it is Private we cannot access that variable for that we will replace private with public. For this reason we are compromising the security. 

   To avoid this before the private variables in apex class we can include @TestVisible so that even though varaiable is private we can access from the test class.  

@TestVisible private static Integer recordNumber = 1;


7. What is Test.isRunningTest()?

Ans: Sometimes we cannot specify certain if conditions for the apex class, in that situations we can add Test.isRunningTest() separated with OR condition.

Eg: if(condition || Test.isRunningTest())

  The Test.isRunningTest() method is used to identify, if  the piece of code is being executed from a Test class or from Trigger or Batch Job etc.   Returns true if the code being executed from test class otherwise returns false.

8. What is system.runAs()?

Ans: By default test class runs in System Mode. If we want to execute a piece of code in a certain user context then we can use System.runAs(UserInstance).

To avoid MIXED-DML-OPERATION  error we can include DML Statements inside of System.runAs(), still error persists keep DML statements inside of Test.startTest()  and Test.stopTest() methods. 

9. How to pass parameters in Test class?

Ans: ApexPages.currentPage().getParameters().put('parameterName', 'paramValue');

 We can put date Parameter in current page Like.

Date Var = date.ValueOf(System.Today());

ApexPages.CurrentPage().getParams().put('MyVar', Var);

10. How to cover constructor in test class?

Ans: Just create an Object for that class.

Eg: public class MyClass {

      public MyClass{

    }

}

Test Class: 

@isTest

private class MyTestClass{

 @isTest

private static void testMethod()

{

MyClass cls = new MyClass();

 }

}

11. What is Test.setPage?

Ans: Test.setPage()  method is used to set the context to current page, normally used for testing the visualforce controller in test classes.

12. What are considerations of TestClass?

  • Do not put(seeAllData=true) in test class otherwise, use it for exceptional cases.
  • Use @isTest at the top for all test classes.
  • Test in bulk, it can run for 200 records at once.
  • Avoid using hard coding Ids anywhere in test class or any Salesforce apex class.
  • Use System.runAs() method to test the functionality in user context.
  • Use System.assertEquals() to see our code has the expected outcomes.
  • Use Test.startTest() and Test.stopTest() statement to increase Governer Limits of our test code.



Friday, 8 January 2021

SOQL

1. What is SOQL?

Ans: SOQL stands for Salesforce Object Query Language.

  • SOQL is used to retrieve the data from Database.
  • It is syntactically  similar to SQL
  • We can write SOQL query in apex code or in Query editor( in Developer console).
  • We can retrieve data from single object or from multiple objects which are related to each other
  • We can have 100 SOQL queries per transaction.
  • We can retrieve 50000 records using SOQL query or queries.
        Syntax: SELECT 
                     FROM
                     WHERE
                     WITH
                     GROUP BY
                     HAVING 
                     ORDER BY
                     LIMIT
                     OFFSET
                     FOR{VIEW, UPDATE}

Parent to Child( Inner query )
 Whenever we writing query on Parent Object, we need child records that are associated with that parent then we go for inner query 
    Standard Objects:  
          SELECT Id,Name,(SELECT Id,Name FROM Contacts) FROM Account
              Account : Parent Object
              Contact  : Child Object
* Inside inner query we need to give relationship name. In the above example Contacts is the relationship name between Account and Contact.

  Custom Objeccts: 
  SELECT Id,Name,(SELECT Id,Name FROM Student1__r) FROM Company__c;
        Company__c : Parent Object
         Student__c    :  Child Object
         Relationship name between this Objects Student1. 
        For Custom Objects we need to append with __r.
        i.e Student1__r.(Child relationship name __r).

Child to Parent
  When we are writing query on child object, but  we also need parent of that child record means then we go for Child to Parent Query.
 
Standard Objects:
 SELECT Id,Name,Account.Name,Account.Active__c FROM Contact;
            Contact: Child Object
            Account : Parent Object
We can query parent record fields with .(dot) notation

Custom Objects:
SELECT Id,Name,Company__r.Name,Company__r.Active__c FROM Student__c;
            Company__c : Parent Object
            Student__c    : Child Object
* for custom objects we need to use Parent__r.FieldName 

Note: When we are writing a query from child to parent, relationship name will be Master-Detail Field Name or Lookup Field Name.

Queries can be executed in formats like:
  • List<Sobject> result = [query statements];
  • List<sObject> result = Database.getQueryLocator
  • Database.QueryLocator  result = Database.getQueryLocator(query Statement);
  • Map<Id,sObject> result = new Map<Id,sObject>([query statement]);
Date Literals(Keywords) in Salesforce
    DATE and TIME  keywords

    TODAY, YESTERDAY,  THIS_WEEK,  NEXT_WEEK,  LAST_WEEK
    LAST_N_WEEK:N,   NEXT_N_WEEK:N

    DATE and TIME methods 
    calender_month()
    calender_quarter()
    calender_year()
    Day_month()
    Day_week()

Query Examples:

1. Write a query to fetch Accounts that do not have any Contacts?

Ans: [SELECT  Id,Name FROM Account WHERE  Id  NOT  IN(SELECT AccountId FROM Contact)];

2. Write a query to fetch Accounts that have atleast one Contact?

Ans:[SELECT  Id,Name FROM Account WHERE  Id  IN(SELECT AccountId FROM Contact)];

3. There is a Queue with name MyQueue. How to query it using SOQL from the database?

Ans: Queues will store in Group Object. To query for MyQueue from the database using SOQL, we should use the following syntax.
Group grp=[SELECT Id,Name FROM Group WHERE Name='MyQueue' and  Type='Queue' LIMIT 1];

4. How to query deleted records in Salesforce?

Ans: We can query deleted records using   isDeleted=TRUE and ALLROWS. 
List<Account> acc=[SELECT Id,Name,IsDeleted  FROM Account  WHERE  IsDeleted=TRUE];

5. Write SOQL to fetch  from 5th osition  Account records from 10 records.
Ans:
  List<Account> accs=[SELECT  Id,Name, FROM  Account  LIMIT 10  OFFSET 5];

6.Write a SOQL query to fetch last or recently  10 Accounts created.
Ans:
 List<Account> accounts=[SELECT Id,Name FROM Account  ORDER BY  DESC  LIMIT 10 ];

7. Write a SOQL query to fetch all those opportunities whose Stageame is prospecting and amount is greater han 50000?
Ans:
  List<Opportunity> opp=[SELECT Id,Name,Stagename,Amount FROM Opportunity WHERE Stagename='Prospecting'  AND Amount>50000]; 

8. How can you lock records in apex code using SOQL?
Ans:
    List<Account> accounts=[SELECT Id,Name FROM Account LIMIT 2 FOR UPDATE];
* The above query can lock the records.
Note: FOR UPDATE will be used only in Apex classes and Triggers.
   
Like clause in soql?
Ans: Like cluase is used to compare the string values or used to search for the string value in the given fields.
           '%'  it is used for any number of characters
           '_'    it is used for only one character

9. Write a query to fetch all the accounts whose name starts with United?
Ans:
      SELECT Id,Name,Phone FROM Account WHERE Name Like 'United%'

10. Write a query to fetch Accounts with corresponding contacts whose phone number is 12345?
Ans:
   List<Account> accList=[SELECT Id,Name,(SELECT Id,LastName,Phone  FROM Contacts WHERE Phone=12345) FROM Account];

11. Write a SOQL Quey to fetch the Leads whose Record type as Partner
Ans:
List<Lead> leads= [SELECT  Id, Name,RecordType FROM Lead WHERE RecordType.Name='Partner'];

12. How to use multi select picklist field in SOQL?
Ans:
  SELECT Id, Name FROM Account WHERE msFieldName  includes('AA', 'BBB', 'CCCC')
  

Sunday, 27 December 2020

Apex


1.What is Apex?

Ans: Apex is a Strongly typed, object - oriented programming language. Apex works like a database scripts and stored procedures. The syntax of Apex looks like Java. Java is case sensitive but Apex is not case sensitive

  • A Stored procedure is used to retrieve data, modify data, and delete data in database table. We don't need to write a whole SQL command each time you want to insert, update or delete in an SQL Database. A stored procedure is a precompiled set of one or more SQL statements which perform specific task.
  • Apex enables us to write custom business logic to most system events, including button clicks, related record updates, and visualforce pages.  
  • Data types in Apex: Integer, Decimal, Double, Long, Date, DateTime, Boolean, String, Blob, sObject, Object.
  • Apex provides built in support for 
    • DML calls to insert, update, delete a record.
    • Inline SOQL or SOSL statements for retrieving records.
    • Looping control structures that help with bulk processing.
  • Object-Oriented Programming: It is a methodology or paradigm to design a program using Classes and Objects.
  • Object: An Object can be defined as an instance of a class
    • Object means a real time entity which has some characteristics, based on that characters we say what type of object it is.
    • Example: Our PC. It has Keyboard, Screen, Touchpad based on these characters only we can say it is PC.
  • Class: Collection of Objects, Methods, Variables, Constructors and Blocks is called class.
2. How to create Apex class?
Ans: 
            Syntax: public class className{
                                             variables;
                                             constructors;
                                              Methods;
                                }   
        How to create an Object for class
                className objectNmae = new className();      

3. What is a Variable?
Ans:  A variable is a name given to a memory location. It is the basic unit of storage in a program. The value stored in a variable can be changed during program execution.
    Variable Declaration Syntax: 
                          AccessModifier Datatype VariableName = defaultValue(optional);
  • Local Variable :  A variable defined with in a block or method or constructor is called local variable.    
  • Instance Variable: The variables declared inside the class are called Instance variables. This varaiables can be accessed anywhere in the class.
    • If we want access Instance variables outside the class we have to use Object notation. ObjectName.VariableName
  • Static Variable : A variable declared with static keyword are called Static variables.
    • Static variables or methods can be accessed using ClassName only ClassName.Variable or MethodName.
4. What is Access Modifier?
Ans: Access Modifier specifies the accessbility or scope of a Variable, Field, Method, Constructor or Class.
            Types of Access Modifiers
    • Private
    • Public
    • Protected
    • Global
    • Web Service                                                                                                                    

5. What is Method?

Ans:  A Method is a group of statements which are written in a sequential order to perform a specific task.

  • A Method can return some value or return nothing
  • A Method can be declared inside the class only.
  • Syntax : AccessModifier ReturnType MethodName()
    • Eg: public Integer add()
Types of Methods
  1. Instance Method: Methods which are declared Inside clas  are called Instance Methods. These methods can be accessed through object only. Private methods can be accessed inside the class without any object.
  2. Static Method: Methods which are declared with Static keyword are called Static Methods.
  3. Virtual Method: The methods which are declared with Virtual keyword are called virtual methods.
                    public virtual class virtualParentClass{
                                public void add(Integer a, Integer b){
                                    
                                 }
                                public void sub(Integer c, Integer d){
                                                      
                                 }
                      }
 * If we want override a virtual class we must use keyword extends.
 
                            public  class  virtualChildClass  extends  virtualParentClass {
                                      
                                 }    
The child class doesn't have any methods but, when we use extends all the methods which are declared      in Parent class  indirectly comes into exending class(ChildClass).
*  If the method is declared as private, it will not come into ChildClass.
*  If we want to override any method, that method should be declared with keyword Virtual
              public  virtual  Integer  add(Integer  a,  Integer  b)
          If we do not mention virtual keyword that method cannot be overridden.
*  In ChildClass we must use override keyword if we want to override.
              public  override Integer add(Integer  a,  Integer  b)
In virtual methods overriding is optional(If we want we can override otherwise we cannot.)

        4. Abstract Method: If we want to declare a Abstract class we must use keyword Abstract.
             * Abstract methods should not have any body, but we can declare our methods.
              * In virtual class overriding is optional, but in Abstract class if we declare any method we must                   and should override that method. 
              * Let say we have declared 3 methods and overriding only 2 methods then it throws error. All                       the 3 methods must override.
*Method overloading: If one method is implemented more than once with same name and different        arguments and different return types then it is overloading.

6. What is Constructor?
Ans: Constructor is like method which is used to perform task while creating an object. It is used to create an Object.
  • Constructor name should be same as ClassName.
  • Constructor should not return any datatype even void also. 
  • If constructor declared as Private, Object cannot be created outside the class.
  • Every class has it's own default constructor.
  • Syntax : AccessModifier  className(parameter)
  • THIS keyword: It is used inside the constructor to access the same calss instance variables and also used to call one method from other.
7. What are Collections in Salesforce?
Ans: Collection is a group of elements which stores data into a single variable. We have three types of collections.
  • List
  • Set
  • Map

        


Monday, 7 December 2020

Architecture

 1.What is the architecture of  Salesforce and Salesforce Lightning?

Ans: Salesforce follows MVC(Model, View, Controller) architecture, here

    • Model  means, Where we can store data. In Salesofrce for storing data we have Objects, Custom settings and Custom Metadata types.
    • View means, How the information is displayed to the user. We have PageLayouts, Visualforce Pages, Lightning Page and Lightning web pages.
    • Controller means, How the data is going to process, We have workflows, Process Builder, Apex and Triggers.
Salesforce Architecture


* Salesforce Lightning follows MVCC architecture

    Salesforce Lightning Platform is for building an interactive user experience. We can build highly interactive and fast response user interfaces with this new platform.
    • Model, View, Controller, Controller
    • Controller: One controller is javaScript controller(Client side) to communicate with view.
    • Controller: Another controller is Apex controller(Server side) to communicate with model.
Lightning architecture


2.What is the difference between C in component and C in the controller?
Ans: If C is used in the component then it is used to call the controller action. In simple we can say action provider in Component.

        If C is used in the controller means, it is calling Apex Method(Calling Server side action).

3. How to call Apex  class method(Server side action) from javascript controller in Lightning?
Ans: If we want to call apex method from javascript controller, 
    • The component should have controller="Apex class name".
    • The Apex class method should be annotated with @AuraEnabled
    • Method should be Public, Static and Return type should be anything like string, List, sObject etc.
    In javascript we can call Apex method as
                 var action = component.get("c.Apex class Method name");
   * To set data to be passed to the server-side controller we use                                                                                               action.setParams({});

   * We have action.setCallback() that sets a callback action that is invoked after the server-side action returns
            action.setCallback(this, function(response){.....});
* The server- side action results are available in the response variable.
    • response.getState() gets the state of the action returned from the server.
    • response.getReturnValue() gets the value returned from the server.
* $A.enqueueAction(action) adds the server-side controller action to the queue of actions to be executed.

4. Explain about Component Bundle?
Ans: The Component Bundle Contains resources like

  • Component (.cmp) 
    • It contains the markup, aura tags for the component
    • It is the only required resource in the bundle
    • Each bundle contains only one component
  • Controller (.js)
    • Controller is used to handle client side events in Component.
    • Controller is a resource in a component bundle that holds the action handlers for that Component and action handlers are just Javascript functions with a particular functions
  • Helper(.js)
    • It contains javascript to handle the logic.
    • We can not call helper directly from Component. Helper can be called from Controller.
    • In Helper we can call the functions that are defined in the controller.
    • We can call helper functions by RENDERER resource, but RENDERER can not call the functons that are defined in the controller.
  • Style(.css)
    • Contains styles for the Component
  • Documentation(.auradoc)
    •  Documentation includes description and example to demonstrate the use of component.
    • Let's we have created a Registration component, If we prepare a document for this component then we can view the entire details of the component  in the documentation.
  • Renderer(.js)
    • Renderer  resource in Lightning component bundle modify the DOM elements which is created by framework for a component. We use custom renderer to change or override the default rendering behaviour of the component.
  • Design
    • File required for components used in Lightning App Builder, Lightning Pages, Community Builder, or Flow Builder can have in design
  • SVG(.svg)
    • It is a custom resource for components that get displayed before the component name in lightning app builder or community builder.

5. What are the methods that we can access to a renderer file in an aura component?
Ans: We can access to 4 methods that are render, rerender, afterRender, unrender

6.What is Aura method?
Ans: <aura:method> enables us to directly to call a method in Child component client-side controller(i.e javascript) from Parent component instead of firing and handling Component Event.

<aura:method  name="   " action="{!c.actionName}"  access="Public"  description=" "/>
    •  name= The method name. Use the method name to call the method in JavaScript code
    • action=  The client-side controller action to execute  
*  An aura method can optionally include parameters. Use an aura:attribute tag within an aura:method to declare parameter for the method.

*  To retrive the arguments we use event.getParam('arguments'). It returns an object if there are arguments or an empty array if there are no arguments. 







                                                                    
   
   
.


        










Sunday, 6 December 2020

Events in Lightning


1. What are Events in Lightning? 

Ans: In Lightning we have Events like System Events, Application Events, Component Events

* Events are used to communicate between the components.

* In Lightning framework, to setup communication between components we make use of Lightning Events.

* If Lightning component has to communicate to the upper level in it's hierarchy i.e to it's parent or grand parent or great grand parent then we use Component Events.

* In Component Events communication has to be done to it's higher hierarchy.

* In Component Event we have two phases 

    • Capture Phase: It starts from Application root and ends with Source Component.
    • Bubble Phase:  It starts from Source Component and moves to Apllication root.

Steps for Component Event

  1. First we have to Register the Event.
            How to Register an Event
               <aura:registerEvent   name="Name of registration"  
                                                    type="c:componentEventName" />
      2.Fire the Event
            For Firing we need to follow steps
    1. Get a Reference to Component Event, by using                                                                               Var cmpEvt= component.getEvent("here we have to pass name of registerEvent");
    2. Set the attribute values using                                                               cmpEvent.setParams([]);
    3. Fire the Event using                                                                                                                      cmpEvent.fire();                                                                                                      

     3.Handle the Event (Based on the Event, decide which component should handle it. Source component can also handles the Event if we want)
<aura:handler name="name is registerEvent name "   event="c:Name of event"  action="{! action while you handling}"   phase="capture" />
* The name of <aura:handler> must match the name of <aura:registerEvent>
    •  By default it should be in bubble phase.
In handler controller read the attribute value that is defined in Component Event using, event.getParam

event.getSource(): It helps to determine which component fired an event. Let us say we have several buttons(New, Edit, Delete) that reuse the same onclick handler. To know which button has fired the event we use getSource.
    event.getSource().get("v.name").
event.pause(), event.resume(): To pause and resume the events we use this functions.
event.stopPropagation(): To stop event propagation.

                                                                 Events in Lightning.

* If we want send the information from Parent to Child component we use Attributes 
* If we want send information from Child to Parent component we use Events.

  • Application Event : Application events are used when you need two independent component to communicate with each other i.e they don't need to be in the hierarchy or nested with each other.Applicaton events are handled by all components that are listening to the event
  1.  How to define Application Event
        <aura:event type="APPLICATION">

  • How to Register Event
            <aura:registerEvent name="Name of register event" type="AppEvent Name" />
  • How to get application event in controller                                                                                                   var appEvt = $A.get("e.c:name of app event");
  • Fire the Event using appEvt.fire();
  • Handling the AppEvent
       <aura:handler name="c:AppEvent name"   action="{!c.action to perform when handling}"/>

  • System Events: System Events are fired automatically by the lightning framework such as during component initialization, attribute value change, rendering etc.                                                            
    • aura:valueRender     Indicates that an app or component has been rendered or rerendered
    • aura:valueInit            Indicates that an app or component has been initialized.
    • aura:valueDestroy    Indicates that component has been destroyed
    • aura:valueChange     Indicates that an attribute value has changed
    • aura:systemError      Indicates that an error has occured.

Friday, 13 November 2020

Governer Limits

 

1. What are Governer limits in Salesforce?

Ans: Salesforce has governer limits to assure the practical usage of resources present in the Force.com platform. To use the code effectively, salesforce establishes some limits, and they are known as Governer Limits.

DescriptionSynchronous LimitAsynchronous Limit
Total number of SOQL queries issued1100200
Total number of records retrieved by SOQL queries50,000
Total number of records retrieved by Database.getQueryLocator10,000
Total number of SOSL queries issued20
Total number of records retrieved by a single SOSL query2,000
Total number of DML statements issued2150
Total number of records processed as a result of DML statementsApproval.process, or database.emptyRecycleBin10,000
Total stack depth for any Apex invocation that recursively fires triggers due to insertupdate, or delete statements316
Total number of callouts (HTTP requests or web services calls) in a transaction100
Maximum cumulative timeout for all callouts (HTTP requests or Web services calls) in a transaction120 seconds
Maximum number of methods with the future annotation allowed per Apex invocation500 in batch and future contexts; 1 in queueable context
Maximum number of Apex jobs added to the queue with System.enqueueJob501
Total number of sendEmail methods allowed10
Total heap size46 MB12 MB
Maximum CPU time on the Salesforce servers510,000 milliseconds60,000 milliseconds
Maximum execution time for each Apex transaction10 minutes
Maximum number of push notification method calls allowed per Apex transaction10
Maximum number of push notifications that can be sent in each push notification method call2,000
Maximum number of EventBus.publish calls for events configured to publish immediately150

2. Object limit in Salesforce?
Ans:
   Saleforce edition                    Custom fields per Object               Total Custom Objects
   Group Edition                                       100                                                                      50
   Professional Edition                             100                                                                      50
   Enterprise Edition                                500                                                                      200
   Unlimited Edition                                 500                                                                      2000

  • Active Lookup Filters      : 5
  • Active Validation Rules   : 100
  • Active Workflow Rules   :  50
  • Approval Process            : 500
  • Custom Fields                  : 500
  • Custom Relationship Fields  : 40
  • Rollup Summary Fields   :  25
  • Sharing Rules(Both Owner - and Criteria - based) : 300
  • Sharing Rules(Criteria - based Only) : 50
  • Total Workflow Rules : 500
  • VLOOKUP Functions : 10
  


3. How to get current logged in UserId in Salesforce?
Ans:   In Formula fields use $user.Id.
          In Apex use UserInfo.getUserId().
          In Visualforce Pages use:  {!$user.Id}
          In Lightning use:  $A.get("$SobjectType.CurrentUser.Id");