+ Start a Discussion
Semira@gmail.comSemira@gmail.com 

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>();
        //addrow();
         }

    public void addrow(){
   
        Expense_Line_Item__c exp = new Expense_Line_Item__c();
      
        expense.add(exp);
     
    }
           
    public void removerow(){
        Integer i = expense.size();
        expense.remove(i-1);}
           
    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;
             expense.clone();
         }
            
       
          Integer count = 0;
          count = expense.size();
          system.debug('count:::::::::::::::::::'+count);
          //expense[0].test_c = LI.expense_c;
          insert expense;
        
        PageReference parrec = new PageReference('​/apex/expense');
        parrec.setRedirect(true);
        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:pageBlockButtons>

    <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:pageblockSection>
  
    <apex:actionRegion immediate="true">
            <apex:pageBlockSection title="Additional Contacts" >
         
            <apex:commandButton value="Add Contact" action="{!addrow}" reRender="table"/>
           <br/>
           <br/>
             <apex:pageBlockTable value="{!expense}" var="a" id="table">              
                <apex:column headerValue="Contact">
                    <apex:inputField value="{!a.Contact__c}" required="false"/>
                </apex:column>                                      
            </apex:pageBlockTable>
            </apex:pageBlockSection>
            </apex:actionRegion>             
   
</apex:pageBlock>
</apex:form>
</apex:page>


What am I doing wrong???
Best Answer chosen by Semira@gmail.com
Sure@DreamSure@Dream
Hi,

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


Thanks,

All Answers

Sure@DreamSure@Dream
Hi,

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


Thanks,
This was selected as the best answer
Semira@gmail.comSemira@gmail.com
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 salesforce.com".  
Sure@DreamSure@Dream
 first comment that part in vf page and save.Then change the method name in controller..
Semira@gmail.comSemira@gmail.com
Thank you very much. That worked. Now I just have to figure out why doesn't it create duplicate records.