Sales Force Questions

If we have two pages and one controller, and the pages are using the same controller, how can you retain the view state when a user redirects from one page to the other?

To retain the view state and use the previous page’s variable in a redirected page, we have to call setRedirect(false) on a new PageReference instance (in a button’s click handler, for example.)

What is heap size, and what is its limit for asynchronous and synchronous calls? When the heap size limit is exceeded, how can you resolve that issue?

Hide answer

answer badge

Heap size is the size of the temporary storage of your data while executing your code in synchronous mode. All of your global variables get stored on the heap. For asynchronous mode, the heap size limit is 12 MB, and for synchronous mode, the heap size limit is 6 MB.

To reduce heap size, take the following steps:

  1. Reduce using global variables if not needed.
  2. Avoid using too many maps if not necessary. Try to reuse maps that are already defined if you’re using them for the same purpose later on, or call clear() when you’re done with them to free up heap space as you go.
  3. Use filters to avoid storing unnecessary data in List and Map. The heap size mainly increases due to storing data retrieved from a database in a variable. So if data are not necessary then we should clear() them after we finish our use of a particular Map or List.
  4. Avoid using nested for loops. If there is no way to avoid nested loops then put filter conditions in such a way that you can reduce execution statements.

If we have two pages and one controller, and the pages are using the same controller, how can you retain the view state when a user redirects from one page to the other?

Hide answer

answer badge

To retain the view state and use the previous page’s variable in a redirected page, we have to call setRedirect(false) on a new PageReference instance (in a button’s click handler, for example.)

question badge

What is heap size, and what is its limit for asynchronous and synchronous calls? When the heap size limit is exceeded, how can you resolve that issue?

Hide answer

answer badge

Heap size is the size of the temporary storage of your data while executing your code in synchronous mode. All of your global variables get stored on the heap. For asynchronous mode, the heap size limit is 12 MB, and for synchronous mode, the heap size limit is 6 MB.

To reduce heap size, take the following steps:

  1. Reduce using global variables if not needed.
  2. Avoid using too many maps if not necessary. Try to reuse maps that are already defined if you’re using them for the same purpose later on, or call clear() when you’re done with them to free up heap space as you go.
  3. Use filters to avoid storing unnecessary data in List and Map. The heap size mainly increases due to storing data retrieved from a database in a variable. So if data are not necessary then we should clear() them after we finish our use of a particular Map or List.
  4. Avoid using nested for loops. If there is no way to avoid nested loops then put filter conditions in such a way that you can reduce execution statements.
question badge

How many types of sandbox orgs are available with Enterprise Edition? What is the use of each?

Hide answer

answer badge

There are four types of sandbox org available with Enterprise Edition:

  • Developer provides 200 MB of data space
  • Developer Pro provides 1GB of data space
  • Partial Copy provides 5GB of data space, records (a sample of selected objects), and sandbox template support
  • Full Copy is the same as a production org, with the same record ids the production records have

Note that all of them provide:

  • Standard configuration as built into Salesforce
  • Apex and Metadata
  • All users copied from production

The uses of the sandbox org types are:

  • Developer and Developer Pro: The only difference between these two being their data space, they are both used to code and enhance existing functionality and then move it to production.
  • Partial Copy: Generally, when we are dealing with large amounts of data and want to have real-time testing data, then this sandbox is helpful because Salesforce gives up to 10,000 records of each object from production data.
  • Full Copy: When you want to replicate a production issue in a sandbox and fix it, then this sandbox is the perfect fit. That’s because even if you wanted to debug directly in production, you can’t. Also, sometimes to reproduce an issue and fix it, we need the exact same data, which is what a Full Copy sandbox gives you.

Find top Salesforce developers today. Toptal can match you with the best engineers to finish your project.

HIRE TOPTAL’S SALESFORCE DEVELOPERS

question badge

Can we call a class method from a custom button of an object without using a Visualforce page? If so, how? If not, why not?

Hide answer

answer badge

Yes, we can call a class method from a custom button. To call a class method, we need to use connection JS and Apex JS in the custom button, and then we can call the Apex class method using the following syntax:

{!requireScript("/soap/ajax/20.0/connection.js")}
{!requireScript("/soap/ajax/20.0/apex.js")}

retStr = sforce.apex.execute("SampleClass", "SampleMethod",{parameters of method});

Note: The class you are calling must be a global or Webservice class.

question badge

What is the difference between a SOAP API and a REST API? When we can use a REST API and when we can use a SOAP API?

Hide answer

answer badge

SOAP APIs use WSDL files to make objects and database access available to Salesforce. REST can be JSON- or XML-based, while SOAP is only XML-based. REST is most often used by mobile apps, while SOAP is used to connect with legacy systems. For example, if we want to connect to SAP using Salesforce, then SAP will provide a WSDL file to connect to their database. We can use REST when a third-party system wants to extract data from or insert data into a Salesforce database.

question badge

Write Apex code to get the first date and last date of a month given in a string field where values are in the format 06-2018, using system-provided methods.

Hide answer

answer badge

Because the string is not a full date, we cannot use functions like Date.parse(). Now let’s say the field name is month:

FirstDate = date.newInstance(month.split('-')[1],month.split('-')[0],1);
LastDate = firstDate.addMonth(1).addDays(-1);
question badge

Write Apex code to fetch the picklist values from a particular object, e.g. the Display Industry picklist values from a Visualforce page.

Hide answer

answer badge
Schema.DescribeFieldResult fieldResult = Account.Industry.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
question badge

What is a wrapper class? Give one use case where you would use a wrapper class.

Hide answer

answer badge

A wrapper class is an outer class that we use to bind values or objects which are not available in the inner class.

Use cases:

  • Let’s say we want to display account records and we want to let the user select a record to perform an action on. We can create a wrapper class with one field as a boolean value and another as an account object, to bind the two together.
  • A wrapper class is also used when we have to display data in a matrix format.
  • If we want to show a scoreboard of recruiters from a placement object in a table, then we need to use a wrapper to store the recruiter name and corresponding score. Since there are many placements and many recruiters, we have to map the given placement number to its recruiters, and only then can we bind recruiters with scores and display them in a table.
question badge

What is the difference between the DML statement insert and a Database.insert() call?

Hide answer

answer badge

We use insert so that if any error occurs in any record, the system will throw a System.DmlException: Insert failedexception and none of the records will be inserted.

If we want to allow partially successful bulk insert operations, we use database.insert() instead.

question badge

Why do will need Database.Stateful in a batch class?

Hide answer

answer badge

A batch class is an asynchronous method, so when the batch class runs, each execution method is processed in a separate thread. Now if we have mentioned one list globally to update all of the processed records in a finish method, then we will need to make this batch class stateful to retain the values of global variables. Otherwise, each thread will have its own separate copy of all global variables, so none of them will add to the list used by the main thread’s finish method.* There is more to interviewing than tricky technical questions, so these are intended merely as a guide. Not every “A” candidate worth hiring will be able to answer them all, nor does answering them all guarantee an “A” candidate. At the end of the day, hiring remains an art, a science — and a lot of work.

You May Also Like…

Why Asp.net Core is Better Than Other Languages

In the kaleidoscopic World Wide Web world there are numerous programming languages having specialty of their own.  The world of Web is constantly evolving along with the languages associated with it. One such evolving language is ASP.NET. There are also many other...

Problems Faced By Beginner Developers

Problems Faced By Beginner Developers

With the inception of android operating system in 2008. The world was opened to whole new dimension that was innovative enough that is pierced and permeated the hearts and the mobile market worldwide. The latest and radically unique technology took every one by storm....

Mobile Application Vs Web Application What’s The Difference

Mobile Application Vs Web Application What’s The Difference

There is a wrong concept that mobile applications and web applications are same, but in reality these are two different things. Even the process of developing and deploying them is also different. A web application is actually a website which can run on mobile, tablet...

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Additional REsources

A Few Other Resources We’ve Created for Our Customers

Difference in Software Goals and Systems

Goals are very important aspect of life of human or any business. It defines targets, ambitions and directions. I bet you have many goals in your life. i do I have them. Goal are essential for any person or organizational...

Website using Wix.com – Why it doesn’t worth?

Not even including my freelance years, my agency of over four years has built on Wordpress 99% of the time, with many themes. You don't need to sell me on the power of Wordpress. For years, I've joined in on the belief that Wix is bad. I've had to help edit a few...

Contact Us

Write back to us to discuss your next project, plan, strategy and technology stack.

info@relliks.com

0092 321 6181488

Relliks Systems, T(02) C, Gulberg III, Lahore

M-F: 8am-5pm, S-S: Closed