Difference between JavaScript Remoting and

The <apex:actionFunction> component also lets you call controller action methods through JavaScript.

In general, <apex:actionFunction> is easier to use and requires less code, while JavaScript remoting offers more flexibility.

Here are some specific differences between the two.

The <apex:actionFunction> tag:

1. lets you specify rerender targets
2. submits the form
3. doesn’t require you to write any JavaScript

JavaScript remoting:

1. lets you pass parameters
2. provides a callback
3. requires you to write some JavaScript


Salesforce Interview questions with answers Part 31

1. Suppose C is a junction object which has master detail relationship with A and B objects. Then from which object does C inherits all sharing settings and other features of master detail relationship.

A, if A was the first Master Detail relationship field because that will be the primary object in M:M relationship.


2. What is Merge Statement?



3. Use of Process Builder in Salesforce


4. Custom Settings


5. @RemoteAction in Visual force page


6. What is mean by Winning Records and Losing Records in triggers?


7. What is parallel approval process in Salesforce?


8. Custom Meta data in Salesforce


9. How can we reset the governor limits within a test class?



versions 3.0 and higher must specify pricebook entry id, others must specify product id

If you get this error:

First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: unknown, unknown (versions 3.0 and higher must specify pricebook entry id, others must specify product id): unknown, unknown

Solution 1:


Solution 2:

Make sure while creating OpportunitLineItem (Opportunity Product), PricebookEntryId is not null.


How to disable Advance Currency Management in Salesforce?

1. Go to "Manage Currencies".

2. Click "Disable" button.


Roll-up Summary field is still calculating

If you have created a roll-up summary field and it continues to display the spinning hour-glass icon, you may have advanced currency management enabled and be summarizing a currency field on the opportunity object.

If you have this feature enabled (you can check by going to Setup | Company Profile | Manage Currencies), you cannot create roll-up summary fields that calculate currency on the opportunity object. If you had set up any currency-related roll-up summary fields on the opportunity object, these will be disabled and their values will no longer be calculated.

Check the below link for more info



Lazy Loading Visualforce page

To reduce or delay expensive calculations or data loading, use lazy loading, a technique in which a page loads its essential features first and delays the rest—either briefly or until the user performs an action that requires the information. This technique gives users faster access to essential features, improving the apparent responsiveness of a large page, even though the entire page takes the same total time to load.

To lazy load parts of a Visualforce page:
1. Use the rerender attribute on Visualforce components to update the component without updating the entire page.

2. Use JavaScript Remoting to call functions in your controller through JavaScript, and to retrieve ancillary or static data.

3. Create a custom component to show and hide data according to user actions.

When lazy loading pages, consider the number of users and amount of data you expect to use the page, and watch out for limits like the concurrent API call limit. For example, if a navigation tree only loads elements as needed, the number of queries might end up out of proportion to the data.


What operations are considered in DML count in Salesforce Governor Limits?

Calls to the following methods count against the number of DML queries issued in a request.

delete and Database.delete
insert and Database.insert
merge and Database.merge
undelete and Database.undelete
update and Database.update
upsert and Database.upsert

For more info, check the below link



How to Query Currency Fields in Multi-currency Organization in Salesforce?

Use convertCurrency() in the SELECT statement of a SOQL query to convert currency fields to the user’s currency. This action requires that the org has multiple currencies enabled.

You can’t use the convertCurrency() function in a WHERE clause. If you do, an error is returned.

Sample Queries:

SELECT Id, convertCurrency(AnnualRevenue) FROM Account

The above query will return AnnualRevenue in the user's currency.

SELECT Id, Name FROM Opportunity WHERE Amount > USD5000

In this example, opportunity records are returned if the record’s currency Amount value is greater than the equivalent of USD5000.

Check the below link for more details



Expected Revenue and Amount Fields

Amount is the Opportunity's worth.

Expected Revenue is a formula field. Expected Revenue = Amount * Probability.


How to roll-up in lookup relationship - Rollup Helper AppExchange product

1. Go to the below link


2. Click "Get It Now".

3. Click "Login in to the AppExchange".

4. Click "Install in Production".

5. Click "Confirm and Install".

6. Click "Install".

Let's see how to create roll-up fields in Lookup relationship. I have two object Employee and Hobby which are related by Lookup relationship.

1. Go to "Enable Real Time" tab.


3. Click "Create Rollup".

4. Select the object for Rollup. This should be the parent object.

5. Select the field to store the value.

6. Select the child object and its field for roll-up. Click "Save and Run".


How to delete all the records from an Object in Salesforce?

Truncating a custom object permanently removes all of its records. You can’t recover the records from the Recycle Bin. A copy of the truncated object appears in the Deleted Objects list for 15 days—during this period the object and its records continue to count toward your organization’s limits—and then the copied object and its records are permanently deleted.

1. Go to Create --> Objects.

2. Select the object to Truncate.

3. Click "Truncate" button.

4. Enter the object name not the API name and click "Truncate".


The reference to entity must end with the delimeter Apache ANT tool Salesforce

This issue is caused due to unsupported character in your component name.

For example, if your component name is P&W, replace & with &amp;. So, it will look like P&amp;W.

After retrieving, change the file name to P&W.


When running an Apex test, which type of Apex syntax in tested code is counted in the code coverage calculation?

1. Variable Assignment

2. Apex codes

3. If, for, etc.. loops

4. Inside the If loop, if condition matches

5. Inside for loop, if condition satisfies


What is the name of the standard relationship from Account down to Contact in Salesforce.com?

The name of the standard relationship from Account down to Contact is Contacts.


Which method is defined in the StandardController class?

The action methods that are supported by all standard controllers.

1. save
2. quicksave
3. edit
4. delete
5. cancel
6. list

Check the below link for more info



What is the return type of a SOSL search?

The return type of a SOSL search is List of List of sObjects.

Sample Code:

List<List<SObject>> searchList = [FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead];
Account [] accounts = ((List<Account>)searchList[0]);
Contact [] contacts = ((List<Contact>)searchList[1]);
Opportunity [] opportunities = ((List<Opportunity>)searchList[2]);
Lead [] leads = ((List<Lead>)searchList[3]);


What is the use of transient keyword in Salesforce?

Declaring variables as transient reduces view state size. A common use case for the transient keyword is a field on a Visualforce page that is needed only for the duration of a page request, but should not be part of the page's view state and would use too many system resources to be recomputed many times during a request.

The transient variables are not passed to view state and therefore not stored in View State.

Check the below link for more info



Salesforce Certifications

Salesforce certification exams recognize experience as well as study.

Getting certified boosts your career and enables you to contribute even more to your organization's success.

Check the below link for Salesforce Certifications



How to schedule same Scheduler Class twice or thrice or multiple times in Salesforce?

Sample Code:

SchedulerClass obj = new SchedulerClass();
String cron = '0 30,30,30 8,12,15  * * ? *';
System.schedule('SchedulerClass', cron, obj);

In the above example, SchedulerClass will run daily at 8.30 AM, 12.30 PM and 3.30 PM.

To know more about scheduling, please check the below link



How to set created date for a test record in test class in Salesforce?

Sample Code:

     Employee__c emp = new Employee__c(Employee_Name__c = 'Testsing');  
     insert emp;  
     Test.setCreatedDate(emp.Id, DateTime.newInstance(2000,10,10));  

Check the below link for more information



How to get Username of the user using Apex?

Sample Code:



How to get Sandbox name using Apex?

Sample Code:



How to check Sandbox or Production using Apex?

Option 1:

Sample Apex Class:

public class Utility {

    public static Boolean sandboxBool;
    public static Boolean isSandbox() {
        if ( sandboxBool == null ) 
        sandboxBool = URL.getSalesforceBaseUrl().getHost().left(2).equalsignorecase('cs');
        return sandboxBool;


Controller/Trigger calling:

system.debug(' o ' + Utility.isSandbox());

Option 2:

Sample SOQL:

SELECT Id, IsSandbox, Name FROM Organization LIMIT 1

If IsSandbox is true, then it is Sandbox else it is Production.

Insufficient Privileges when Visualforce page is accessed

1. Go to the user's profile.

2. Select Visualforce page Access.

3. Click Edit button.

4. Add the Visualforce page to the right panel.

5. Click Save.


ActiveXObject date formatting

ActiveXObject always return JAVASCRIPT date format. In order to format it for your requirement, we can get the month, date and year to format it.

Sample Code:

if ( String(XLSheet.Cells(rowIndex, colIndex).value).indexOf(' UTC') != -1 || String(XLSheet.Cells(rowIndex, colIndex).value).indexOf(' GMT') != -1) {
var dt = new Date(XLSheet.Cells(rowIndex, colIndex).value);
var st = (dt.getMonth() + 1).toString() + '/' + dt.getDate() + '/' + dt.getYear();

here st returns the date in MM/DD/YYYY format.


JAVASCRIPT to read excel

Sample Code:

function ReadExcelFile() {
var fileUrl;
var rowIndex;
var colIndex;
var workSheetCount;
var XLSheet;
fileUrl = document.getElementById("hdnFileName").value;
objExcel = new ActiveXObject("Excel.Application");
//alert("Excel Obj Created");
objWorkbook = objExcel.Workbooks.Open(fileUrl);
//alert("Excel Workbook Created");
workSheetCount = objExcel.Worksheets.Count;
XLSheet = null;
for(var Iter = 1; Iter < workSheetCount; Iter++) {
XLSheet = objExcel.Worksheets(Iter);
for(rowIndex = 1; rowIndex <= 5 ; rowIndex++) {
for(colIndex = 1; colIndex <= 5; colIndex++) {
alert(XLSheet.Cells(rowIndex, colIndex).value);


JAVASCRIPT reading excel cell value as date

In order to read excel cell value as it is there in the cell instead of date, remove .value. So, that it will just read the value as it is in the cell instead of formatting it.

Replace XLSheet.Cells(rowIndex, colIndex).value to XLSheet.Cells(rowIndex, colIndex).

Just remove .value, so that it will return the value as it is there in the excel file.

If the above solution didn't work, use the below link to format the date