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
ali-kantar1.3897183320927883E12ali-kantar1.3897183320927883E12 

what am i missing because its still not letting me save the record ?

<apex:page controller="worldcup">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{!wc.Name}"/>
<apex:inputField value="{!wc.who_is_going_to_win__c}"/>
<apex:commandButton action="!{Save}" value="save"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

this is my VF page and the method i have used is :

public class worldcup {

    public worldcup() {

    }

public WorldCup__c wc;

public worldcup (ApexPages.StandardController controller) {
this.wc = (WorldCup__c)Controller.getRecord();
}

public WorldCup__c getwc(){
    return wc;
    }
   
    Public PageReference save(){
   
   WorldCup__c wc=[Select id,Name, who_is_going_to_win__c From WorldCup__c];
  
   upsert wc;
    return null;
    }

}

after i submitted a record on the VF page i recieved an error saying Formula Expression is required on the action attributes. am i missing the save attribute ? 
Best Answer chosen by ali-kantar1.3897183320927883E12
GlynAGlynA
<pre>
<apex:page standardController="WorldCup__c">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection >
            <apex:inputField value="{!WorldCup__c.Name}"/>
            <apex:inputField value="{!WorldCup__c.who_is_going_to_win__c}"/>
            <apex:commandButton action="{!save}" value="Save"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>
</pre>

All Answers

kevin lamkevin lam
You need to change this
<apex:commandButton action="!{Save}" value="save"/>
to
<apex:commandButton action="{!save}" value="save"/>
GlynAGlynA
I see a few issues with the code.  First, since you're using the "worldcup" class as a controller, there will be no standard controller.  The class will be constructed using the no-argument constructor, which doesn't do anything.  "wc" will remain null.

In the VF code, the error you're getting is because you have

action="!{Save}"

it should be

action="{!Save}"

Then, in the save method, you are querying the record, which will overwrite any input that the user has made.  The record will be saved unmodified.

In fact, everything you want to do can be done using the standard controller.  You don't need the "worldcup" class at all.  The code in the next post shows how to do this.

Glyn Anderson
Sr Developer | System Analyst | ClosedWon | closedwon.com
Certified Developer | Certified Advanced Administrator
Blog: GlynATheApexGuy@blogspot.com
Twitter: @GlynAtClosedWon
GlynAGlynA
<pre>
<apex:page standardController="WorldCup__c">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection >
            <apex:inputField value="{!WorldCup__c.Name}"/>
            <apex:inputField value="{!WorldCup__c.who_is_going_to_win__c}"/>
            <apex:commandButton action="{!save}" value="Save"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>
</pre>
This was selected as the best answer
ali-kantar1.3897183320927883E12ali-kantar1.3897183320927883E12
how does this work i am confused because WorldCup__c is an custom object how are you able to use a standard controller for it ? 


GlynAGlynA
Standard controllers are auto-generated for custom objects.  They support basic functionality like "save" and "cancel".  See the VisualForce Developers Guide, http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_controller_std.htm (http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_controller_std.htm" target="_blank), for more information.

-Glyn