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.