function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
santhoshreddy vanchasanthoshreddy vancha 

how to write functionality with standard controller to save,edit,delete svaing infomation go to edit page ?

Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Santhoshreddy,
Please refer the below code Functionality with a standard controller.

Apex Class:
public without sharing class AccountController {
	public Account account{get; set;}
	public AccountController(){
		account = new Account();
	}
	
	public void save(){
		upsert account;
	}
}
VisualForce Page:
<apex:page controller="AccountController">
    <apex:form>
        <apex:pageBlock title="My Content" mode="edit">
            <apex:pageBlockButtons>
                <apex:commandButton action="{!save}" value="Save"/>
            </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:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Hope it will be helpful.

Best Regards
Rahul Kumar

 
Javwad AzeemJavwad Azeem

Hi santhoshreddy,

you can create a method to override the standard buttons:-

Here is the sample code:-

Visualforce Page:- 

<apex:page standardController="Project__c" extensions="YourClassname" showHeader="true" >
<apex:pageBlockButtons >
                <center>  
                    <apex:commandButton action="{!save&new}" Value="Save&New" />
                </center> 
            </apex:pageBlockButtons>

<apex:page>

Apex Controller:-
public with sharing class YourClassname
{
private ApexPages.StandardController stdController  { get; set; }

public Project__c Pro { get; set; }
   
    public YourClassname(ApexPages.StandardController controller) {
        
         stdController = Controller;
                 
    }
public PageReference save&new() {
        
        PageReference detailPage = stdController.save();
        Pro = (Project__c)stdController.getrecord();
        // Construct URL of edit page or whatever the other page you want
        PageReference editPage = new PageReference('/apex/project?id='+Pro .Id);
        editpage.setRedirect(true);
        return editpage;
        
        }

}
 



Hope it will help.

Regards,
Javwad Azeem

santhoshreddy vanchasanthoshreddy vancha
yes i got i tired same way