Deprecated: Optional parameter $list declared before required parameter $is_script is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php on line 21

Deprecated: Optional parameter $register declared before required parameter $footer_or_media is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php on line 45

Deprecated: Optional parameter $register declared before required parameter $footer_or_media is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php on line 104

Deprecated: Optional parameter $expire declared before required parameter $path is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_functions.php on line 54

Deprecated: Optional parameter $depth declared before required parameter $output is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/themes/entaro/inc/classes/megamenu.php on line 155

Deprecated: Optional parameter $depth declared before required parameter $output is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/themes/entaro/inc/classes/mobilemenu.php on line 147

Deprecated: Optional parameter $args declared before required parameter $wp_customize is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 583

Deprecated: Optional parameter $args declared before required parameter $wp_customize is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 606

Warning: Cannot modify header information - headers already sent by (output started at /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php:21) in /home1/oijoiv2f/public_html/wp-includes/feed-rss2.php on line 8
Trigger Archives - Salesforce Next Gen https://salesforcenextgen.com/tag/trigger/ Trailhead and Beyond Mon, 28 Dec 2020 19:46:19 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.3 https://salesforcenextgen.com/wp-content/uploads/2020/10/cropped-76dc0dd6-326a-4956-a412-bfdf20c7fb23_200x200-32x32.png Trigger Archives - Salesforce Next Gen https://salesforcenextgen.com/tag/trigger/ 32 32 Writing a Simple Apex Trigger !! https://salesforcenextgen.com/writing-simple-apex-trigger/ https://salesforcenextgen.com/writing-simple-apex-trigger/#comments Wed, 02 Aug 2017 10:26:56 +0000 http://www.salesforcenextgen.com/?p=885 Writing a Simple Apex Trigger !! Now we know where to write a Trigger, let’s begin with a simple example. In this scenario I would like to add a custom text in the last name of a contact. Let’s have a look at the basic structure of a trigger trigger MyCustomTriggerName on CustomObject__c (trigger_events) { …
Continue reading Writing a Simple Apex Trigger !!

The post Writing a Simple Apex Trigger !! appeared first on Salesforce Next Gen.

]]>
Writing a Simple Apex Trigger !!

Now we know where to write a Trigger, let’s begin with a simple example. In this scenario I would like to add a custom text in the last name of a contact.

Let’s have a look at the basic structure of a trigger

trigger MyCustomTriggerName on CustomObject__c (trigger_events) {

Line of codes to execute(Business Logic)

}

Using the above-mentioned structure we will write our code, in the above code we can give Trigger any name we want, and since we want the trigger to be on contact standard object, the structure of trigger looks like below

trigger ContactTestTrigger on contact (before insert) {

Line of codes to execute(Business Logic)

}

Now that we have defined the basic structure of the trigger now we will write the business logic as discussed in the beginning.

trigger ContactTestTrigger on contact (before insert) {

for(contact con : Trigger.new){

con.lastname  = ‘New Last Name using Trigger’;

}

}

Simple Apex Trigger

This is it, we have written a simple Trigger which initiates at before insert event of a contact. Based on the occurrence of the DML event, there are broadly two types of Triggers; Before Trigger and After Trigger. Further, the trigger can be classified into the below groups based on the events.

  1. Before insert, after insert.
  2. Before update, after update.
  3. Before delete, after delete.
  4. Before undelete.

In Trigger, we can modify the data without explicitly calling any DML operation, and if the operation is performed then it results in an error. The record is committed to the database once the trigger has completed its execution

Here you also see the use of a variable Trigger.new in the for loop, it is a trigger’s context variable.  Trigger’s context variable holds the values of the record which initiated the execution of the trigger, for e.g. Trigger.New contains the list of contacts which initiated the trigger. There are some Trigger’s context variables which return Boolean values and with the help of context variables, we can determine which event fired the trigger. There are many context variable available in Salesforce and can be studied in detail here.

This concludes how to write a Simple Trigger

Next, I would like to present, how to call apex class method in trigger, callout, and using trigger exceptions

find interview Questions on Trigger here

Interview Questions Apex Trigger

Also, Have a look at the below learning resources:

  1. SOQL (Salesforce Object Query Language)

  2. Apex Trigger Best Practices and the Trigger Framework

  3. Salesforce Interview Question and Answers Part 2

  4. Salesforce Interview Questions on Test Class

  5. Salesforce-lightning-interview-questions-2018

     6. Salesforce Interview Questions Batch Class 

The post Writing a Simple Apex Trigger !! appeared first on Salesforce Next Gen.

]]>
https://salesforcenextgen.com/writing-simple-apex-trigger/feed/ 2
Batch class : Salesforce Interview Question https://salesforcenextgen.com/salesforce-interview-question-batch-class/ https://salesforcenextgen.com/salesforce-interview-question-batch-class/#comments Mon, 17 Jul 2017 15:23:12 +0000 http://salesforcenextgen.com/?p=834 Salesforce Interview Question on Batch class What is Batch Apex? It is a class which is capable of accepting records in bulk and then depending upon the batch size the group of records are broken into Batches and are processed asynchronously. When should we use a batch class? We should batch apex when we are …
Continue reading Batch class : Salesforce Interview Question

The post Batch class : Salesforce Interview Question appeared first on Salesforce Next Gen.

]]>
Salesforce Interview Question on Batch class

What is Batch Apex?

It is a class which is capable of accepting records in bulk and then depending upon the batch size the group of records are broken into Batches and are processed asynchronously.

When should we use a batch class?

We should batch apex when we are dealing with records in bulk mainly the record size above 10000 and cannot be handled by the normal DML operations.

What is the basic structure of a Batch class?

the basic structure of a batch consists of three methods:

  1. Start
  2. Execute
  3. Finish

Describe each method of a batch class?

Start method:

Syntax: global Database.QueryLocator start(Database.BatchableContext BC)

This method receives the batchable context variable as an argument and returns a query locator variable.

Execute method:

Syntax:  global void execute(Database.BatchableContext BC, List<Account> scope)

This method receives the batchable context variable and an additional argument as scope which of list of subject type we are working with.

Finish method:

Syntax: global void finish(Database.BatchableContext BC)

This method receives the batchable context variable and is the last method which gets executed after all the batches have been processed, we can perform all the post execute logic in this method like sending an email etc.

What is a scheduler class?

A scheduler class implements the Schedulable interface and have to implement its execute method.

how to schedule a batch class ?

there are two ways to schedule a batch class:-

  1. Using developer console
  2. Using System Scheduler

By Developer console we have to pass a cron variable like below:-

AScheduleClass A = new AScheduleClass();

String schedule =  ’20 30 8 10 2 ?’; // cron object

String jobID = system.schedule(‘Merge Job’, schedule, A);

Via System Scheduler:

  1. Go to setup and in quick search bar type schedule. Then click on schedule apex.
  2. Select schedule created and set the time with help of the Salesforce UI.

Can we call a batch class from another batch class?

Yes, we can call one batch class from another batch class but only if it is called from its finish method.

Can we call a Future method from batch class?

no, we cannot directly call a future method from a batch class.

What is Database.Stateful used for in batch class?

As batch class runs asynchronously, to maintain the state of a variable across each batch we implement Database.Stateful.

How many can concurrent batch jobs be added to the queue?

At most, there can be 5 bath jobs queued at a time.

How can we track the status of the current running batch job?

The job Id returned by the batchable context variable helps us in finding the status of a batch through AsyncApexJob.Status.

Q . What is the purpose of start method in Batch Class?

Start object returns the list or group of records on which we are going to make changes.

What is database.getQuerylocator and what are its advantages?

It is used to fetch records from the database, if used in batch class it can fetch up to 50 millions records.

******* More questions to come

Want to learn more about batch Classes and Asynchronous Apex have a look at link below

Asynchronous Apex

The post Batch class : Salesforce Interview Question appeared first on Salesforce Next Gen.

]]>
https://salesforcenextgen.com/salesforce-interview-question-batch-class/feed/ 8
Salesforce Interview Questions on Trigger https://salesforcenextgen.com/salesforce-interview-questions-trigger/ https://salesforcenextgen.com/salesforce-interview-questions-trigger/#comments Thu, 13 Jul 2017 08:41:26 +0000 http://salesforcenextgen.com/?p=824 Salesforce Interview Questions on Trigger What is a Trigger? Trigger can invoke Apex code, they come in handy when we want to perform some custom task just before or after a record is either created updated or deleted. What are the various event on which a trigger can fire? A trigger is a set of …
Continue reading Salesforce Interview Questions on Trigger

The post Salesforce Interview Questions on Trigger appeared first on Salesforce Next Gen.

]]>
Salesforce Interview Questions on Trigger

What is a Trigger?

Trigger can invoke Apex code, they come in handy when we want to perform some custom task just before or after a record is either created updated or deleted.

What are the various event on which a trigger can fire?

A trigger is a set of statement which can be executed on the following events:

  1. Undelete
  2. Update
  3. Merge
  4. Delete
  5. Upsert
  6. Insert

 Broadly classify the Trigger?

Triggers can be broadly classified as before or after Trigger.

  • Before triggers are used to perform a task before a record is inserted or updated or deleted.
  • After triggers are used if we want to use the information set by Salesforce system and to make changes in the other records

What are the considerations while implementing the Triggers?

Consider the following before implementing the triggers.

  • Upsert trigger fires on 4 different events :- before(insert, update), after (insert, update)
  • Merge trigger are 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.

Read the Apex Developer Guide for more detailed considerations.

Write the syntax of Apex Trigger?

Trigger TName On ObjName(name the events){

……. Apex code here ……..

}

What are context variables in regards to trigger?

Following are the context variable available in triggers. Please note variable’s availability varies according to the type of trigger events.

  1. isExecuting
  2. isInsert
  3. isUpdate
  4. isDelete
  5. isBefore
  6. isAfter
  7. isUndelete
  8. new
  9. newMap
  10. old (update and delete only)
  11. oldMap (update and delete only)
  12. size

How is Trigger.New Different from Trigger.newMap?

Trigger.New variable returns the list of sObject which has invoked the trigger and Trigger.NewMap returns the map of ID’s with the newly entered records. NewMap is only available in after insert, before and after the update and after undelete.

How is Trigger.new different from Trigger.old?

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 delete events

Can a trigger call a batch class?

Yes, we can call a batch class in the trigger as we do in the normal apex code.

Can a trigger make a call to Apex callout method?

we can call a callout method in Apex Trigger but the only condition is that it has to be an asynchronous callout because the trigger flow cannot wait on the response received by the callout method.

Define Recursive Trigger and how to avoid it?

There is a possibility that the result of the trigger can end up calling the same trigger again and can run in a loop, this is known as a recursive trigger. To avoid this scenario we should create a static variable and check the value of this variable before we execute anything in the trigger.

What do you mean by the bulkifying trigger?

A trigger that can handle both single record and thousands of record. It is capable of handling mass action.

Is there any limit on number of triggers define on an object?

We can define as many triggers on an object as we want but it is recommended to have one trigger per object because the order of execution of different trigger is not guaranteed and any trigger can fire first.

Can you explain the order of execution in Triggers?

Following is the order of execution of events which Salesforce perform before a DML Event.

  1. The record is loaded from the database or is initialized in case of upset statement.
  2. 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:
    1. Any layout specific rules are checked
    2. All the required values are checked at layout and field level
    3. 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.

  1. Now all the before triggers are executed at the database.
  2. 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.
  3. After the success of the previous step, the record is reviewed for duplicate records, by running the duplicate rule. If a duplicate is found the flow is stopped and no further actions performed.
  4. In this step, record is saved to the database but it not committed yet.
  5. Now all the after Triggers are executed.
  6. In this step, assignment rules are executed.
  7. Now if there is any auto-response rule is present then they are executed.
  8. Next in the queues are the workflow, they are executed after the auto response.
  9. If the workflow was updating a field, then the fields updated in this step and the flow after this step varies if this was the case.
  10. If a field was updated then the before and after update triggers are fired once more and standard validation are also executed again. Custom validation escalation rule and duplicate rules are not required to run again.
  11. Once the execution has reached this stage, then process is fired if there are any declared on the object.
  12. Now the escalation rules are executed.
  13. Entitlement rules are executed if any.
  14. If there are any roll-up summary field, then they are calculated at this step and the parent object go through the save process.
  15. Now the sharing rules are executed.
  16. If we reach this stage, then that means no error has occurred and the data is ready to be committed to the database and is committed now.
  17. Now if there is any post-commit logic like email, then that is executed.

The post Salesforce Interview Questions on Trigger appeared first on Salesforce Next Gen.

]]>
https://salesforcenextgen.com/salesforce-interview-questions-trigger/feed/ 11
Salesforce Interview Questions and Answers Part 1 https://salesforcenextgen.com/salesforce-interview-questions-answers-part-1/ https://salesforcenextgen.com/salesforce-interview-questions-answers-part-1/#comments Sat, 08 Jul 2017 07:10:08 +0000 http://salesforcenextgen.com/?p=798 Salesforce Interview Questions and Answers What is Salesforce and what is the architecture of Salesforce? A. Salesforce is a Cloud based software made on Force.com platform, it has a pre-built feature to serve as a CRM,              but Salesforce is not limited to be called CRM, It has many out of …
Continue reading Salesforce Interview Questions and Answers Part 1

The post Salesforce Interview Questions and Answers Part 1 appeared first on Salesforce Next Gen.

]]>
Salesforce Interview Questions and Answers

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

A. Salesforce is a Cloud based software made on Force.com platform, it has a pre-built feature to serve as a CRM,              but Salesforce is not limited to be called CRM, It has many out of the box features. Salesforce uses Multitenant            architecture

2. What is Multitenancy?

A. It is the methodology in which all users share IT related resources to make it cost effective even for a small business. It helps in reducing the initial cost of starting a new.

Salesforce interview question                                      Salesforce interview question

Images sourced from site https://developer.salesforce.com/page/Multi_Tenant_Architecture

3. Can you explain multi-tenant Data model?

A. To deal with a tremendous, constantly changing arrangement of the genuine database, Force.com implements it storage model with the help of metadata, data and pivot table as described in the diagram below.

Salesforce interview question

Images sourced from site https://developer.salesforce.com/page/Multi_Tenant_Architecture

4.  Describe an object in Salesforce? How many types of objects are there in Salesforce?

A. They are similar to database tables of an organization and are used to store a record in Salesforce. Salesforce has provided us with some predefined objects which are known as standard objects and Salesforce has provided us with the ability to create new objects which are known as the Custom object.

5. What is the distinguishing factor between the standard object and custom object?

A. API name of Custom objects contains a suffix of ‘__c’. It is added automatically by Salesforce. E.g customobjectName__c

6. What is a field and how many types of field are there in Salesforce?

A. There are 4 types of fields, 1) Compound Field 2) system Field 3) required Field 4) custom field

7. What is a relationship field in Salesforce and how many types of relationships are there in Salesforce?

A. A relationship field is the one which associates one object with another object. A relationship can be formed between standard objects, custom objects and also between custom and standard objects. Salesforce provides three type of relationships, 1) Lookup 2) Master-Detail Relationship 3) External Relationship, the first two are the most common relationship used throughout the Salesforce.

8. The difference between lookup and master-detail relationship?

A. There are fundamental differences in the behavior and record sharing that you need to read up on.

The most important difference is that master-detail has a direct dependency between the objects:

You cannot have a detail record without a master.
The detail record inherits sharing rules from the master.
The maximum number of master-detail relationships are limited to two.
All related detail objects are deleted if the master object is deleted.

Lookups are used when the behavior of the master-detail – particularly around sharing rules, profile permissions and cascade delete are not required.
when multiple parents need to be referenced then we use look-up

9. Define Self Relationship in Salesforce?

A. It is a look up Relation to the same object.

10. How many types of Object Relationships are supported by Salesforce?

A. Salesforce supports three types of object relationship: 1) one -to- one 2) one – to – many 3) many – to – many

11. What is a trigger, when do we use before and after trigger?

A. A trigger is the flow of code which initiates before or after a DML Event. i.e. before insert or after update etc. We use before trigger if we want to process data before the record is committed and after trigger where we want to use the values from the committed record to change the value in other object’s record.

Salesforce interview Questions based Apex Collections

 Apex Collections are set of identical elements grouped together in a collection. A collection can be of three types list, set and map. Interview related questions as per the ones which I have faced during my interviews.

Q.What are the types of collections which are supported by salesforce?

A. Salesforce supports three types of collections

  1. List
  2. Set
  3. Map

Q. What are the difference between list, set and maps?

A. There are many differences between these collections.

  1. List is ordered, it allows duplicate values, values entered can be indexed. Sort method is available and contains methods is not available.
  2. Set is unordered, it does not allow duplicates and values entered cannot be indexed. Sort Method is not available and contains method is available in set.
  3. Map is a key value pair collection. It uses containsKey method, keyset() to get only the keys, values() to fetch all the values.

Q. what is the difference between add() and addAll() method?

A add() is used to add only one element in the collection and addAll() is used to add a collection to another similar collection.

Q. how to check whether a list is null or empty?

A. We check a list is empty or null by checking following condition/

If((listObj != null)&&(list.size()>0))

****More Questions to come 

Next: 

The post Salesforce Interview Questions and Answers Part 1 appeared first on Salesforce Next Gen.

]]>
https://salesforcenextgen.com/salesforce-interview-questions-answers-part-1/feed/ 4