Interview Q&A

1. What is App in Sales force?

An app is a group of tabs that work as a unit to provide functionality. Users can switch between apps using the Force.com app drop-down menu at the top-right corner of every page.

You can customize existing apps to match the way you work, or build new apps by grouping standard and custom tabs.

Navigation to create app in Sales force: Setup ->Build ->Create->App-> Click on new and create your application according to your requirements.

2. What is object in Sales force?

Custom objects are database tables that allow you to store data specific to your organization in salesforce.com. You can use custom objects to extend salesforce.com functionality or to build new application functionality.

Once you have created a custom object, you can create a custom tab, custom related lists, reports, and dashboards for users to interact with the custom object data. You can also access custom object data through the Force.com API.

Navigation to create object in sales force: Setup->Build->Create->Object-> Click on new object and create object according to your requirement.

3. How many relationships included in SFDC & What are they? 

We are having two types of relationships, they are

Lookup Relationship

Master-Detail Relationship

4.  What is a “Lookup Relationship”?

This type of relationship links two objects together,

Up to 25 allowed for object

Parent is not a required field.

No impact on a security and access.

No impact on deletion.

Can be multiple layers deep.

Lookup field is not required.

5. What is “Master-Detail Relationship”?

Master Detail relationship is the Parent child relationship. In which Master represents Parent and detail represents Child. If Parent is deleted then Child also gets deleted. Rollup summary fields can only be created on Master records which will calculate the SUM, AVG, MIN of the Child records.

Up to 2 allowed to object.

Parent field on child is required.

Access to parent determines access to children.

Deleting parent automatically deletes child.

A child of one master detail relationship cannot be the parent of another.

Lookup field on page layout is required.

6. How can I create Many – to – Many relationship?

Lookup and Master detail relationships are one to many relationships. We can create many – to – Many relationship by using junction object. Junction object is a custom object with two master detail relationships.

7.  A custom object contains some records, now my requirement is to create field in this object with master detail relationship. Can we create master detail relationship in this case?

No, directly we cannot create master details relationship if custom object contains existing records.

Following are the steps to create to create master-detail relationship when records are available in custom object.

First create field with lookup relationship.
And then associate look field with parent record for every record
3. Next change the data type of the field from look up to Master detail.

8. List examples of custom field types?

Text, Pick list, Pick list (multi select), Date, Email, Date/Time, Date, Currency, Checkbox, Number, Percent, Phone, URL, Text Area, Geolocation, lookup relationship, master detail relationship etc…..

9. What is TAB in Salesforce?

Tab is a user interface component to display custom object data.

There are three type of tabs.

Custom Tabs

Visual force Tabs

Web Tabs

10. Does user can create insert their own custom logo, while creating their own custom applications?

Yes user can upload their custom logo in documents and then they choose that logo for organization.

11. List things that can be customized on page layouts?

We can customize different things on page layout like, Fields, Buttons, Custom Links and Related Lists. We can also create sections.

12. What is a “Self Relationship”?

Self Relationship is a lookup relationship to the same object. Suppose let’s take an object “Merchandise”. Here we can create relationship in between the Account to Account (same object) object. That is called “Self Relationship”.

13. What are the main things need to consider in the “Master-Detail Relationship”?

Record level access is determined by the parent, Mandatory on child for reference of parent, cascade delete (if you delete the parent, it can cascade delete the child).

14. What is difference between trigger and workflow?

Workflow



Workflow is automated process that fired an action based on Evaluation criteria and rule criteria.

We can access a workflow across the object.

We cannot perform DML operation on workflow

We cannot query from database

Trigger

Trigger is a piece of code that executes before or after a record is inserted or updated.

We can access the trigger across the object and related to that objects

We can use 20 DML operations in one trigger.

We can use 20 SOQL’s from data base in one trigger.

15. What is Wrapper class?  

A Wrapper class is a class whose instances are collection of other objects.

It is used to display different objects on a Visual Force page in same table.

16. What is Difference between SOQL and SOSL?

SOQL(Salesforce Object Query Language)

Using SOQL we can Search only on one object at a time.

We can query on all fields of any datatype

We can use SOQL in Triggers and classes.

We can perform DML operation on query results.

SOSL(Salesforce object Search Language)

Using SOSL we can search on many objects at a time.

We can query only on fields whose data type is text,phone and Email.

We can use in calsses but not in Triggers.

We cannot perform DML operation on search result

17. What is difference insert() and database .insert() ?

Using insert method we can insert the records but if any error occurs in any record system will throw an error insertion fail and none of the records are inserted.

If we want to execute partially success of bulk insert operation we will use database .insert.

18. What is Static Resources?

Using Static Resources we can upload images, zip files, jar files, java script and CSS files that can be referred in a visual force page.

The maximum size of Static Resources for an organization is 250mB.

19. How to call java script using Static Resource in Visual Force page?

Add java script file in Static Resource setup -> develop -> Static Resources -> click on ‘New’ -> Name: filename and add file from local desktop and save.

We can use that file as follows in Visual Force page

<apex: includescript values=” {! $Resource.fileName}”/>

20. What is sharing rule?

If we want to give the access to other users we use sharing rules.

21. How many ways we can share a record?

Role Hierarchy:

If we add a user to a role, the user is above in the role hierarchy will have read access.

Setup -> manage users -> roles -> setup roles -> click on ‘add role’ -> provide name and save.

OWD:

Defines the base line setting for the organization.

Defines the level of access to the user can see the other user’s record

OWD can be Private, Public Read Only, Public Read and Write.

Setup -> Security Controls -> sharing settings -> Click on ‘Edit’

Manual Sharing:

Manual Sharing is sharing a single record to single user or group of users.

We can see this button detail page of the record and this is visible only when OWD setting is private.

Criteria Based Sharing rules:

If we want to share records based on condition like share records to group of users

Whose criteria are country is India.

Setup -> security controls -> sharing settings -> select the object and provide name and

Conditions and save

Apex sharing:

Share object is available for every object(For Account object share object is AccountShare ). If we want to share the records using apex we have to create a record to the share object.

22. What are the actions in workflow?    

1. Email Alert

2. Task

3. Field Update

4. Outbound Message

Go through the below link for the more information about workflow actions      https://www.salesforcetutorial.com/salesforce-workflow-automation-workflow-management/



23.  How many ways we can made field is required?

1. While creation of field

2. Validation rules

3. Page Layout level

24.  What is difference between Role and Profile? 

Role is Record level access and it is not mandatory for all users.

Profile is object level and field level access and it is mandatory for all users.

25. What is the maximum size of the PDF generated on visualforce attribute renderAs?

15MB

26.  How many controllers can be used in a visual force page? 

Salesforce come under SAAS so, we can use one controller and as many extension controllers.

27.  What is difference between Action support and Action function?

Action function:  Invoke the controller method from java script using AJAX and we can use action function from different places on visual force page.

Action support: Invoke the controller method using AJAX when even occurs on page like onMouseOver, onClick, ect… and we can use action support for a particular single apex component.

28. How many ways we can call the Apex class?

1. Visual force page

2. Web Service

3. Triggers

4. Email services

29. How to create Master Details relationship between existing records?

Directly we can’t create Master Detail relationship between existing records, first we have to create Lookup relationship and provide valid lookup fields and it shouldn’t  null.

30. What is permission set?

Permission sets extend user’s functional access without changing user’s profile.

Ex:  A user has only read access through profile on custom object, administrator want to give access Edit and create operations to him without changing the profile. Administrator creates the permission set having edit and creates operation on custom object and assign to that user.

31. What is manual sharing?

Manual sharing is to share a record to a particular user manually.

Go to detail page of record and click on manual sharing button and assign that record to other user with Read or Read/Write access.

Manual Sharing button enables only when OWD is private to that object.

32. How we can change the Grant access using role hierarchy for standard objects?

Not possible.

33. What is the use of “Transfer Record” in profile?

If user have only Read access on particular record but he wants to change the owner name of that record, then in profile level Transfer Record enables he can able to change the owner.

34. What is Field dependency?

According to the field selection on one field filter the pick list values on other field.



35. Is check box performs like controlling field?

Yes possible. Controlling field should be Check box or pick list.

36. How many field dependencies we can use in Visual Force page?

Maximum we can use 10 field dependencies in VF page.

37. What is Roll-up summary?

Roll-up displays the count of child records and calculate the sum, min and max of fields of the child records.

38. How to create Roll-up summary field on lookup relation?

Not possible. Roll-up summary is enabled for only Master –Detail relationship.

39. What are the Record Types?

 Record Types are restrict the pick list values and assign to the different page layouts for different Record Types.

40. What is Audit Trail?

Audit Trail provides the information or track all the recent setup changes that an administrator done to the organization.

This can store the last 6 months data.

41.  What are the Report Types?

4 Types of report in Salesforce

Tabular Reports: We can only displays the grand total in the table form.

Summary Reports: It is a detail form of report in which the grouping done based on Columns.

Matrix Reports: It is a detail form of report in which the grouping done based on both Rows and Columns.

Joined Reports: We can join the two or more reports in the single report displayed in the form of blocks.

42. What is Dashboard?

Dashboard is a pictorial representation of report. We can add up to 20 reports in single dashboard.


43. What is the default timeout period while calling webservice from Apex.

10Sec

44. We have a “Time Based Workflow” and there is Action scheduled to be executed. If we Deactivate the workflow, Scheduled actions will be removed from queue or not?

Action will be performed even if we are deactivated the workflow.

45.  How to delete “Time based workflow” if there is already an action scheduled?

We can’t delete the “Time based workflow” if any pending actions in the queue.



46. How to update the record using After Trigger context? 

Not possible. You will get error like “Record is Read only”.

47. What is the difference between “Export” and “Export All” in Data Loader in Salesforce?

Export is export all the data from Salesforce.com excluding the recycle bin’s data.

Export All is export all the data from Salesforce including the recycle bin’s data.

48. What is the use of “ALL ROWS” in SOQL?
ALL ROWS is used for retrieving the records from recycle bin.

Ex:  SELECT Id from Campaign ALL ROWS

-> “ALL ROWS” is not work in developer console.

49. What is the use of “FOR UPDATE” in SOQL?

FOR UPDATE is used to lock the records.

Ex:  Campaign cam = [SELECT id FROM Campaign LIMIT 1 FOR UPDATE];

50. What is the use of “savepoint” in apex?

This is will use for to roll back the changes.

51. How to call Apex class using java script?

Check the below code.

Apex Class:

global class ClassName{

webService static String methodName(String camName) {

Campaign cam = new Campaign(name = camName);

return cam.name;

}

}

Java Script:

var Campaign = sforce.sObject(“Campaign”);

var String = sforce.apex.exceute(“ClassName”,”methodName”,{name=”ABC”});

52. How to run trigger in asynchronously?

If you use @FUTURE annotation trigger run asynchronously.

53. We are not providing some of fields in .csv file which are required in page layout level. What      happens if we try to insert records into Salesforce through data loader?         

 All records are inserted in Salesforce successfully.

54. We are not providing some of fields in .csv file which are required in Filed level. What      happens if we try to insert records into Salesforce through data loader?

Except those records remaining records will be inserted into Salesforce.

=======================================================

55.What is visualforce?

Visualforce is tag-based markup language to develop a customized user interface in salesforce.

56. What is the visualforce controller in salesforce? What are they?

Visualforce controller is a set of instructions that specify what happens when a user interacts with components on visualforce pages, such buttons & links.

There are three types of controllers. They are.

Standard Controller, Custom controller & Controller extensions.



57. What is Standard Controller?

A standard controller provides the salesforce inbuilt functionality to interact with visualforce pages. You can use the standard actions like Save, Edit, Cancel & delete by using standard controllers.

Syntax : <apex:page standardController=”Account”>

Know more about the standard controller

58. What is Standard List Controller?

Standard List Controller allows displaying a list of records in a visualvalfoce page. Standard list controller provides additional pagination actions (First, Lat, Next & Previous) compared to the standard controller.

Syntax: <apex:page standardController=”Account” recordSetVar=”accounts”>

defining this controller is similar to standard controller. But need to add one more attribute recordSetVar

Know more about Standard List Controller

59. What is Custom Controller?

Custom controller is an apex class that implements customized logic to visualfore pages.

We can override or create new functionality by using custom controllers.

Syntax: <apex:page controller=”Account” >

Know more about custom controller

60. Can we use standardController & controller attributes at a time?

No, We cannot reference both attributes at a time.

See below syntax to under stand

<apex:page standardController=”ControllerName” extensions=”Class1, Class2,..”> Correct

<apex:page Controller=”MYControllerName” extensions=”Class1, Class2,..”> Correct syntax

<apex:page standardController=”MYControllerName” Controller=”MyController”>  Wrong

61. What are the tasks of standard controller?

Standard controllers provides the ability to access and interact with structured business data contained in records displays in the proper user interface.

Standard controller tasks: controlling data, controlling actions and controlling navigation.

62. How can you create a visualforce page in salesforce?

We can create visualforce pages in two ways.

1. From the setup menu go to Setup-> develop -> Build->Pages-> click on new button to create a page & enter name & code for visualforce page.

2. From the Visualforce editor. Enter /apex/pagename at the url & create a new page in the visualforce editor.

Know more information about this

63. What is <apex:page> tag in visualforce markup?

This tag represents a single visualforce page. Every page must start & end with this tag.

<apex:page>

<!– Body of the page –>

</apex:page>

know more about <apex:page> tag

64. How can we enable visualforce editor?

We need to check the “development mode” check box at the user level to enable visualforce editor.

To enable this, go to user details page check the development mode check box.


================================================

Salesforce Integration Interview Questions and answers:

1. What is Integration?
Integration is a process of connecting two applications. 

2. What is webservices?
Webservices is a functionality or code which helps to us to do integration. Web services are open standard (XML, SOAP, HTTP, etc.) based web applications that interact with other web applications for the purpose of exchanging data. Web services can convert your existing applications into web applications.

3. What is Protocal ?
Protocal is a set of mutually accepted and implemented rules at both ends of the communications channel for the proper exchange of information.

4. How many types of API’s available in salesforce?
REST API
SOAP API
Bulk API
Streaming API
Metadata API
Chatter REST API
User Interface API
Analytics REST API
Apex REST API
Apex SOAP API
Tooling API
 

5. When to Use REST API:
Use for mobile applications. 

6. When to Use SOAP API
To integrate Salesforce with your org’s ERP and finance systems. You can also deliver real-time sales and support information to company portals and populate critical business systems with customer information.

7. When to Use Chatter REST API
Use Chatter REST API to display Chatter feeds, users, groups, and followers, especially in mobile applications. Chatter REST API also provides programmatic access to files, recommendations, topics, notifications, Data.com purchasing, and more. 

8. When to Use Streaming API
Use Streaming API to receive near-real-time streams of data that are based on changes in Salesforce records or custom payloads. For Salesforce record changes, Salesforce publishes notifications when the changes occur. 

9. When to Use Apex REST API
Use Apex REST API when you want to expose your Apex classes and methods so that external applications can access your code through REST architecture. Apex REST API supports both OAuth 2.0 and Session ID for authorization.

10. When to Use Apex SOAP API
Use Apex SOAP API when you want to expose Apex methods as SOAP web service APIs so that external applications can access your code through SOAP.
Apex SOAP API supports both OAuth 2.0 and Session ID for authorization.

11. When to Use Tooling API
Use Tooling API to integrate Salesforce metadata with other systems. 

12. What is Call In and Call Out?
Call In is used to exposing our webservices to another system.
Call out enables you to tightly integrate your Apex with an external service by making a call to an external Web service or sending a HTTP request from Apex code and then receiving the response.

13. What is WSDL ?
WSDL (Web Services Description Language) is an XML document that describes a web service. WSDL is derived from Microsoft’s Simple Object Access Protocol (SOAP) and IBM’s Network Accessible Service Specification Language (NASSL). WSDL replaces both NASSL and SOAP as the means of expressing business services in the UDDI registry. It is used in combination with SOAP and XML Schema to provide web services over the Internet. A client program connecting to a web service can read the WSDL to determine what functions are available on the server. Any special datatypes used are embedded in the WSDL file in the form of XML Schema. The client can then use SOAP to actually call one of the functions listed in the WSDL. There are two types of WSDL in  Salesforce:

Enterprise WSDL
Partner WSDL

15. What is difference between Enterprise WSDL and Partner WSDL?
Enterprise WSDL
The Enterprise WSDL is strongly typed.
The Enterprise WSDL is tied (bound) to a specific configuration of Salesforce (ie. a specific organization’s Salesforce configuration).
The Enterprise WSDL changes if modifications (e.g custom fields or custom objects) are made to an organization’s Salesforce configuration.
Partner WSDL
The Partner WSDL is loosely typed.
The Partner WSDL can be used to reflect against/interrogate any configuration of Salesforce (ie. any organization’s Salesforce configuration).
The Partner WSDL is static, and hence does not change if modifications are made to an organization’s Salesforce configuration.
How SOAP can be accessed ?
SOAP can be communicate through WSDL file, without WSDL file we can’t do integration.
Message format in SOAP is XML

16. How to generate WSDL file?
Go to Setup -> Develop  -> apex classes
Click on Apex class
Click on Generate WSDL button
Generate WSDL code from class
Save as .wsdl file in your system
 

17. How to consume external WSDL file
In the application, from Setup, enter Apex Classes in the Quick Find box, then select Apex Classes.
Click Generate from WSDL.
Click Browse to navigate to a WSDL document on your local hard drive or network, or type in the full path. This WSDL document is the basis for the Apex class you are creating.
Click Parse WSDL to verify the WSDL document contents. The application generates a default class name for each namespace in the WSDL document and reports any errors. Parsing fails if the WSDL contains schema types or constructs that aren’t supported by Apex classes, or if the resulting classes exceed the 1 million character limit on Apex classes. For example, the Salesforce SOAP API WSDL cannot be parsed.
Modify the class names as desired. While you can save more than one WSDL namespace into a single class by using the same class name for each namespace, Apex classes can be no more than 1 million characters total.
Click Generate Apex. The final page of the wizard shows which classes were successfully generated, along with any errors from other classes. The page also provides a link to view successfully generated code.
What is remote site settings ?
Remote site settings is used to authorize the endpoint and allow us to whom integrate(end user)

18. How manys ways to XML parsing ?
They are two ways of XML parsing
1. XML streams
2. XML DOM

19. How to read root element in XML DOM ?
getroot element

20. How to read child element in XML DOM ?
getchild element

21. How to read all child elements in XML DOM ?
getchild elements

22. How to read text between tags ?
gettext

23. How SOAP and REST will Communicate ?
SOAP will communicate through WSDL file.
REST will communicate through HTTP protocol.

24. What are methods in REST
HTTPGET : Retrieve data identified by a URL.
HTTPPOST : Create a resource or post data to the server.
HTTPDELETE : Delete a resource identified by a URL.
HTTPPUT : Create or replace the resource sent in the request body.
 
25. What is difference between SOAP and REST?
SOAP API: The Simple Object Access Protocol (SOAP) is an attempt to define a standard for creating web service APIs. It is a pattern, a web service architecture, which specifies the basic rules to be considered while designing web service platforms. It typically uses HTTP as a layer 7 protocol, although this is not mandatory.

The SOAP message itself consists of an envelope, inside of which are the SOAP headers and body, the actual information we want to send. It is based on the standard XML format, designed especially to transport and store structured data. SOAP may also refer to the format of the XML that the envelope uses. SOAP is a mature standard and is heavily used in many systems, but it does not use many of the functionality build in HTTP. While some consider it slow, it provides a heavy set of functionality which is a necessity in many cases. It might now be the best solution for browser-based clients, due to its custom format.

Supports data in the form of XML only and not JSON.
Requires WSDL for the integration
Use SOAP API in any language that supports Web services.
 

REST API: The Representational State Transfer (REST) is another architectural pattern (resource-oriented), an alternative to SOAP. Unlike SOAP, RESTful applications use the HTTP build-in headers (with a variety of media-types) to carry meta information and use the GET, POST, PUT and DELETE verbs to perform CRUD operations. REST is resource-oriented and uses clean URLs (or RESTful URLs).

Supports both XML and JSON format
Preferred for mobile and web apps since JSON being Lighter the app runs smoother and faster

26. What is JSON ?
JSON stands for JavaScript Object Notation. JSON is light weighted than XML.  When exchanging data between a browser and a server, the data can only be text. JSON is text, and we can convert any JavaScript object into JSON, and send JSON to the server.

 
Order of Execution
------------------

Here is cheat-sheet of Order of execution. Salesforce performs the following events in below order.

Loads Initial record.

If the request came from a standard UI edit page, Salesforce runs system validation to check the record for page layout specific rules, field definition, Maximum field length.

Executes  flows that make before-save update. (New Change in Winter 20)

Executes all before triggers. 

Runs most Custom validation.
Executes duplicate rules. 
Saves the record to the database, but doesn’t commit yet. 
Executes all after triggers. 
Assignment rules. 
Executes auto-response rules. 
Executes workflow rules. 
If there are workflow field updates, updates the record again.
Due to Workflow field updates introduced new duplicate field values, executes duplicate rules again. If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules are not run again.
Executes processes and flow. 
Escalation rules. 
Executes entitlement rules. 
Executes record-triggered flows that are configured to run after the record is saved.
If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure. 
If the parent record is updated, and a grandparent record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the grandparent record. Grandparent record goes through save procedure. 
Executes Criteria Based Sharing evaluation. 
Commits all DML operations to the database. 
Executes all after-commit logic, such as sending email.

What is part of the after commit logic?

All email sends
Asynchronous Apex: @future methods
Async Sharing Rule processing (for >25,000 records)
Outbound Messages placed on queue
Calculate Index, such as Search Index
Render File Previews
Publication of Platform Events (if configured)

Salesforce Lightning Interview Questions and answers:

1. 

Asynchronous Apex Interview Questions

1. Can we call the batch in to another batch apex?

Yes, we can call from finish method.

2.Can we call batch apex in to another batch in excute method?

Only in batch class finish method, We can call another batch class. If you will call another batch class from batch class execute and start method, then Salesforce will throw below runtime error.

System.AsyncException: Database.executeBatch cannot be called from a batch start, batch execute, or future method.

3.Can we call the batch apex from triggers in salesforce?

Yes, it is possible. We can call a batch apex from trigger but we should always keep in mind that we should not call batch apex from trigger each time as this will exceeds the governor limit this is because of the reason that we can only have 5 apex jobs queued or executing at a time.

4.Can we call webservice callout from batch apex?

To make a Webservice callout in batch Apex, we have to implement Database.AllowsCallouts interface.

5.How many times start,execute,finish methods will excute in batch apex?

Start method,finish method one time, execute method it depends on requirement. Based on the batch size and data retrieved in Start method.

6.What is the Batch executions limit per day?

The maximum number of batch executions is 250,000 per 24 hours.

7.Can we call the future method in batch class?

No,we can’t call.

8. Is Future method support primitive data types? Why sobject parameters not supported?

The reason why sObjects can’t be passed as arguments to future methods is that the sObject might change between the time you call the method and the time it executes. In this case, the future method will get the old sObject values and might overwrite them.

9.How can I perform Callouts from Future methods?

We need to add a parameter callout=true in @future.

10.Can I write a future call in Trigger?

Yes.

11.What are the limitations of future methods?

It is not a good option to process large numbers of records.

Only primitive data types supported.

Tracing a future job is also typical.

Can’t call future from batch and future contexts, 1 call from queueable context is allowed.

12.What is future method?

Use of future methods to isolate DML operations on different sObject types to prevent the mixed DML error. Each future method is queued and executes when system resources become available. That way, the execution of your code doesn’t have to wait for the completion of a long-running operation. A benefit of using future methods is that some governor limits are higher, such as SOQL query limits and heap size limits

NOTE :-
1) Methods with the future annotation must be static methods

2) can only return a void type

3) The specified parameters must be primitive data types, arrays of primitive data types, or collections of primitive data types

4) Methods with the future annotation cannot take sObjects or objects as arguments.

5) You can invoke future methods the same way you invoke any other method. However, a future method can’t invoke another future method

6) No more than 50 method calls per Apex invocation

7) Asynchronous calls, such as @future or executeBatch, called in a startTest, stopTest block, do not count against your limits for the number of queued jobs

8) The maximum number of future method invocations per a 24-hour period is 250,000 or the number of user licenses in your organization multiplied by 200, whichever is greater

9) To test methods defined with the future annotation, call the class containing the method in a startTest(), stopTest() code block. All asynchronous calls made after the startTest method are collected by the system. When stopTest is executed, all asynchronous processes are run synchronousl

13.How does Queueable Apex differ from Future methods?

Queueable Apex is similar to future methods in that they’re both queued for execution, but they provide us these additional benefits.

When you queue a Queueable Apex, you get a job ID, that can be used to trace it easily, which is not possible in case of future methods.

You can use non-primitive datatypes in Queueable Apex, like objects and sObjects, which is not possible in case of future methods, because it supports only primitive data types as params.

You can chain jobs, by calling another starting a second job from a running job, which is not possible in case of future methods, because we can’t call another future method from a future context.

14.Can you write a sample Queueable Job?

Create a class, implement the Queueable interface, and override the execute method.

public class QueueableApexExample implements Queueable {
public void execute(QueueableContext context) {
//some process
}
}

15.How can I use this Job Id to trace the Job?

Just perform a SOQL query on AsyncApexJob by filtering on the job ID.

AsyncApexJob jobInfo = [SELECT Status,NumberOfErrors FROM AsyncApexJob WHERE Id=:jobID];

16.Can I do callouts from a Queueable Job?

Yes, you have to implement the Database.AllowsCallouts interface to do callouts from Queueable Jobs.

17.How many numbers of jobs, I can queue using System.enqueueJob() at a time?

You can add up to 50 jobs to the queue with System.enqueueJob in a single transaction in Synchronous apex. In asynchronous transactions, you can add only one job to the queue.

18.Can I call Queueable from a batch?

Yes, But you’re limited to just one System.enqueueJob call per execute in the Database.Batchable class. Salesforce has imposed this limitation to prevent explosive execution.

19.If I have written more than one System.enqueueJob call, what will happen?

System will throw LimitException stating “Too many queueable jobs added to the queue: N”

20.I have a use case to call more than one Queueable Jobs from a Batch apex, how can I achieve it?

Since we can’t call more than one Queueable Job from each execution Context, We can go for scheduling the Queueable Jobs.

The approach is we need to first check how many queueable jobs are added in the queue in the current transaction by making use of Limits class. If the number has reached the limit, then call a schedulable class and enqueue the queueable class from the execute method of a schedulable class.


No comments:

Post a Comment