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
kickingboykickingboy 

Saving mass edited records

I am trying to create VF page to mass edit and save a set of records. There is a pretty good discussion of the issue  here  

http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=8058#M8058

 

but both my objects (parent and child) are custom objects and I just cannot make it work. For example there does not seem to be a Selected method for custom objects so just using a standard controller will not work but if I use an extension I get the error message Unknown constructor 'EventsList.EventsList(ApexPages.StandardController controller)' if I use the recordsetVar attribute

 

My apex is

 

public class EventsList {
    public EventsList(ApexPages.StandardSetController controller) {

    }


   
 public PageReference save() {
     
    return null;
 }





  public Service__c getService() {
    return [select id, name,
             (select id, name, Actual_Fee__c, Actual_days__c, Employee__c from ServiceEvents__r limit 200)
             from Service__c where id =
             :ApexPages.currentPage().getParameters().get('Id') ];
}

public String getName() {
  return 'Events List';
  }
}

 

My VF is 

<apex:page standardController="Service_Event__c"  recordsetVar ="scheds" extensions="EventsList"  id="updateOwnerPage" tabstyle="Schedules__tab" sidebar="false">
  <apex:pageBlock title="Hello {!$User.FirstName}!">
        You are displaying Schedules.
       
    </apex:pageBlock>
    <apex:form >
        <apex:pageBlock mode="edit">
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!Service.ServiceEvents__r}" var="a">
                <apex:column value="{!a.name}"/>                                           
                <apex:column headerValue="Actual Fee">
                    <apex:inputField value="{!a.Actual_Fee__c}"/>
                </apex:column>
                <apex:column headerValue="Actual days">
                    <apex:inputField value="{!a.Actual_days__c}"/>
                </apex:column>
                <apex:column headerValue="Employee">
                   <apex:inputField value="{!a.Employee__c}"/>
                </apex:column>
                </apex:pageBlockTable>
        </apex:pageBlock>
     </apex:form>
</apex:page>

 

 

What am I not understanding?

Best Answer chosen by Admin (Salesforce Developers) 
kickingboykickingboy

OK this works

 public class EventsList {
    public Service_Event__c [] events = new Service_Event__c[0];
    public EventsList(ApexPages.StandardSetController controller) {
     
    }
 
 private PageReference pageRef;
 public PageReference save() {
    update events;
   return pageRef;
 }


  public Service_Event__c[] getevents(){
  for (Service__c S: [select id, name,
             (select id, name, Actual_Fee__c, Actual_days__c, Employee__c from ServiceEvents__r limit 200)
             from Service__c where id =
             :ApexPages.currentPage().getParameters().get('Id') ]){
             Service_Event__c[] Eevents = S.ServiceEvents__r;
             events = Eevents;
             pageRef = new pageReference('/' +ApexPages.currentPage().getParameters().get('Id'));

             }

     return events;
  }


  public Service__c getService() {
    return [select id, name
         //    (select id, name, Actual_Fee__c, Actual_days__c, Employee__c from ServiceEvents__r limit 200)
             from Service__c where id =
             :ApexPages.currentPage().getParameters().get('Id') ];
       }


}

 

 

<apex:page standardController="Service_Event__c"  recordsetVar="scheds" extensions="EventsList"  id="updateOwnerPage" tabstyle="Schedules__tab" sidebar="false">
  <apex:pageBlock title="Hello {!$User.FirstName}!">
        You are displaying Schedules {!Service.name}
        
    </apex:pageBlock>
    <apex:form >
        <apex:pageBlock mode="edit">
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!events}" var="a">
                <apex:column value="{!a.name}"/>                                            
                <apex:column headerValue="Actual Fee">
                    <apex:inputField value="{!a.Actual_Fee__c}"/>
                </apex:column>
                <apex:column headerValue="Actual days">
                    <apex:inputField value="{!a.Actual_days__c}"/>
                </apex:column>
                <apex:column headerValue="Employee">
                   <apex:inputField value="{!a.Employee__c}"/>
                </apex:column>
                </apex:pageBlockTable>
        </apex:pageBlock>
     </apex:form>
</apex:page>

All Answers

kickingboykickingboy

OK this works

 public class EventsList {
    public Service_Event__c [] events = new Service_Event__c[0];
    public EventsList(ApexPages.StandardSetController controller) {
     
    }
 
 private PageReference pageRef;
 public PageReference save() {
    update events;
   return pageRef;
 }


  public Service_Event__c[] getevents(){
  for (Service__c S: [select id, name,
             (select id, name, Actual_Fee__c, Actual_days__c, Employee__c from ServiceEvents__r limit 200)
             from Service__c where id =
             :ApexPages.currentPage().getParameters().get('Id') ]){
             Service_Event__c[] Eevents = S.ServiceEvents__r;
             events = Eevents;
             pageRef = new pageReference('/' +ApexPages.currentPage().getParameters().get('Id'));

             }

     return events;
  }


  public Service__c getService() {
    return [select id, name
         //    (select id, name, Actual_Fee__c, Actual_days__c, Employee__c from ServiceEvents__r limit 200)
             from Service__c where id =
             :ApexPages.currentPage().getParameters().get('Id') ];
       }


}

 

 

<apex:page standardController="Service_Event__c"  recordsetVar="scheds" extensions="EventsList"  id="updateOwnerPage" tabstyle="Schedules__tab" sidebar="false">
  <apex:pageBlock title="Hello {!$User.FirstName}!">
        You are displaying Schedules {!Service.name}
        
    </apex:pageBlock>
    <apex:form >
        <apex:pageBlock mode="edit">
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!events}" var="a">
                <apex:column value="{!a.name}"/>                                            
                <apex:column headerValue="Actual Fee">
                    <apex:inputField value="{!a.Actual_Fee__c}"/>
                </apex:column>
                <apex:column headerValue="Actual days">
                    <apex:inputField value="{!a.Actual_days__c}"/>
                </apex:column>
                <apex:column headerValue="Employee">
                   <apex:inputField value="{!a.Employee__c}"/>
                </apex:column>
                </apex:pageBlockTable>
        </apex:pageBlock>
     </apex:form>
</apex:page>
This was selected as the best answer
mtbclimbermtbclimber

I'm not sure why you need the standardsetcontroller in this case, it doesn't appear you are even using it.

 

Here's an example that doesn't use the standardsetcontroller for updating opportunities on a given account.

 

Page:

 

 

<apex:page controller="accountOpptyUpdatesCon">
<apex:form >
<apex:pageBlock id="thePageBlock">
<apex:pageMessages />
<apex:pageBlockSection title="Select an Account">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Account Name" for="select"/>
<apex:outputPanel >
<apex:selectList value="{!accountId}" size="1">
<apex:selectOptions value="{!accountOptions}"/>
<apex:actionSupport action="{!findOpps}" event="onchange" rerender="thePageBlock" status="status"/>
</apex:selectList>
<apex:actionStatus startText="getting related opportunities..." id="status"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="related opportunities" rendered="{!accountId != null}">
<apex:pageBlockTable value="{!opportunities}" var="o">
<apex:column value="{!o.name}"/>
<apex:column headerValue="Close Date">
<apex:inputField value="{!o.stagename}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Save" action="{!save}" rendered="{!accountId != null}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Controller:

 

 

public class accountOpptyUpdates2Con {

public Id accountId { get; set; }
public List<Opportunity> opportunities { get; set; }

public List<SelectOption> getAccountOptions() {
List<ApexPages.SelectOption> options = new List<ApexPages.SelectOption>();
options.add(new ApexPages.SelectOption('','--SELECT AN ACCOUNT--'));
for(Account a:[select name from account where id in (select accountId from opportunity) limit 5]) {
options.add(new ApexPages.SelectOption(a.id, a.name));
}
return options;
}

public void findOpps() {
opportunities = [select name, stagename from opportunity where accountId = :accountId limit 20];
}

public PageReference save() {
PageReference p;

try {
Database.update(opportunities, true);
p = new ApexPages.StandardController(new Account(Id = accountId)).view();
} catch (System.DMLException e) {
ApexPages.addMessages(e);
}

return p;
}
}

 

 If you're trying to wire this page up to a list button then you don't need any apex at all from what I can tell. If you want to edit all the records selected from the parent's related list you'd just need a page like this:

 

 

<apex:page standardController="Opportunity" recordsetvar="opportunities">
<apex:form >
<apex:pageBlock id="thePageBlock">
<apex:pageMessages />
<apex:pageBlockSection title="related opportunities">
<apex:pageBlockTable value="{!selected}" var="o">
<apex:column value="{!o.name}"/>
<apex:column headerValue="Close Date">
<apex:inputField value="{!o.stagename}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 Then bind that page to a list button for the given object (Opportunity in this case), add the button to the standard page layout for the parent (account in this case) then go to a parent page, select a couple of the children and click the button you just added.

 

 

 

 

kickingboykickingboy

Hi Andrew

As I now have my code working I will examine your code in detail to see if I can use it to identify improvements but I will say that the bottom snippet will not work for me because as I say at the top of the thread I am using CUSTOM  OBJECTS  and your example is using standard objects (Accounts and opps) and the Select method does not appear to exist  in the standard controller for custom objects.

 

Stuart