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 

Visualforce Error: Formula Expression is required on the action attributes.

Hi, I have a requirement to write an extension that will create multiple records by cloning the records and inserting different contacts with one click of a button. 

So I wrote my controller going through for loop that will look for more records in a list, insert the contact and parent ID and then clone the record. But maybe this is not the way to do it? I'm getting Visualfoce error. I have no idea what it means. My page reference looks correct.

Please help! It is kind of urgent so any help is appreciated. 

Here's my controller: 

public class ContactInsert
    public List<Expense_Line_Item__c> expense {get; set;}
    private final Expense_Line_Item__c LI;
    public ContactInsert(ApexPages.StandardController myController) {
        this.LI = (Expense_Line_Item__c)myController.getRecord();
        expense = new List<Expense_Line_Item__c>();

    public void addrow(){
        Expense_Line_Item__c exp = new Expense_Line_Item__c();
    public void removerow(){
        Integer i = expense.size();
    public PageReference save() {
     /*   List<Expense_Line_Item__c> listexpense = new List<Expense_Line_Item__c>();
        Account acct = [Select id, name from Account where id=:LI.expense__c];
        //Contact con =[Select id, name from Contact where id=:LI.contact__c];
        //Expense_Line_Item__c exp = new Expense_Line_Item__c();
        for(Expense_Line_Item__c exp :expense)
             Contact con =[Select id, name from Contact where id=:LI.contact__c];
             LI.expense__c = acct.ID;
             LI.contact__c = con.ID;
          Integer count = 0;
          count = expense.size();
          //expense[0].test_c = LI.expense_c;
          insert expense;
        PageReference parrec = new PageReference('​/apex/expense');
        return parrec; }

Here's my Visualforce Page:
<apex:page StandardController="Expense_Line_Item__c"  extensions="ContactInsert" standardStylesheets="true" >
<apex:form >
<apex:pageBlock >

    <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!Save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>

    <apex:pageblockSection >
                <apex:inputField value="{!Expense_Line_Item__c.Expense__c}" />
                <apex:inputField value="{!Expense_Line_Item__c.Name}"/>
                <apex:inputField value="{!Expense_Line_Item__c.Date_of_Expense__c}" />
                <apex:inputField value="{!Expense_Line_Item__c.Contact__c}" />                  
                <apex:inputField value="{!Expense_Line_Item__c.Amount__c}"/>
    <apex:actionRegion immediate="true">
            <apex:pageBlockSection title="Additional Contacts" >
            <apex:commandButton value="Add Contact" action="{!addrow}" reRender="table"/>
             <apex:pageBlockTable value="{!expense}" var="a" id="table">              
                <apex:column headerValue="Contact">
                    <apex:inputField value="{!a.Contact__c}" required="false"/>

What am I doing wrong???
Best Answer chosen by

Change the method name to something else and see..instead of save().


All Answers


Change the method name to something else and see..instead of save().

This was selected as the best answer
Unfortunately, it doesn't work. it gives me error saying "ContactInsert Compile Error: The method System.PageReference save() is referenced by Visualforce Page (expense) in".  
 first comment that part in vf page and save.Then change the method name in controller..
Thank you very much. That worked. Now I just have to figure out why doesn't it create duplicate records.