SFDC Coding Start Up:-
Hi Friends,
This is very useful for Developers who is very new to Coding.
How To create a Visual force Page/Apex class :-
YourName-->Setup --> App Setup --> Develop --> Pages/ Apex classes --> Name of that page
(OR)
Go with the URL
ap1.salesforce.com/apex/ExamplePage
Then after If you want to see your output..:-
You should go Using URL only
Types of Controllers:-
Standardcontroller :- StandardController objects reference the pre-built Visualforce
controllers provided by salesforce.com.
Controller :- A custom controller is an Apex class that implements all of the logic for
a page without leveraging a standard controller.
Extension controller :- A controller extension is an Apex class that extends the functionality
of a standard or custom controller.
Using Standard Controller:-
Here We have a scenario , i.e Save a record using VF page.
<apex:page standardController="Account"> <apex:form > <apex:pageBlock title="My Content" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!cancel}" value="cancel"/> </apex:pageBlockButtons> <apex:pageBlockSection title="My Content Section" columns="2"> <apex:inputField value="{!account.name}"/> <apex:inputField value="{!account.ParentPickList__c}"/> <apex:inputField value="{!account.type}"/> <apex:inputField value="{!account.AccountNumber}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Using Controller:-
so here is the simple code for Calculator . I am using Controller with Action methods.
<apex:page controller="calculator">
<apex:form >
<apex:pageBlock >
Enter Va1ue1: <apex:inputText value="{!Value1}"/>
Enter Value2: <apex:inputText value="{!Value2}"/><br/>
Value1OutPut:<apex:OutputText value="{!Value1}"/><br/>
Value2OutPut:<apex:OutputText value="{!Value2}"/><br/>
Your Result :<apex:outputText value="{!OutputValue}"/>
<apex:pageBlockButtons >
<apex:commandButton value="Add" action="{!Add}"/>
<apex:commandButton value="Sub" action="{!Sub}"/>
<apex:commandButton value="Mul" action="{!Mul}"/>
<apex:commandButton value="Div" action="{!Div}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
public class calculator
{
public String getNum1() {
return null;
}
Integer num1,num2,num3;
public Void SetValue1(Integer v1)
{
num1=v1;
}
public Integer getValue1()
{
return num1;
}
public void SetValue2(Integer v2)
{
num2=v2;
}
public Integer getValue2()
{
return num2;
}
public Integer getOutputValue()
{
return num3;
}
public void Add()
{
system.debug('<------------METHOD IS CALLING---------->');
num3=num1+num2;
}
public void Sub()
{
system.debug('<------------METHOD IS CALLING---------->');
num3=num1-num2;
}
public void Mul()
{
system.debug('<------------METHOD IS CALLING---------->');
num3=num1*num2;
}
public void Div()
{
system.debug('<------------METHOD IS CALLING---------->');
num3=num1/num2;
}
}
Using Extension Controller:-
so here is the simple code for Saving record. Please note that I've used standard controller
("Account" in the code) Instead of save Button I am using My Logic for saving the record.
("Account" in the code) Instead of save Button I am using My Logic for saving the record.
<apex:page standardController="Account" extensions="MyOwnLogic"> <apex:form > <apex:pageBlock title="My Content" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!Logic}" value="MyLogic"/> <apex:commandButton action="{!Cancel}" value="Cancel"> </apex:commandButton> </apex:pageBlockButtons> <apex:pageBlockSection title="My Content Section" columns="2"> <apex:inputField value="{!account.name}"/> <apex:inputField value="{!account.site}"/> <apex:inputField value="{!account.type}"/> <apex:inputField value="{!account.accountNumber}"/> <apex:inputField value="{!account.ParentID}"/> <apex:inputField value="{!account.SLASerialNumber__c}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
public class MyOwnLogic { Account AccRec; String VarStr; public MyOwnLogic(ApexPages.StandardController abc) { AccRec=(Account)abc.getRecord(); } public void Logic() { System.debug('Account Values---------->'+AccRec.name); VarStr=ApexPages.currentPage().getParameters().get('txt'); system.debug('URL VALUE------------->'+VarStr); upsert AccRec; } }
No comments:
Post a Comment