Sumitdatta

Your first Salesforce Apex Trigger from scratch!!! - SalesforceNextGen. Writing your first Salesforce Apex Trigger from scratch!!! Before we dive deep into the abyss of Salesforce Trigger, we should know a little more about Triggers and why do we need a Trigger. Triggers are set of code lines which are scheduled to run on a DML event, i. e. when a record is created, updated, deleted, merged or recovered and automate the flow of execution before or after the DML event.

But we have another tool to automate business logic on DML event and that is Workflows. As we know that there are certain scenarios, in which we are not able to use Workflow for e.g., If we want to create a record of the separate object, on an update of standard contact object then we simply cannot use workflow. With workflow we can only perform few task i.e., field update, send email, send an outbound message and create a task.

To overcome these limitations of workflow, Salesforce provided us with Trigger. There are two places where you can write Trigger: SandboxDeveloper Edition. Writing a Simple Apex Trigger !!
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) { Now that we have defined the basic structure of the trigger now we will write the business logic as discussed in the beginning. for(contact con : Trigger.new){ con.lastname = ‘New Last Name using Trigger’; This is it, we have written a simple Trigger which initiates at before insert event of a contact.

This concludes how to write a Simple Trigger Interview Questions Apex Trigger. Making Apex trigger a bit more complex. Making the Apex trigger a bit more complex!! Making a Call to class’s method from the Trigger. This way we are able to implement the OOPs concept, our trigger’s code is efficient and maintenance of the code is easier. In the following code, we are going to call a method from a utility class, this method is used for sending an email to a recipient. To create the trigger, go to Developer Console->file->New-> Apex Trigger. Give it a name for e.g. SendEmailExampleTrigger and select Contact sObject. You will get some predefined code in the console, replace it with this code and save it. trigger SendEmailExampleTrigger on Contact (after insert, after delete) { if (Trigger.isInsert) { EmailManager.sendMail(SampleEmail@Address.com’, ‘Email’s Subject’, ‘Email’s Body’); **** Email Manager utility class need to be created separately.

To test this trigger all we need to do is insert a contact record and we can see that the email is sent to the mentioned email in the code. for(Account acc : Trigger.New) {
Design Patterns for Bulkifying an Apex Trigger. Design Patterns for bulkifying an Apex Trigger As Salesforce is built on the multi-tenant architecture, it has multiple platform limits which govern the uses of resources at one particular transaction. As the Apex trigger can operate on multiple records at the same time, it can easily breach the governor limits and therefore it is suggested that Apex trigger should be bulkified before it is moved to production.

Benefits of bulkified Trigger are many for e.g.: Better performanceConsume fewer resources and time over the serverIt rarely breach the governor limits To bulkify trigger means to work on collections of sObject instead of individual records. Let have a look in the below example: Trigger FirstBulktrigger on Account(before insert){ For(account test : Trigger.New){ Test.description = ‘Bulk Trigger was used’; SOQL is used in Trigger for so many reasons and one reason could be to fetch the related records. The best practices suggest the following code pattern: Con.lastname = ‘Bulk DML’;
Visualforce for salesforce Beginners. Visualforce for Beginners What is Visualforce? It is a web development framework. Developers can make complex UI both for mobile and desktop which can be hosted on forc.com environment. Visualforce provides access to Salesforce inbuilt features and enables us to extend them and introduce a new or custom functionality.

There are some powerful features enabled in visualforce like standardcontroller with help if with we can create awesome new apps from scratch. That’s enough for the background lets dive into coding. Sample Visualforce code: The page will display a field account name and save command button. Let’s break down the code:- This is a simple Visualforce page, where we have utilized few of the Visualforce –apex tag, now we will move on to a bit more complex pages. Now the question arises, where and how I can use the Visualforce Page: Creating and Editing a Visualforce page in Salesforce Let’s make our first Visualforce page; follow the below steps to create your first Visualforce page {!

{!
Data Model and Management - SalesforceNextGen. A data model is a way to represent the tables in the database which makes sense to humans, they help in understanding the relationship between different objects and Salesforce provides a very intuitive way to model the database. In the database a table is equivalent to an object, fields of the object are referred as a column of the table and a row of this table is known as a record. The data model is a collection of these objects and field in an app. There are many types of objects supported by Salesforce like standard object, custom object, external objects, Big Objects and Platform events.

We are going to stick with standard and custom object for now. Standard objects are the objects which are already created by Salesforce and are useful when it comes to the core of the Salesforce i.e. Custom Objects are the objects which are created if the standard out of the box objects is not able to satisfy a business need or requirement. 3. 4. 5. There are broadly four types of field:
Salesforce interview Questions Latest - SalesforceNextGen. In this post, I have collected all the Salesforce interview Questions which were asked to me in Salesforce interview for 2-3 years of experience. I have compiled these questions to the best of my knowledge. The answer provided here are answered to the best of my knowledge and they can be wrong, so kindly refer Apex developer guide and visualforce guide and other means to verify the answers. If you think any answer is incorrect then do mention the same in the comments. Here goes the list of Salesforce Interview Questions Q 1.

A) trigger.oldb) trigger.newc) trigger.new and trigger.oldd) None of the above Q2.When considering trigger context variables, which of the statement is true? A) We can delete trigger.newb) We cannot delete trigger. new c) trigger.new is always ready onlyd) trigger.new is ready only, so we can deletee) None of the statement is true 3. 4. A) Lookup b) Master-Detailc) Many to Manyd) Master to Mastere) Both b & c Q.5. Q.6. Q7. Q.8. 9. Q.10. *CCC selected Q.11. Q.12. Q.13. Get {
Asynchronous Apex, Batch Apex, Future method, Queuable and Schedule. Asynchronous Apex, we all know how sometimes Salesforce Governor Limit can haunt us at times. With the limited amount of resource available due to the multi tenant architecture, we have to restrict our self with the optimum usage of the resources. But what if we want to use the platform to its maximum limit, what if we want to do the process on huge volume of data.

To overcome the above-mentioned crisis, Salesforce Apex has provided us with the feature of Asynchronous Apex. To start with Asynchronous Apex provides us with the double governor limits in most of the cases and in some, we can perform a bulk operation on records up to 50 million. There are lots of benefits of using Asynchronous Apex, but we are supposed to choose which Asynchronous apex would be the best way to reach our business goal. Image Source: There are 4 Asynchronous Apex features their name and use cases are mentioned below:- @Future @future @isTest.

Salesforce Admin Certification Mock Exam - SalesforceNextGen. Then go through the series of Salesforce Admin Mock exams and test your skills. 0 of 60 questions completed Questions: Information This quiz will help budding Salesforce Administrator to prepare for the certification. You have already completed the quiz before.

You must sign in or sign up to start the quiz. You have to finish following quiz, to start this quiz: 0 of 60 questions answered correctly Your time: Time has elapsed You have reached 0 of 0 points, (0) Your result has been entered into leaderboard. Apex Trigger Best Practices and the Trigger Framework - SalesforceNextGen. Apex Trigger Best Practices In this section we will understand the best practices a user needs to follow to ensure the Trigger runs smoothly throughout its lifetime. We have always run in the situation where we have begun with a trigger which has a few lines of codes and serves a single purpose.

But as the time progress our trigger becomes more and more complex with addition of new business logic and keeps on growing. Soon it becomes difficult/ impossible to manage. Sooner or later we are going to find our self in a situation where a trigger has become too difficult to maintain and even the slightest change may have a disastrous effect. 1. The reason this is on top my best practice list is that, if we make more than one Trigger on an object then we are not able to control the order of execution of these trigger’s i.e. there is no proper flow control. 2. Next good practice is to make Trigger without covering any business logic inside the trigger itself, make it logic-less piece of code.
Asynchronous Apex, Batch Apex, Future method, Queuable and Schedule.

A. Q. A. SELECT Id, Name, FieldNameMultiSelectPl__C FROM CustomObjectName__c WHERE FieldNameMultiSelectPl__C = ‘ABC;EFG’ Or for multiple values. SELECT Id, Name, FieldNameMultiSelectPl__C FROM CustomObjectName__c WHERE FieldNameMultiSelectPl__C includes (‘ABC;EFG’ ,’CDE’ ) Q. A. Q. A. If a query includes Group by clause then it cannot be used with queryMore() method.
Salesforce Interview Questions and Answers Part | SalesforceNextGen. 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 the box features. Salesforce uses Multitenant architecture 2. What is Multitenancy? A. Images sourced from site 3. A. 4. A. 5. A. 6. A. 7. A. 8. A. The most important difference is that master-detail has a direct dependency between the objects: You cannot have a detail record without a master.

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. A. 10. A. 11. A. Salesforce interview Questions based Apex Collections Q.What are the types of collections which are supported by salesforce? A.
Salesforce Interview Questions on Trigger | SalesforceNextGen. 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: UndeleteUpdateMergeDeleteUpsertInsert 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. Read the Apex Developer Guide for more detailed considerations. Write the syntax of Apex Trigger? Trigger TName On ObjName(name the events){ ……. What are context variables in regards to trigger?
Salesforce Live, Working, Demo of Projects | SalesforceNextGen. Here you will find the Live working demo of projects made with the help of Salesforce platform using Apex, VisualForce, SOQL, SOSL, Lightening. SOQL2SQL – this code utilizes all the concept from Salesforce dynamic apex, Dynamic SOQL, sObject Describe call etc. With the help This app you can create/structure SOQL query without even typing a single line of code yourself, this is a perfect tool for beginners to check their knowledge of SOQL and cheat tool for advanced developer to quickly build SOQL query for their requirement.

All this possible without logging on to an external website like Workbench. Link : SOQL2SQL 2. RelationShip Model: Created a relationship map of based on their network, we can understand the importance of a particular record and estimate its influence. Link: Relationship Map *** more Salesforce projects to be uploaded soon. Salesforce interview questions on Batch Class | SalesforceNextGen.

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: StartExecuteFinish 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.
Salesforce Interview Question Test Class | SalesforceNextGen.