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
AmbigaRamAmbigaRam 

Problem in saving page when using add row functionality

Hi,

 

I am creating the page which consists some fields that are not present in row and some other fields that are present in row.

 

I created the custom controller which add the row  functionality in my page.

 

When I am going to save the page , It does not save the page which is in need of other fields (not in row) .

 

Can anyone help for me to show how to save by means of pagereference method  fields (in rows and not in rows)?

 

The following are my code,

Public class MultiAddRowFn{

//Will hold the master records to be saved
public list<Mentor__c>  lstmarf= new list<Mentor__c>();

//List of the inner class
public list<innerClass> lstInner
{get;set;}

//Will indicate the rows to be deleted
public string selectedRowIndex
{get;set;}

//no.of rows added/records in the inner class list
public integer count=1;

////save the records by adding the elements in the inner class list to lstAcct,return to the same page
Public pageReference save()
{
 PageReference pr = new PageReference('/apex/MultiAddRowFn');

for(integer j=0; j<lstInner.size(); j++)
{
lstmarf.add(lstInner[j].ment);
}
update lstmarf;
pr.setRedirect(True);
return pr;
}
//add one or more row
public void add()
{
count=count+1;
addMore();
}

//Begin addMore
public void addMore()
{
innerClass objInnerClass = new innerClass(count);

//add the record to the inner class list
lstInner.add(objInnerClass);
system.debug('lstInner---->'+lstInner);
}/*end add more*/

/*Begin Delete*/
 public void Del()
    {
        system.debug('selected row index---->'+selectedRowIndex);
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;
        
    }/*End del*/
 /*Constructor*/
 public MultiAddRowFn(ApexPages.StandardController ctlr)
 {
 lstInner=new list<InnerClass>();
 addMore();
 selectedRowIndex ='0';
 }/*end constructor */
 
 /*Inner Class*/
 public class innerClass
 {
 public string recCount
 {get; set;}
 
 public Mentor__c ment
 {get; set;}
 
 public innerClass(Integer intCount)
 {
 recCount = string.valueof(intCount);
  ment=new Mentor__c();
  }
  }
 
 
}

 Thanks and Regards.,

Ambiga

sandeep@Salesforcesandeep@Salesforce

Can you please show error message and page code.

AmbigaRamAmbigaRam

Hi,

 

Following is the error

 

 

System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []

Error is in expression '{!save}' in page mentor

 

 

Class.MultiAddRowFn.save: line 26, column 1

 

Following is the page code

<apex:page standardController="Mentor__c" extensions="MultiAddRowFn" id="thePage">
 <apex:form >
 <apex:pageblock id="pb">
 <apex:pageblockButtons >
 <apex:commandbutton value="Add" action="{!Add}" rerender="pb1"/>
 <apex:commandButton action="{!save}" value="save"/>
 </apex:pageblockButtons>
 <apex:pageBlock Title="Mentor Content"  >
 <apex:pageblocksection title="ContactDetails" columns="2">
 <apex:inputField value="{!Mentor__c.Name}"/>
 <apex:inputField value="{!Mentor__c.Last_Name__c}"/>
 <apex:inputField value="{!Mentor__c.Employer__c}"/>
 <apex:pageblocksectionitem ></apex:pageblocksectionitem>
 <apex:inputField value="{!Mentor__c.Email_address__c}"/>
 <apex:pageblocksectionitem ></apex:pageblocksectionitem>
 <apex:inputField value="{!Mentor__c.Work_Landline__c}"/>
 <apex:pageblocksectionitem ></apex:pageblocksectionitem>
 <apex:inputField value="{!Mentor__c.Work_Mobile__c}"/>
 <apex:pageblocksectionitem ></apex:pageblocksectionitem>
 <apex:inputField value="{!Mentor__c.Work_Address__c}"/>
 <apex:pageblocksectionitem ></apex:pageblocksectionitem>
 <apex:inputField value="{!Mentor__c.Town_City__c}"/>
 <apex:pageblocksectionitem ></apex:pageblocksectionitem>
 <apex:inputField value="{!Mentor__c.Country__c}"/>
 <apex:pageblocksectionitem ></apex:pageblocksectionitem>
 <apex:inputField value="{!Mentor__c.Post_Code__c}"/>
 <apex:pageblocksectionitem ></apex:pageblocksectionitem>
 <apex:inputField value="{!Mentor__c.Work_district__c}"/>
 </apex:pageBlockSection>
 <apex:pageblocksection title="Status" columns="1">
 <apex:inputField value="{!Mentor__c.Mentor_Status__c}"/>
 <apex:inputField value="{!Mentor__c.Mentor_status_Notes__c}"/>
 </apex:pageblockSection>
 <apex:pageblockSection title="Mentor-Mentee" columns="1">
 <apex:inputField value="{!Mentor__c.Associate_Name__c}"/>
 <apex:outputLink value="https://c.na15.visual.force.com/apex/preuniversity?q={Associate__c.Name}">    Create New Associate</apex:outputLink>
 <apex:inputtext label="upReach Contact"/>
 <apex:inputField value="{!Mentor__c.Mentee_Preferences_if_any__c}"/>
 <apex:inputField value="{!Mentor__c.Mentor_availability__c}"/>
 <apex:inputField value="{!Mentor__c.Name_of_the_contact_at_the_employer__c}"/>
 <apex:inputField value="{!Mentor__c.Date_completed_mentoring_training__c}"/>
  </apex:pageBlockSection>
  <apex:pageblockSection title="Role" columns="1">
  <apex:inputField value="{!Mentor__c.Job_Title__c}"/>
  <apex:inputField value="{!Mentor__c.How_would_you_describe_your_job__c}"/>
  <apex:inputField value="{!Mentor__c.Broad_business_areas__c}"/>
  <apex:inputField value="{!Mentor__c.Previous_mentoring_experience__c}"/>
  <apex:inputField value="{!Mentor__c.Tick_box_if_no_previous_experience__c}"/>
  </apex:pageBlockSection>
  <apex:pageblockSection title="Career background and Experiences" columns="1">
 <apex:inputField value="{!Mentor__c.Career_Background_Professional_Journey__c}"/>
  <apex:inputField value="{!Mentor__c.Interests_outside_of_work__c}"/>
   </apex:pageBlockSection>
   <apex:pageblockSection title="Adjustments" columns="1">
 <apex:inputField value="{!Mentor__c.Any_adjustments_may_need_to_be_made__c}"/>
 <apex:inputField value="{!Mentor__c.Any_adjustments_may_need_to_be_made__c}"/>
 </apex:pageBlockSection> 
       <apex:pageblock id="pb1" >
            
        <apex:repeat value="{!lstInner}" var="e1" id="therepeat">
                <apex:panelGrid columns="6">
                
                <apex:panelGrid headerClass="Name">
                    <apex:facet name="header">Del</apex:facet>
                    <apex:commandButton value="X" action="{!Del}" rerender="pb1">
                    <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                    </apex:commandButton>
                </apex:panelGrid>   
                
                <apex:panelGrid title="SPD" >
                    <apex:facet name="header">Degree_Title</apex:facet>
                    <apex:inputfield value="{!e1.Ment.Degree_Title__c}"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">University</apex:facet>
                    <apex:inputfield value="{!e1.ment.University__c}"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Year of Graduation</apex:facet>
                    <apex:inputfield value="{!e1.ment.Year_of_Graduation__c}"/>
                </apex:panelGrid>
            </apex:panelgrid>
        </apex:repeat>
        </apex:pageblock>
    
    
   </apex:pageBlock>
   </apex:pageblock>
 </apex:form>
</apex:page>

 Pls help me to solve this problem.

 

Thanks and Regards.,

R.Ambiga