2

it sounds so simple, get a list of similar items and allow the user to edit one field, then click save and return to where you came from. I just do not understand enough to make this happen, can some one take a look? When i hit save i get "There is no record to save"

<apex:page standardController="ERP_Data__c" extensions="opportunityList2Con">

<apex:form >
    <apex:pageBlock title="{!erp.Chain__c}" >
        <apex:pageMessages />
        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlockButtons>
        <apex:pageBlockTable value="{!Opportunities}" var="o" >

            <apex:column value="{!o.Account__c}"/>

            <apex:column value="{!o.id}"/>

            <apex:column value="{!o.Acct_RT_Name__c}"/>

            <apex:column headerValue="Program">

                <apex:inputField value="{!o.Program__c}"/>

            </apex:column>

        </apex:pageBlockTable>      
    </apex:pageBlock>
</apex:form>

and the controler

public class opportunityList2Con {

   public opportunityList2Con(ApexPages.StandardController controller) {}

    erp_data__c erp;
    public erp_data__c geterp() {
    if (erp == null){                      
    erp = [SELECT Chain__c FROM ERP_Data__c WHERE 
        id = :ApexPages.currentPage().getParameters().get('id')];
          }
       return erp;

    }

    String myTestString = ApexPages.currentPage().getParameters().get('name') ;

    // ApexPages.StandardSetController must be instantiated
    // for standard list controllers
    public ApexPages.StandardSetController seterp {
         get {
            if(seterp == null) {
               return new ApexPages.StandardSetController(
                         Database.getQueryLocator(
                    [SELECT name, Account__c ,Acct_RT_Name__c, Chain__c, 
                            Id, Program__c, RecordTypeId    
                     FROM ERP_Data__c  
                     WHERE Chain__c = :myTestString limit 25 ]));
            }
            return seterp;
        }
      private  set;
     }
    // Initialize seterp and return a list of records
    public list<ERP_Data__c> getOpportunities()  
    {
    return (list<ERP_Data__c>) seterp.getRecords();
    }   
}

1 Answer 1

2

You are using the standard controller Save method in your command button, which would only save changes to the ERP_Data__c record you open the page with. If you want to save data in the list, you need a custom save method to be called.

<apex:page standardController="ERP_Data__c" extensions="opportunityList2Con">
<apex:form >
<apex:pageBlock title="{!erp.Chain__c}" >
    <apex:pageMessages />
    <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!mysave}"/>
    </apex:pageBlockButtons>
    <apex:pageBlockTable value="{!Opportunities}" var="o" >

        <apex:column value="{!o.Account__c}"/>

        <apex:column value="{!o.id}"/>

        <apex:column value="{!o.Acct_RT_Name__c}"/>

        <apex:column headerValue="Program">

            <apex:inputField value="{!o.Program__c}"/>

        </apex:column>

    </apex:pageBlockTable>      
</apex:pageBlock>

</apex:form> </apex:page>

Controller:

public class opportunityList2Con {
public opportunityList2Con(ApexPages.StandardController controller) {}

erp_data__c erp;
public erp_data__c geterp() {
if (erp == null){                      
erp = [SELECT Chain__c FROM ERP_Data__c WHERE 
    id = :ApexPages.currentPage().getParameters().get('id')];
      }
   return erp;

}

String myTestString = ApexPages.currentPage().getParameters().get('name') ;

// ApexPages.StandardSetController must be instantiated
// for standard list controllers
public ApexPages.StandardSetController seterp {
     get {
        if(seterp == null) {
           return new ApexPages.StandardSetController(
                     Database.getQueryLocator(
                [SELECT name, Account__c ,Acct_RT_Name__c, Chain__c, 
                        Id, Program__c, RecordTypeId    
                 FROM ERP_Data__c  
                 WHERE Chain__c = :myTestString limit 25 ]));
        }
        return seterp;
    }
  private  set;
 }
// Initialize seterp and return a list of records
public list<ERP_Data__c> getOpportunities()  
{
return (list<ERP_Data__c>) seterp.getRecords();
}
public PageReference mysave(){
    seterp.save();  //call the save method on your set controller
    //controller.save();  add this if you want to save your original ERP_Data__c record         
    //as well
return null;
}

}
1
  • I see how I was using the incorrect set, but it is still not working. No errors, hit save and the page refreshes without the new data recorded. it feels much closer and I am just missing the concept enough that i cant find the issue Nov 6, 2013 at 16:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .