+ Start a Discussion
Swetha Sfdc1Swetha Sfdc1 

Need Visualforce & Apex class help

Hi Friends Thanks in advance

I have created Visualforce page with Dynamic multiadd functionalty, I have given Field dependency picklist values but I am facing some issues  like
  • Field alignment missing
  • save function is not working
  • Field lable is repeating

Name of Dealer field is Master Relation ship

Please find attached is the screens regarding above issues.


--Visualforcepage--
<apex:page StandardController="Service_sheet__c" extensions="MultiAdd" id="thePage" sidebar="false">

<apex:form >
<apex:pageblock id="pb" >
    <apex:pageBlockButtons >
        <apex:commandbutton value="Add" action="{!Add}" rerender="pb1"/>
        <apex:commandbutton value="Save" action="{!Save}"/>
    </apex:pageBlockButtons>       
                
                
            <apex:pageBlockSection title="My Content Section" columns="2">
               <apex:inputText value="{!Service_sheet__c.Sno__c}" style="width:80px;height:20px;"/>
               <apex:inputText value="{!Service_sheet__c.Nameofdealer__c}" style="width:50px;height:20px;"/>
               <apex:inputText value="{!Service_sheet__c.AGENCY__c}" style="width:150px;height:20px;"/>
               <apex:inputText value="{!Service_sheet__c.Date_of_service__c}" style="width:50px;height:20px;"/>
               <apex:inputText value="{!Service_sheet__c.Currency__c}" style="width:130px;height:20px;"/>
               <apex:inputfield value="{!Service_sheet__c.Nameofdealer__c}"/>
            </apex:pageBlockSection>
               
               
        <apex:pageblock id="pb1">              
        <apex:repeat value="{!lstInner}" var="e1" id="therepeat">
                <apex:panelGrid columns="16"> 
                
                <apex:panelGrid title="Date" >       
                 <apex:facet name="header">Date</apex:facet>             
                    <apex:inputfield value="{!e1.acct.Date__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>  
                
                <apex:panelGrid title="City" >
                    <apex:facet name="header">City</apex:facet>
                    <apex:inputfield value="{!e1.acct.City__c}"  style="width:115px;height:20px;"/>
                </apex:panelGrid> 
                
                <apex:panelGrid title="Category" >
                    <apex:facet name="header">Category</apex:facet>
                    <apex:inputfield value="{!e1.acct.Category__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid> 
                
                <apex:panelGrid title="Details" >
                    <apex:facet name="header">Details</apex:facet>
                    <apex:inputfield value="{!e1.acct.Details__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid> 
                
                <apex:panelGrid title="Product Cost" >
                    <apex:facet name="header">Product Cost</apex:facet>
                    <apex:inputfield value="{!e1.acct.Prod_Cost__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                <apex:panelGrid title="No.of Pieces" >
                    <apex:facet name="header">No.of Pieces</apex:facet>
                    <apex:inputfield value="{!e1.acct.No_of_Pieces__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                <apex:panelGrid title="Total" >
                    <apex:facet name="header">Total</apex:facet>
                    <apex:inputfield value="{!e1.acct.Total__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                <apex:panelGrid title="Comments" >
                    <apex:facet name="header">Comments</apex:facet>
                    <apex:inputfield value="{!e1.acct.Comments__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>  
                
                <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>
        </apex:repeat>
        
        
    </apex:pageBlock>
    
    
        
</apex:pageblock>
</apex:form>
</apex:page>
--Apexclass--
public class MultiAdd
{
    
    //will hold the Service_sheet__c records to be saved
    public List<Service_sheet__c>lstAcct  = new List<Service_sheet__c>();
    
    //list of the inner class
    public List<innerClass> lstInner 
    {   get;set;    }
    
    //will indicate the row to be deleted
    public String selectedRowIndex
    {get;set;}  
    
    //no. of rows added/records in the inner class list
    public Integer count = 1;
    //{get;set;}
    
    
    ////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/MultiAdd');
        
        for(Integer j = 0;j<lstInner.size();j++)
        {
            lstAcct.add(lstInner[j].acct);
        } 
        insert lstAcct;
        pr.setRedirect(True);
        return pr;
    }
        
    //add one more row
    public void Add()
    {   
        count = count+1;
        addMore();      
    }
    
    /*Begin addMore*/
    public void addMore()
    {
        //call to the iner class constructor
        innerClass objInnerClass = new innerClass(count);
        
        //add the record to the inner class list
        lstInner.add(objInnerClass);    
        system.debug('lstInner---->'+lstInner);            
    }/* end addMore*/
    
    /* begin delete */
    public void Del()
    {
        system.debug('selected row index---->'+selectedRowIndex);
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;
        
    }/*End del*/
    
    
    
    /*Constructor*/
    public MultiAdd(ApexPages.StandardController ctlr)
    {
    
        lstInner = new List<innerClass>();
        addMore();
        selectedRowIndex = '0';
        
    }/*End Constructor*/
        


    /*Inner Class*/
    public class innerClass
    {       
        /*recCount acts as a index for a row. This will be helpful to identify the row to be deleted */
        public String recCount
        {get;set;}
        
        
        public Service_sheet__c acct 
        {get;set;}
        
        /*Inner Class Constructor*/
        public innerClass(Integer intCount)
        {
            recCount = String.valueOf(intCount);        
            
            /*create a new Service_sheet__c*/
            acct = new Service_sheet__c();
            
        }/*End Inner class Constructor*/    
    }/*End inner Class*/
}/*End Class*/
Issue1

When I click save button following Validation error

issue2
Issue3
Chandra Sekhar CH N VChandra Sekhar CH N V
Is there any manadatory field (Name of dealer) ion your object?
Swetha Sfdc1Swetha Sfdc1
Hi Chandra Sekhar CH N V, Thanks for Response,
  • Here mandatory field is Name of Dealer.
  • Name of Dealer(Master Detail Relation ship)
  • All the saved data fields information should be place in Dealer object.
Please help me over here. to resolve this issue.

Thanks,
Swetha