Wednesday, September 21, 2016

GETTER AND SETTER METHODS - WHAT ARE THEY??

ell, once you start using a controller or an extension you will get used to these words...

So, it is good that we understand what these methods really do..

Getter and setter methods are used to pass data from your visualforce page to your controller and vice versa..

Let's take a very simple scenario... Let's assume you want to display a textbox in your visualforce page.. When the user enters some value in this textbox and clicks on a button you want the value entered by the user in your Apex class (ie. basically your controller or extension)

So go ahead and create a simple visualforce page.. the code for this would be
<apex:page controller="simplegetset">
  <apex:form>
    <apex:outputlabel value="Enter your name here"/>
       <apex:inputtext value="{!userinput}"/>          
  </apex:form>    
</apex:page>


The Apex code for this page would be...

public class simplegetset
{
    public String userinput{get; set;}
}


Now, the variable "userinput" in your Apex class will store the value entered by the user....

Let's analyze the methods now...

Get

The "get" method is used to pass data from your Apex code to your Visualforce page.. In our example we are not passing any value.. hence, when your page loads initially the textbox will have a empty value...

So, lets modify our code and pass a default value to the textbox.. Change the Apex code as follows..

public class simplegetset
{  
    public String userinput;
    public String getuserinput(){return 'John';}
   
    public void setuserinput(String userinput)
    {
        this.userinput = userinput;
    }   
}


You can now see that your page loads with a value 'John'...

Set

The "set" method is used to pass values from your visualforce page to the controller... In our example the variable "userinput" will be storing the value entered in the textbox..

Now modify your VF page as below..

<apex:page controller="simplegetset">
  <apex:form>
    <apex:outputlabel value="Enter your name here"/>
       <apex:inputtext value="{!userinput}">
           <apex:actionsupport event="onclick" rerender="display" />
       </apex:inputtext>                   
    <apex:outputpanel id="display">
        <apex:outputtext value="The name entered is {!userinput}"/>
    </apex:outputpanel>                   
  </apex:form>    
</apex:page>


The Apex code would be...

public class simplegetset
{
    public String userinput{get; set;}
}


In this example what happens is.. the variable "userinput" stores the value entered in visualforce page and passes it to the Apex code.. hence you are able to see the entered value in the visualforce page..

I guess you might understand what i am saying.. to make things simple now use the same visualforce page.. but modify the Apex code as below..

public class simplegetset
{  
    public String userinput;
    public String getuserinput(){return 'John';}
   
    public void setuserinput(String userinput)
    {
        this.userinput = userinput;
    }   
}


Now, whatever value you enter the page always displays "The name entered is John".... This is because your get method always returns 'John'... but still your set method will store the value you entered in the variable "userinput"...

Tuesday, September 13, 2016

Top Interview Questions


1.What is Apex ?
It is the in-house technology of salesforce.com which is similar to Java programming with object oriented concepts and to write our own custom logic.
2.What is S-Control ?
S-Controls are the predominant salesforce.com widgets which are completely based on Javascript. These are hosted by salesforce but executed at client side. S-Controls are superseded by Visualforce now.
3.What is a Visualforce Page ?
Visualforce is the new markup language from salesforce, by using which, We can render the standard styles of salesforce. We can still use HTML here in Visualforce. Each visualforce tag always begins with “apex” namespace. All the design part can be acomplished by using Visualforce Markup Language and the business logic can be written in custom controllers associated with the Page.
4.Will Visual force still supports the merge fields usage like S-control ?
Yes. Just like S-Controls, Visualforce Pages support embedded merge fields, like the {!$User.FirstName} used in the example.
5.Where to write Visualforce code ?
Ans: You can write the code basically in 3 ways.
1. setup->App Setup->Develop->Pages and create new Visulaforce page.
2.  Setup -> My Personal Information -> Personal Information -> Edit check the checkbox development mode. When you run the page like this, https://ap1.salesforce.com/apex/MyTestPage. you will find the Page editor at the bottom of the page. You can write you page as well as the controller class associated with it, there it self.
3.Using EclipseIDE you can create the Visulaforce page and write the code.
6.What are Apex Governor Limits?
Governor limits are runtime limits enforced by the Apex runtime engine. Because Apex runs in a shared, multitenant environment, the Apex runtime engine strictly enforces a number of limits to ensure that code does not monopolize shared resources. Types of limits that Apex enforces are resources like memory, database resources, number of script statements to avoid infinite loops, and number of records being processed. If code exceeds a limit, the associated governor issues a runtime exception.

Sunday, September 11, 2016

How to Update a field when a button is clicked on record level ?

Step 1.  Create  a custom button (name it as "Update Field") and select content source as  "Onclick Javascript "

Step 2 . Paste below code in it

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

var newRecords = [];
var c = new sforce.SObject("Account"); 
c.id ="{!Account.Id}";
c.NumberofLocations__c = '400';
newRecords.push(c); 
result = sforce.connection.update(newRecords);
window.location.reload();

Note: - Here NumberofLocations__c is a custom field

Step 3 . Open any account record 
Before Clicking UpdateField Button 



After Clickling UpdateField Button 
You will find value of Number of locations is changed from 6 to 400 as below 


Process Builder

Process Builder is a workflow tool that helps you easily automate your business processes by providing a powerful and user-friendly graphical representation of your process as you build it. 

The new Lightning Process Builder has two main features that stand out. The first is the huge amount of functionality the new process builder brings with it. Before, a process that might have taken 10 separate workflows to accomplish with different outcomes now only has to have one process. This is because we can have true and false actions for a criteria, which can then have true and false actions coming off them again. In addition to having multiple outcomes, the amount of actions available have increased, so now, we can post to chatter, launch flows, update record and (this is the BIG one), we can create records. Taking it one step further, we can also default some fields for these automatically created records.


The second feature is how the Process Builder brings a visual designer with it. In the diagram below, see  how you can bring workflows together to create complex processes to automate time-consuming tasks. This makes “old school” workflows look a bit antiquated, especially when you are creating workflows that interact with one another to set off a chain-like reaction.




From the diagram above, you can see how processes can be built quickly and simply. We start at the top and work our way through the diagram to see which actions will be triggered by what criteria. If you follow through this simple flow diagram, you can see that we are working with an account, and the criteria I have chosen is Account Type (my actual criteria is Account Type = Prospect). You can also see that when this criteria is true, I have made an immediate action to create an Opportunity.



Clicking on this ‘Create Opportunity” tab will open up a separate area, where I can choose to default as many fields as I like. Then we can have similar actions if the criteria equals false, and then test another criteria, and so on.

Synchronous and Asynchronous Messages

Synchronous Messages

Synchronous messaging involves a client that waits for the server to respond to a message. Messages are able to flow in both directions, to and from. Essentially it means that synchronous messaging is a two way communication. i.e. Sender sends a message to receiver and receiver receives this message and gives reply to the sender. Sender will not send another message until get reply from receiver.
Asynchronous Messages

Asynchronous messaging involves a client that does not wait for a message from the server. An event is used to trigger a message from a server. So even if the client is down , the messaging will complete successfully. Asynchronous Messaging means that, it is a one way communication and the flow of communication is one way only.

How to delete an apex class or trigger from production org in salesforce

Steps :
Step 1:Open the sandbox org in force.com IDE(Eclipse).
Step 2:Open the matching .xml file of the class/trigger which we need to delete and change the status XML tag from "Active" to "Deleted".
Step 3:Save the file and then deploy the main class as well as associated .xml file to production.

Quick start with Salesforce Lightning components

Step 1: Sign up for a Developer Edition Environment

2. Fill out the form, noting the following:a. Make sure to use an email address you can easily check right now.b. The username is in the form of an email address, but it doesn’t have to be the same as your email address. your.name@DF14.com is a perfectly good username, even if it isn’t your actual email address.

Step 2: Create a Namespace

Every Lightning component is prefixed by a namespace, so the first thing you need to do is
register for a unique namespace.
1. Click Setup | Create | Packages and then click Edit.
2. Click Continue.
3. Type a namespace and then click Check Availability to see if it’s unique.
4. Click Review My Selections and then Save.

Step 3: Enable Lightning Components

1. From Setup, click Develop | Lightning Components.
2. Select the Enable Lightning Components checkbox and click Save.

Step 4: Create a Lightning App

Bundles are like folders that hold related files. The first bundle you’ll create is an
app bundle.
1. In your Developer Edition (DE) environment, Click <your_name> and then Developer
Console.
2. Select File | New | Lightning Application.
3. Name it HelloWorld and click Submit.

Step 5: Edit the App

1. If HelloWorld.app isn’t open, click APPLICATION in the sidebar.
2. Add some HTML, such as My First Lightning App!
     <aura:application>
            <h1>My first Lightning app!</h1>

    </aura:application>

3. Save the app.


Step 6: Test the App

In the Developer Console, click the Preview button on the sidebar to open the app.

Step 7: Create a Component

As you just saw, you can place markup directly inside the app. However, putting it in a
component allows you to reuse it across different apps.

1. Select File | New | Lightning Component.
2. Type hello and then click Submit.
3. Add the following code and then Save.
     <aura:component>
          <h1>Hello World!</h1>
      </aura:component>

Step 8: Embed the Component in the App

1. In the Developer Console, open HelloWorld.app.
2. Add code to use your hello component.
    <aura:application>
           <jam:hello />
     </aura:application>
3. Make sure to replace the jam namespace with your own namespace. Then Save.
4. Click the Preview button on the sidebar to view the updated app.

Interview Questions-Part2

1) What is the advantage of using custom setting?
AnsYou donot have to query in apex(fire select query) to retrieve the data stored in custom settings.

2) what is whoid and whatid in activities?

Ans: Whoid is the id of either contact or lead.Whatid is the id of the related to record in activiity record(standard or custom object).

3) what is the difference between  a standard controller and custom controller?

Ansstandard controller inherits all the standard object properties,standard button functionalities can be directly used.Custom controller defines custom functionalities,a standard controller can be extended to develop custom functionalities using keyword "extensions".

4) Can you have more than one extension associated with a single page?
AnsYes we can have more than one extension.

5) If page is having extensions and if two extensions have methods of same name.Then which method out of these two will be called from vf page?
AnsThe one which is present in the controller defined on the left side will be called.

6) What are governer limits?
Ans: Governer limits are the limits impossed by salesforce so as to avoid monopoly by orgs in using salesforce shared resources.

7) What is the difference between force.com and salesforce.com?
Ans: force.com is paas(platform as a service) and salesforce.com is Saas(Software as a service)

8) How many records can a select query return?
AnsAs of now,it can return upto 50000 records.

9) How many records can a sosl query return?

AnsAs of now it can return upto 2000 records.

10) How can you access custom label in visualforce page?
AnsUse this syntax for accessing custom label in visualforce page - {!Label.LabelName} where LabelName is the name of Label.

11) How can you query all records(including deleted records) using an SOQL query?

AnsUsing ALL Rows Keyword.This will query all records including deleted records in recyclebin.
Eg:List <Account> accountList = [select id from account  ALL ROWS];

12) What is the use of @future annotation?

AnsUsing @future annotation with a method executes it whenever salesforce has resources available.

13) what is the significance of static keyword?
AnsMethods,variables when defined as static are initialized only once when class is loaded.Static variables are not transmitted as part of view state for a visualforce page

14) Can custom setting be accessed in a test class?
AnsCustom setting data is not available default in a test class.We have to set seeAllData parameter true while defining a test class as below
@isTest(seeAlldata=true).

15) what is the difference between role and profile?
AnsRole defines record level access while profile defines object level access.

16) Through Sales force Import wizard how many records we can import?

Ans : Using Import wizard, we can upload up to 50000 records.

17) Import wizard will support for which Objects?

Ans : Only Accounts, Contacts, Leads, Solutions and custom object’s data can be imported.  If we want to import other objects like Opportunities and other object’s data, then we need to go for Apex Data Loader.

18)  What is app exchange?

Ans : The developed custom applications can be uploaded into the app exchange so that the other person can share the applicaition.

19) What is a VLOOKUP in S.F?

Ans : VLOOKUP is actually a function in sales force which is used to bring relevant value to that record from another record automatically.

20) When I want to export data into SF from Apex Data Loader, which Option should be enable in Profile?

Ans : Enable API

21) What is a web - lead?

Ans : Capturing a lead from a website and routing it into lead object in Sales Force is called wed-lead (web to lead).

22) What are the Types of Account and difference between them?

Ans : We have two types of accounts.
Personal accounts
Business accounts

In personal accounts, person’s name will be taken as primary considerations where as in business accounts, there will be no person name, but company name will be taken into consideration.

23) What is a Wrapper Class in S.F?

Ans : A wrapper class is a class whose instances are collections of other objects.

24) What are formula and Rollup Summary fields and Difference between them? When should Rollup- Summary field enable?

Ans : 
Formula: A read-only field that derives its value from a formula expression that we define. The formula field is updated when any of the source fields change.

Rollup Summary: A read-only field that displays the sum, minimum, or maximum value of a field in a related list or the record count of all records listed in a related list.

25) What is a Sandbox? What are all the Types of sandboxex?

Ans : Sandbox is the exact replica of the production.

4 Types:
Developer
Developer Pro
Partial Copy
Full Copy

26)Difference between insert and Database.insert()

Ans : 

Database.insert() :


                             Using the  Database.insert()  we can specify whether or not to allow for partial record processing if errors are encountered .

                              It means even though errors are present while doing insert/update/delete operation,if we use Database methods, process will continue .

insert :


           Using the Insert statement we can not specify whether or not to allow for partial record processing if errors are encountered .

              It means if errors are present while doing insert/update/delete operation,the process will get stopped and error is thrown away. 

Sales Cloud & Services Cloud

1. "Sales Cloudrefers to the "sales" module in salesforce.com. It includes Leads, Accounts, Contacts, Contracts, Opportunities, Products, Price books, Quotes, and Campaigns . It includes features such as Web-to-lead to support online lead capture, with auto-response rules. It is designed to be a start-to-end setup for the entire sales process; you use this to help generate revenue.

While “Service Cloudrefers to the "service" (as in "customer service") module in salesforce.com. It includes Accounts, Contacts, Cases, and Solutions. It also encompasses features such as the Public Knowledge Base, Web-to-case, Call Center, and the Self-Service Portal, as well as customer service automation (e.g. escalation rules, assignment rules). It is designed to allow you to support past, current, and future clients' requests for assistance with a product, service, and billing. You use this to help make people happy.

2Sales Cloud Implements Sales and Marketing while Service cloud implements Salesforce Knowledge.

3. Sales Cloud ,A great solution for small and value oriented mid-sized sales groups that want to rapidly and cost effectively deploy Salesforce While Service Cloud  provides Customer Support to the Clients and giving you the tools to provide a better customer experience for your clients. 

4. Sales Cloud gives you the ability to open Cases (issues) and relate them to Accounts, Contacts; etc. While The Service Cloud is a superset of Sales Cloud, meaning you get everything that is in Sales Cloud PLUS some other features.

5.When we develop product in force.com for sales then it comes in Sales Cloud Ex: - Account, Contacts, and Lead.  While when we want to provide some facility and also provides support to the clients then it comes in Service CloudEx: - create cases is the example of Service Cloud in which client write his problem into cases instead of call.


Comparison table for Sales Cloud and Service Cloud functionality

How to delete existing Apex Scheduled jobs from Apex ?

Step 1 : Create a Apex Class and copy past the below code in it

         public class CronTrigger
           {
                public List<CronTrigger> listCronTrigger;
               public void testing()
              {
                   listCronTrigger = [select Id from CronTrigger  where ( CronJobDetail.Name like 'yourjobname')  limit 10];
           
                    System.debug('No of jobs: '+listCronTrigger.size());
    
                    If (listCronTrigger.size() > 0)
                   {
                             for (Integer i = 0; i < listCronTrigger.size(); i++)
                            { 
                                   System.abortJob(listCronTrigger[i].Id);
                                   System.debug('Job details ::'+String.valueOf(listCronTrigger[i]));
                            }
                     }
               }
          }

          Step 2 : Create a VF page and call testing method on load 

       On every page refresh 10 jobs will be deleted.

Salesforce Cheat Sheets

what is the difference between != null and != ' '

!= null checks if the value is equal to null 
!= ' '  will check for a blank

id field can be either hold a 15 or 18 digit id or can be null but not blank
for string use string.isblank() returns true if string is space ,empty or null

Is there a way to Print the Number of SOQL Queries in Debug During Runtime?

System.debug('Total Number of SOQL Queries allowed in this apex code context: ' +  Limits.getLimitQueries());



System.debug('Total Number of SOQL Queries fired in this apex code context: ' +  Limits.getQueries());

Disable Picklist field based on another picklist Value using JQuery In Visualforce

Sometime we want to disable picklist field based on another picklist field value like below.


In the above we can see if the Account Type is Partner then Industry Vertical (Picklist Field) is disable this can be achieved using below code.


<apex:page sidebar="false" standardController="Account">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!Account.Name}"/>
                <apex:inputField value="{!Account.Type}" id="type"/>
                <apex:inputField value="{!Account.Phone}" id="Phone"/>
                <apex:inputField value="{!Account.AccountNumber}" id="actNumber"/>
                <apex:inputField value="{!Account.Industry}" id="industry"/>
                <apex:inputField value="{!Account.AnnualRevenue}" id="anualReven"/>
                 
            </apex:pageBlockSection>   
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>   
        </apex:pageBlock>   
    </apex:form> 
    <script>
        $(window).load(function(){
            $("[id$=type]").change(function(){
                if(this.value=="Partner"){
                        $("[id$=Phone]").val("");
                        $("[id$=actNumber]").val("");
                        $("[id$=industry]").val("");
                        $("[id$=anualReven]").val("");
                      
                        $("input[id$=Phone]").prop("disabled",true);                       
                       $("[id$=Phone]").prop("disabled",true);
                        $("[id$=actNumber]").prop("disabled",true);
                        $("[id$=industry]").prop("disabled",true);
                        $("[id$=anualReven]").prop("disabled",true);
                      
                }
                else{
                      $("[id$=Phone]").prop("disabled",false);
                        $("[id$=actNumber]").prop("disabled",false);
                        $("[id$=industry]").prop("disabled",false);
                        $("[id$=anualReven]").prop("disabled",false);
                       
                }               
            });
        });
    </script>
</apex:page>