Posts

Showing posts from August 16, 2019

Trigger Most Common Interview Questions and Answers for MNCs and Small-Mid Companies

Image
***  Trigger Most Common Interview Questions and Answers for MNCs and Small-Mid Companies  *** Salesforce Trigger How is Trigger. New Different from Trigger.newMap? Ans:-  Trigger. New variable returns the list of sObject which has invoked the trigger and Trigger.NewMap returns the map of ids with the newly entered records. NewMap is only available in after insert, before and after the update and after undelete. Difference between Trigger.new different from Trigger.old? Ans:-  Trigger. New variable returns the list of sObject which has invoked the trigger and Trigger.old returns a list of the older versions of the records which have invoked the trigger. Trigger.Old is only available in update and deletes events What is a Trigger? Ans:  Trigger   😇⇍ Click This Link What is Trigger Syntax? Ans:  Trigger Syntax   😇⇍ Click This Link What are the various event on which a trigger can fire? Ans:  Trigger Event   😇⇍ Click

Trigger best practices

Best Practices of Trigger   1. One Trigger Per Object:-    A single Apex Trigger is all you need for one particular object. If you develop multiple Triggers for a single object, you have no way of controlling the order of execution if those Triggers can run in the same contexts 2. Logic-less Trigger:-    If you write methods in your Triggers, those can’t be exposed for test purposes. You also can’t expose logic to be re-used anywhere else in your org. 3. Context-Specific Handler Method:-     Create context-specific handler methods in Trigger handlers 4. Bulkify Codes:-    Bulkifying Apex code refers to the concept of making sure the code properly handles more than one record at a time. 5. Avoid SOQL Queries or DML statements inside FOR Loop:-     An individual Apex request gets a maximum of 100 SOQL queries before exceeding that governor limit. So if this trigger is invoked by a batch of more than 100 Account records, the governor limit will throw a runtime exception 6.

Order of execution in Triggers

Order of execution in Triggers The record is loaded from the database or is initialized in case of an upset statement. New record’s field values are overwriting the old values, now depending on the origin of the request this flow varies: if the request is from a UI page then the following validations are performed by Salesforce: Any layout specific rules are checked All the required values are checked at layout and field level All the field formats are validated along with the maximum length of field values If the request originates other than UI then Salesforce only checks for Validation of foreign keys. Before triggers are executed at the database. Most of the validations are performed again to verify that all the required fields are holding some values and are not null, at this step user-defined validations are also executed and the only validation which is not repeated in this step are the rules specific to the layout. After the success of the previous step, t

What is a Trigger?

Trigger Definition A trigger is  piece  codes  that occur before or after a record is inserted or update on database.  triggers are  Use  to perform tasks that can’t be done by using the point-and-click tools in the Salesforce user interface. For example, if validating a field value or updating a field on a record, use validation rules and workflow rules instead. *** Trigger Most Common Interview Questions and Answers for MNCs and Small-Mid Companies *** Visualforce Most Common Interview Questions and Answers for MNCs and Small-Mid Companies  ⇒  *** Comming Soon *** Apex Most Common Interview Questions and Answers for MNCs and Small-Mid Companies  ⇒ *** Comming Soon *** Lightning Component Most Common Interview Questions and Answers for MNCs and Small-Mid Companies  ⇒  *** Comming Soon *** Lightning Design System  Most Common Interview Questions and Answers for MNCs and Small-Mid Companies  ⇒  *** Comming Soon *** Freelancing Services  At

Trigger Syntax

Syntax of a Trigger  trigger TriggerName on ObjectName (Trigger_Events) {          // Your Code }         ---------------------------------------------------------------- * After Insert Trigger Syntax: trigger TriggerName on ObjectName (After Insert) {          // Your Code } * Before Insert Trigger Syntax: trigger TriggerName on ObjectName (Before Insert) {          // Your Code } * After Upadte Trigger Syntax: trigger TriggerName on ObjectName (After Update) {          // Your Code } * Before Update Trigger Syntax: trigger TriggerName on ObjectName (Before Update) {          // Your Code } * Before Delete Trigger Syntax: trigger TriggerName on ObjectName (Before Delete) {          // Your Code } * After Delete Trigger Syntax: trigger TriggerName on ObjectName (After Delete) {          // Your Code } * After Undelete Trigger Syntax: trigger TriggerName on ObjectN

Considerations while implementing a Trigger

Considerations while implementing a Trigger * Upsert trigger fires on 4 different events:- before(insert, update), after (insert, update) ** Merge trigger is fired on both events on delete *** Field history is updated after the trigger has successfully finished processing data. **** Any callout should be asynchronous so that trigger does not have to wait for the response. ***** A trigger cannot have a static keyword in its code. ****** If a trigger completes successfully the changes are committed to the database and if it fails                                                                                                         the transaction is rolled back. *** Trigger Most Common Interview Questions and Answers for MNCs and Small-Mid Companies *** Visualforce Most Common Interview Questions and Answers for MNCs and Small-Mid Companies  ⇒  *** Comming Soon *** Apex Most Common Interview Questions and Answers for MNCs and Small-Mid Companies  ⇒ *** Com

Context variables in triggers

Context variables in triggers At Trigger we have 12 types of context variables that fire on the trigger: IsInsert :- Returns  true  if this trigger was fired due to an insert operation, from the Salesforce user interface, Apex, or the API. IsUpdate :- Returns  true  if this trigger was fired due to an update operation, from the Salesforce user interface, Apex, or the API. IsDelete :- Returns  true  if this trigger was fired due to a delete operation, from the Salesforce user interface, Apex, or the API. IsBefore :- Returns  true  if this trigger was fired before any record was saved. IsAfter :- Returns  true  if this trigger was fired after all records were saved. IsUndelete :- Returns true  if this trigger was fired after a record is recovered from the Recycle Bin. New :- Returns a list of the new versions of the sObject records. This sObject list is only available in insert, update, and undelete triggers, and the records can only be mod

Type of Triggers

Type of Triggers   Two-type of triggers:- * Before triggers:-    used to perform a task before a record is inserted or updated or deleted. These are used to update or validate record values before they are saved into the database. *  After triggers:-  used to perform a task after a record is inserted or updated. The records that fire at  after trigger  is read-only. *** Trigger Most Common Interview Questions and Answers for MNCs and Small-Mid Companies *** Visualforce Most Common Interview Questions and Answers for MNCs and Small-Mid Companies  ⇒  *** Comming Soon *** Apex Most Common Interview Questions and Answers for MNCs and Small-Mid Companies  ⇒ *** Comming Soon *** Lightning Component Most Common Interview Questions and Answers for MNCs and Small-Mid Companies  ⇒  *** Comming Soon *** Lightning Design System  Most Common Interview Questions and Answers for MNCs and Small-Mid Companies  ⇒  *** Comming Soon *** Freelancing Services  At

Various event on a trigger

Various event on which a trigger A trigger is a set of a statement which can be executed on the following events. In the above trigger events, one or more of below events can be used with comma-separated. * Before Insert:- Return true is trigger is fire for Before and Insert operation. * Before Update:- Return true is trigger is fire for Before and Update operation. * Before Delete:- Return true is trigger is fire for Before and Delete operation. * After Insert:- Return true is trigger is fire for After and Insert operation. * After Update:- Return true is trigger is fire for After and update operation. * After Delete:- Return true is trigger is fire for After and delete operation. * After Un-delete:- Return true is trigger is fire for After and Undelete operation. *** Trigger Most Common Interview Questions and Answers for MNCs and Small-Mid Companies *** Visualforce Most Common Interview Questions and Answers for MNCs and Small-Mid Compa

Undelete Trigger on Case

Undelete Trigger on Case Undelete Trigger Class: trigger unDeleteCase on Case (after undelete) { if( trigger.isundelete){ list<Case> casesUnDeletedList = new list<Case>(); casesUnDeletedList = [SELECT id,After_Undelete__c FROM Case WHERE Id IN :trigger.newmap.keyset()]; for(Case c :casesUnDeletedList) { c.After_Undelete__c = true; } update casesUnDeleted; } } *** Trigger Most Common Interview Questions and Answers for MNCs and Small-Mid Companies *** Visualforce Most Common Interview Questions and Answers for MNCs and Small-Mid Companies  ⇒  *** Comming Soon *** Apex Most Common Interview Questions and Answers for MNCs and Small-Mid Companies  ⇒ *** Comming Soon *** Lightning Component Most Common Interview Questions and Answers for MNCs and Small-Mid Companies  ⇒  *** Comming Soon *** Lightning Design System  Most Common Intervi

Trigger Upsert Contact record using trigger when account record is updated

Trigger Upsert Contact record using trigger when account record is updated Upsert Trigger Class: trigger upsert Contact on Account (after update, before update, after insert, before insert){    List<Contact> contactList = new List<Contact>();    List<Contact> contactList1 = new List<Contact>();    for(Account acc: [SELECT Id,(SELECT Id,checkbox__c FROM Contacts) FROM Account                                                               WHERE Id in: Trigger.new]){    If(acc.Contacts.size()>0){      contactList.addAll(acc.Contacts);       }   }    for(contact c:contactList){           c.checkbox__c= false;           contactList1.add(c);    }    try{    Upsert contactList1; }catch(Exception e){     system.debug('e');   } } *** Trigger Most Common Interview Questions and Answers for MNCs and Small-Mid Companies *** Visualforce Most Common Interview Questions and Answ

Trigger Update Contact record using trigger when account record is updated

Trigger  Update Contact  record using trigger  when account record is updated  Trigger Class: trigger updateContact on Account (after update, before update){    List<Contact> contactList = new List<Contact>();    List<Contact> contactList1 = new List<Contact>(); for(Account acc: [SELECT Id,(SELECT Id,checkbox__c FROM Contacts) FROM Account WHERE Id in: Trigger.new]){    If(acc.Contacts.size()>0){      contactList.addAll(acc.Contacts);     } } for(contact c:contactList){         c.checkbox__c=true;         contactList1.add(c); } try{ update contactList1; }catch(Exception e){ system.debug('e'); } } *** Trigger Most Common Interview Questions and Answers for MNCs and Small-Mid Companies *** Trigger Upsert Contact record using trigger when account record is updated Upsert Trigger Class: trigger upsert Contact on Account (after update, before update, after insert, before in