• Mani@45
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I created a linline visualforce page for the child and that placed it on Parent obj i.e when a parent record(Like Account) open in bottom then child obj(Like Contact) fields shown and we enter the values and save it this is my vf page...Here my problem is when parent record(Account) is open then in bottom Contact Vf page Account field automatically Created with which account you opened..   when i save then this error is coming

" System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Call2]: [Call2]
Error is in expression '{!Save}' in component <apex:commandButton> in page productrelated "



Here call2__C is parent obj and product__c is child object..

Visualforce Page

<apex:page standardController="Call2__c" sidebar="false" extensions="Add">
{!greet}
<apex:outputField value="{!Call2__c['Name']}" />
<apex:form >
<apex:pageblock id="pb" >
    <apex:pageBlockButtons >
        <apex:commandbutton value="Add" action="{!Addrow}" rerender="pb1"/>
        <apex:commandbutton value="Save" action="{!Save}" />
    </apex:pageBlockButtons>
     <apex:pageMessages />
     
      <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="header" >
                    <apex:facet name="header">Call</apex:facet>
                    <apex:inputfield value="{!e1.pro.Call__c}"/>
                </apex:panelGrid>  -->
                
                       <apex:panelGrid title="header" >
                       <apex:facet name="header">Call</apex:facet>
                    <!--   <apex:outputLink value="/{!e1.pro.Id}">{!e1.pro.Call__c}</apex:outputLink>
                           <apex:inputfield value="{!e1.pro.Call__c}"/>
                        <apex:outputField value="{!e1.pro.Call__c}"/>-->
                        <apex:outputField value="{!Call2__c['Name']}" />
                    </apex:panelGrid>
               
                <apex:panelGrid title="header" >
                    <apex:facet name="header">Quantity</apex:facet>
                    <apex:inputfield value="{!e1.pro.Quantity__c}" />
                </apex:panelGrid>
               
                <apex:panelGrid >
                    <apex:facet name="header">Product</apex:facet>
                    <apex:inputfield value="{!e1.pro.Products__c}" />
                </apex:panelGrid>
               
                <apex:panelGrid >
                    <apex:facet name="header">Item</apex:facet>
                    <apex:inputfield value="{!e1.pro.Item__c}" />
                </apex:panelGrid>
               
                <apex:panelGrid >
                    <apex:facet name="header">Notes</apex:facet>
                    <apex:inputfield value="{!e1.pro.Notes__c}"/>
                </apex:panelGrid>
              
            </apex:panelgrid>
        </apex:repeat>
    </apex:pageBlock>    
</apex:pageblock>
</apex:form>

</apex:page>

Apex

public class Add
{  
    Public List<product__c> lstpro{get;set;}
    Public List<product__c> edpro{get;set;}
    Public call2__c cl;
    public String var {get;set;}
    public List<innerClass> lstInner {get;set;}
    public String selectedRowIndex {get;set;} 
    private List<product__c> calln;
    public id calid;
    public Integer count = 1;

   
    public PageReference Save()
    {
        var= ApexPages.currentPage().getParameters().get('Id');   
        PageReference pr = new PageReference('/apex/productrelated?'+var);
       
       // PageReference pr = new PageReference('/'+cl.id);
          
       // PageReference pr;
       // pr = Page.productrelated;
       
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error:Fields Can not Null');
        ApexPages.addMessage(myMsg);
      
        for(Integer j = 0;j<lstInner.size();j++)
        {
            lstpro.add(lstInner[j].pro);
        }
        insert lstpro;
        pr.setRedirect(True);
        return pr;
    }
   
    public void Addrow()
    {  
        count = count+1;
        addMore();     
    }

    public void addMore()
    {
        innerClass objInnerClass = new innerClass(count);
        lstInner.add(objInnerClass);   
              
    }
  
    public void Del()
    {
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;
    }
   
    public Add(ApexPages.StandardController controller)
    {
        controller.addFields(new List<String>{'Name'});
        this.cl = (call2__c)controller.getRecord();
        lstpro = [select call__c,call__r.name,id,quantity__c,products__c,Item__c from Product__c where id=:cl.id];
        lstInner = new List<innerClass>();
        addMore();
        selectedRowIndex = '0';
       
    }
    public String getGreet() {
       return ' (' + cl.id + ')';
   }
 
    public class innerClass
    {      
      public String recCount{get;set;}
      public product__c pro {get;set;}
      
       public innerClass(Integer intCount)
        {
            recCount = String.valueOf(intCount);       
            pro = new product__c();
        }
    }
}
I created a linline visualforce page for the child and that placed it on Parent obj i.e when a parent record(Like Account) open in bottom then child obj(Like Contact) fields shown and we enter the values and save it this is my vf page...Here my problem is when parent record(Account) is open then in bottom Contact Vf page Account field automatically Created with which account you opened..   when i save then this error is coming

" System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Call2]: [Call2]
Error is in expression '{!Save}' in component <apex:commandButton> in page productrelated "



Here call2__C is parent obj and product__c is child object..

Visualforce Page

<apex:page standardController="Call2__c" sidebar="false" extensions="Add">
{!greet}
<apex:outputField value="{!Call2__c['Name']}" />
<apex:form >
<apex:pageblock id="pb" >
    <apex:pageBlockButtons >
        <apex:commandbutton value="Add" action="{!Addrow}" rerender="pb1"/>
        <apex:commandbutton value="Save" action="{!Save}" />
    </apex:pageBlockButtons>
     <apex:pageMessages />
     
      <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="header" >
                    <apex:facet name="header">Call</apex:facet>
                    <apex:inputfield value="{!e1.pro.Call__c}"/>
                </apex:panelGrid>  -->
                
                       <apex:panelGrid title="header" >
                       <apex:facet name="header">Call</apex:facet>
                    <!--   <apex:outputLink value="/{!e1.pro.Id}">{!e1.pro.Call__c}</apex:outputLink>
                           <apex:inputfield value="{!e1.pro.Call__c}"/>
                        <apex:outputField value="{!e1.pro.Call__c}"/>-->
                        <apex:outputField value="{!Call2__c['Name']}" />
                    </apex:panelGrid>
               
                <apex:panelGrid title="header" >
                    <apex:facet name="header">Quantity</apex:facet>
                    <apex:inputfield value="{!e1.pro.Quantity__c}" />
                </apex:panelGrid>
               
                <apex:panelGrid >
                    <apex:facet name="header">Product</apex:facet>
                    <apex:inputfield value="{!e1.pro.Products__c}" />
                </apex:panelGrid>
               
                <apex:panelGrid >
                    <apex:facet name="header">Item</apex:facet>
                    <apex:inputfield value="{!e1.pro.Item__c}" />
                </apex:panelGrid>
               
                <apex:panelGrid >
                    <apex:facet name="header">Notes</apex:facet>
                    <apex:inputfield value="{!e1.pro.Notes__c}"/>
                </apex:panelGrid>
              
            </apex:panelgrid>
        </apex:repeat>
    </apex:pageBlock>    
</apex:pageblock>
</apex:form>

</apex:page>

Apex

public class Add
{  
    Public List<product__c> lstpro{get;set;}
    Public List<product__c> edpro{get;set;}
    Public call2__c cl;
    public String var {get;set;}
    public List<innerClass> lstInner {get;set;}
    public String selectedRowIndex {get;set;} 
    private List<product__c> calln;
    public id calid;
    public Integer count = 1;

   
    public PageReference Save()
    {
        var= ApexPages.currentPage().getParameters().get('Id');   
        PageReference pr = new PageReference('/apex/productrelated?'+var);
       
       // PageReference pr = new PageReference('/'+cl.id);
          
       // PageReference pr;
       // pr = Page.productrelated;
       
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error:Fields Can not Null');
        ApexPages.addMessage(myMsg);
      
        for(Integer j = 0;j<lstInner.size();j++)
        {
            lstpro.add(lstInner[j].pro);
        }
        insert lstpro;
        pr.setRedirect(True);
        return pr;
    }
   
    public void Addrow()
    {  
        count = count+1;
        addMore();     
    }

    public void addMore()
    {
        innerClass objInnerClass = new innerClass(count);
        lstInner.add(objInnerClass);   
              
    }
  
    public void Del()
    {
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;
    }
   
    public Add(ApexPages.StandardController controller)
    {
        controller.addFields(new List<String>{'Name'});
        this.cl = (call2__c)controller.getRecord();
        lstpro = [select call__c,call__r.name,id,quantity__c,products__c,Item__c from Product__c where id=:cl.id];
        lstInner = new List<innerClass>();
        addMore();
        selectedRowIndex = '0';
       
    }
    public String getGreet() {
       return ' (' + cl.id + ')';
   }
 
    public class innerClass
    {      
      public String recCount{get;set;}
      public product__c pro {get;set;}
      
       public innerClass(Integer intCount)
        {
            recCount = String.valueOf(intCount);       
            pro = new product__c();
        }
    }
}