Alert button in Visualforce page in Salesforce

Sample Code:

Visualforce page:

<apex:page controller="SampleController">
        function callSave(){
            var r = confirm("Are you sure want to save?");
            if(r == true) {                
    <apex:form >
        <apex:actionFunction name="callSav" action="{!sav}"/>
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:inputField value="{!member.Name}"/>
                <apex:inputField value="{!member.E_Mail_Id__c}"/>
                <apex:inputField value="{!member.State__c}"/>
                <apex:inputField value="{!member.City__c}"/>
                <apex:inputField value="{!member.Age__c}"/>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" onclick="callSave();"/>

Apex controller:

public class SampleController {
    public Member__c member {get;set;}
    public SampleController() {
        member = new Member__c();
    public void sav(){
        insert member;
        member = new Member__c();



How to create DateTime with time as 00:00:00 using Apex in Salesforce?

Sample Code:

Datetime myDate = Datetime.newInstanceGMT(2008, 12, 1, 0, 0, 0);
system.debug('Value is ' + myDate);


How add n days to a date field using formula in Salesforce?

Just add n days to the Date field in the formula field. Kindly select Date while creating a formula field.

How to compare old field value with the next field value in Salesforce?

Sample Trigger:

trigger emailCheck on Employee__c (before update)
    Map<Id,Employee__c> o = new Map<Id,Employee__c>();
    o = trigger.oldMap;
    for(Employee__c n :
        Employee__c old = new Employee__c();
        old = o.get(n.Id);
        if(n.Email__c != old.Email__c)
            n.Email__c.addError('Email cannot be changed');


How to enable as Knowledge user in Salesforce?

Knowledge User checkbox on the user detail:
By default, all internal users with Read permission can read published articles.

Lightning Knowledge uses user profile permissions or permissions sets to give agents access to authoring actions. In contrast, Knowledge in Salesforce Classic uses public groups and article actions.

To do more than read articles, agents need the Knowledge User license.

Go to My Settings --> Personal --> Advanced User Details, Click edit and check " Knowledge user" check box is enabled.

Simple AJAX in Salesforce


The relationship between Member and Interests is Master Detail. One member can have multiple interests.

Check Valid Interests button will say whether any interest under the Member is active using AJAX.

Custom Detail page Button:

Button Javascript code:


var soql = "SELECT InfallibleTech__Active__c FROM  InfallibleTech__Interest__c WHERE InfallibleTech__Member__c = '{!InfallibleTech__Member__c.Id}'";

result = sforce.connection.query(soql);
records = result.getArray("records");
var check = "false";

if(records.length > 0){
    for (var i=0; i < records.length; i++) {
        var record = records[i];
        if(record.InfallibleTech__Active__c == "false"){
            check = "true";
        } else{
            check = "false";
} else {
    check = "true"

if(check == "true"){
    alert("No active interests");
} else {
    alert("Active interests are present");


With Active interests:

With No Active interests:

How to find number of lines covered and uncovered in Apex class using SOQL?


SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate ORDER BY ApexClassOrTrigger.Name ASC


How to disable Quick Access Menu in Salesforce?

How to enable Quick Access Menu in Salesforce?

1. Go to My Settings.

2. Select Personal and Advanced User Details.

3. Click "Edit".

4. Enable " Quick Access Menu".


How to avoid Recursive Trigger in Salesforce?

Sample Trigger:

trigger AccountTrigger on Account(after insert, after update){

Sample Classes:

Class for Trigger Handler: 

public class AccountHandlerController{
                CommonUtility.check = false;
        public static perform(List<Account> listAccount){
         for(Account acct : listAccount){
        update listAccount;

Class for storing boolean variable

public class CommonUtility{
        public static Boolean check = true;

If the Boolean variable is not used inside the class, it will cause infinite loop and we will face "maximum trigger depth exceeded exception" in Salesforce.

The boolean variable should be set to false first and not at the last.


maximum trigger depth exceeded exception in Salesforce

"maximum trigger depth exceeded" exception in Salesforce occurs mainly due to recursion.

Kindly implement a static variable in a class to avoid recursion.

Check the below site to avoid recursion in triggers


How to open child records list from custom button on parent object?

Custom Button:

Visualforce page:

<apex:page controller="InterestListController">
    <apex:pageBlock >
        <apex:pageBlockTable value="{!listInterest}" var="int">
            <apex:column value="{!int.Name}"/>
            <apex:column value="{!int.Description__c}"/>

Apex Controller:

public class InterestListController {
    Id memId;
    public List<Interest__c> listInterest {get;set;}
    public InterestListController(){
        listInterest = new List<Interest__c>();
        memId = ApexPages.currentPage().getParameters().get('memId');
        listInterest = [SELECT Name, Description__c FROM Interest__c WHERE Member__c = : memId];


How to enable My Settings in Salesforce?

Go to Customize --> User Interface and enable "Enable Improved Setup User Interface" check box.

Advantages of using Apex Data Loader


1. An easy-to-use wizard interface

2. An alternate command line interface

3. A batch mode interface with database connectivity

4. Drag-and-drop field mapping(from .csv file to Salesforce object)

5. Detailed success and error log files in CSV format which avoid reworks

6. A built-in CSV file viewer

7. Security token will be used as an additional security measure, if we are trying to load data outside our network.


Data Types Supported by Data Loader

Data Types Supported by Data Loader:

1. Base64

2. Boolean

3. Date

4. Double

5. ID

6. Integer

7. String


What are all the limitations in Apex Data Loader?

1. Supports large files up to 5 million records.

2. Data Loader currently does not support the extraction of attachments. As a workaround, we recommend that you use the weekly export feature in the online application to export attachments.

3. Not supported in MAC Operating System.

4. Supports only .csv files.


Getting Started with Salesforce's Apex Data Loader

The Data Loader is an easy to use graphical tool that helps you to get your data into Salesforce objects. The Data Loader can also be used to extract data from database objects.

Data Loader is mainly used for bulk import and export.

When to use Data Loader:

Data loader is used when
1. You need to insert or update or delete bulk amount of data.
2. You need to load 50,000 to 5,000,000 records. Data Loader is supported for loads of up to 5 million records.
3. You need to load into an object that is not yet supported by the import wizards.
4. You want to schedule regular data loads, such as nightly imports.
5. You want to export your data for backup purposes.

How to Download Data Loader?

1. Go to Setup --> Administer --> Data Management -- > Data Loader.

Operations Supported:

1. Insert - We can bulk insert new records into our Salesforce organization.

2. Update - We can bulk update existing records in our Salesforce organization.

3. Upsert - We can insert and update together using Salesforce Record Id or External Id field.

4. Delete - We can bulk delete existing in our Salesforce organization.

5. Hard  Delete - If we use Delete, the deleted records will be stored in Recycle Bin. But if we use Hard Delete, deleted records will not be available in Recycle Bin. Hard Delete is permanent delete.

6. Export - We can bulk export records in .csv file format.

7. Export All - If we use Extract, records from Recycle Bin will not be exported, but in Export All, the records from Recycle Bin will also be included in the exported .csv file.

Limitations in Data Loader:

1. Supports large files up to 5 million records.

2. Data Loader currently does not support the extraction of attachments. As a workaround, we recommend that you use the weekly export feature in the online application to export attachments.

3. Not supported in MAC Operating System.

4. Supports only .csv files.

Recommendations and Suggestions:

1. Take a backup of your records before updating and deleting.

2. Review the success and error files.

3. If out of 100 records, 90 got inserted or updated and 10 records got some error, view the error file. Do the necessary changes by seeing the errors mentioned in Error column and then insert or update that 10 records alone instead of roll back and starting it from again.

Data Types Supported by Data Loader:

1. Base64
2. Boolean
3. Date
4. Double
5. ID
6. Integer
7. String

Salesforce Interview questions with answers Part 24

1. What is the use of webtabs?

2. Business process in salesforce?

Lead --> Account, Contact and Opportunity and then Case and Lead.

3. Do we have sales process in Salesforce?


4. What is the difference between Default Internal Access and Default External Access?

5. Can we able to create the more than one Search Layout?


External Organization-Wide Defaults in Salesforce

External organization-wide defaults provides separate organization-wide defaults for internal and external users. It simplifies your sharing rules configuration and improve recalculation performance. Additionally, administrators can easily see which information is being shared to portals and other external users.

Separate organization-wide defaults is available for these objects.

  • Accounts and their associated contracts and assets
  • Cases
  • Contacts
  • Opportunities
  • Custom Objects
  • Users

External users include:

  • Authenticated Website users
  • Chatter External Users
  • Customer Portal users
  • Guest users
  • High-Volume Portal Users
  • Partner Portal users
  • Service Cloud Portal users
This feature is not enabled in your organization by default. For information on enabling it, contact

How to enable order in Salesforce?

1. Go to Customize --> Orders --> Settings.

2. Check Enable check box.

3. Select the layouts where we can have Orders related list.

How to deploy using

1. Log into the organization from which we want to move.

2. Click "Switch Mode".

3. Select "Push".

4. Select the filter.

5. Select the component from the left panel and add it to the right panel.

6. Click "Retrieve" button.

7. The zip folder with the name "retrieve" will be downloaded.

8. Log in to the organization in which the components should be deployed.

9. Drag and drop the retrieve zip folder.

Cheers!!! is a salesforce ide in the cloud.

It is fast, free, and easy to use. No signup is required.

Using this IDE we can create and modify the class in a minute. This tool do the activities so quick.

1. Go to

2. Select the organization.

3. Enter your login credential.

4. Select "New Apex Class".

5. Enter the name for the class and press Ctrl + S to save it.


CRM tutorial

Trigger to add Opportunity owner in Opportunity team

Sample Trigger:

trigger OpportunityTrigger on Opportunity (after insert) {
    List<OpportunityTeamMember> listOpptyTeamMem = new List<OpportunityTeamMember>();
    for(Opportunity oppty : trigger.New){
        OpportunityTeamMember OTM = new OpportunityTeamMember();
        OTM.OpportunityId = oppty.Id;
        OTM.TeamMemberRole = 'Sales Rep'; 
        OTM.UserId = oppty.OwnerId;
    if(listOpptyTeamMem.size() > 0){
        insert listOpptyTeamMem;

Approval process through Visual Workflow in Salesforce


How to start renumbering every day in Salesforce?

Sample Trigger:

trigger MemberTrigger on Member__c (before insert) {
    Integer count = 0;
    List<Member__c> listMember = new List<Member__c>();
    listMember = [SELECT Id FROM Member__c WHERE CreatedDate > :];
    system.debug('Size is ' + listMember.size());   
    if(listMember.size() > 0){
        count = listMember.size();

    for(Member__c mem : trigger.New){
        count += 1;
        mem.Today_s_Count__c = count;


Salesforce Interview questions with answers Part 23

1. How to add SOQL in Visualforce page?

Using AJAX in Javascript.

2. How to send parameter from one page to another page in Salesforce?

At the end of the url, you can pass the parameter.


3. Write a trigger to roll up sum of amount from opportunities to Account "Total Amount"?

4. How to find users in Schedule Future Runs in Reports in Salesforce if it is not available?

5. How code coverage is calculated in Salesforce?


Visual Workflow in Salesforce

Visual Workflow allows administrators to build applications, known as flows, that guide users through screens for collecting and updating data. For example, you can use Visual Workflow to script calls for a customer support center or to generate real-time quotes for a sales organization.

Visual Workflow has three different aspects: flow design, flow management, and runtime. As an administrator, you create the flows using the Cloud Flow Designer, which has a drag-and-drop user interface that lets you diagram flow structure and configure how it runs, without writing any code. Once you create a flow, you can manage it in Salesforce, edit its properties, activate, deactivate, delete, or run it at will. Flow users can then run the active flow from a custom button, tab, link, or directly from the flow URL.

Lets see a simple Visual Workflow implementation.

1. Go to Create --> Workflow & Approvals --> Flows.

2. Drag and drop a Screen element.

3. Enter the required information in General Info tab.

4. Drag and drop required fields in Add a Field tab.

5. In Field Settings tab, provide the field properties.

6. Similarly create a screen for child object.

7. Drag and Drop required DML operation element.

8. Map it with the correct object.

9. Map it with the correct fields.

10. Create a variable to store the member id.

11. Similarly for Interest object do the same and create a variable for storing Interest Id. Create a output screen to show the output.

12. Assign the flow.

13. Set the starting element.

14. Save the Flow.

15. Run the Flow.