The custom controller in Salesforce:
When you want to override an existing functionality or you want to access information
based on certain logic or when you want the logic to run in system mode so that user
permission is not enforced we use custom controller or controller.
Inside controller, you can refer apex class. Only one apex class can be referred at a time.
Controller by default works in system mode. The apex class will have all of the logic.
Sample custom controller example to fetch contact, update it and save it to the database...
VISUALFORCE PAGE:
<apex:page Controller="customClass">
<apex:form >
<apex:pageBlock >
<apex:inputField value="{!contact.firstname}"/>
<apex:inputField value="{!contact.lastname}"/>
<apex:commandButton action="{!save}" value="save contact"/>
</apex:pageBlock>
</apex:form>
</apex:page>
CONTROLLER:
public class customClass{
public contact obj;
public customClass()
{
obj=[select firstname,lastname from contact limit 1];
}
public contact getContact()
{
return obj;
}
public pageReference save()
{
update obj;
return null;
}
}
**************************************************************************************************************
Custom controller in salesforce,Custom controller in visualforce,Custom controller salesforce,Custom controller visualforce.
**************************************************************************************************************
When you want to override an existing functionality or you want to access information
based on certain logic or when you want the logic to run in system mode so that user
permission is not enforced we use custom controller or controller.
Inside controller, you can refer apex class. Only one apex class can be referred at a time.
Controller by default works in system mode. The apex class will have all of the logic.
Sample custom controller example to fetch contact, update it and save it to the database...
VISUALFORCE PAGE:
<apex:page Controller="customClass">
<apex:form >
<apex:pageBlock >
<apex:inputField value="{!contact.firstname}"/>
<apex:inputField value="{!contact.lastname}"/>
<apex:commandButton action="{!save}" value="save contact"/>
</apex:pageBlock>
</apex:form>
</apex:page>
CONTROLLER:
public class customClass{
public contact obj;
public customClass()
{
obj=[select firstname,lastname from contact limit 1];
}
public contact getContact()
{
return obj;
}
public pageReference save()
{
update obj;
return null;
}
}
**************************************************************************************************************
Custom controller in salesforce,Custom controller in visualforce,Custom controller salesforce,Custom controller visualforce.
**************************************************************************************************************
No comments:
Post a Comment