You need to sign in to do that
Don't have an account?
Naidu Sagvi
I am getting missing required field body error...
rajesh Admin
Hi Every one...Actually i getting System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body]
My task is,we have a button while clicking that popup should be open and having one input file component and two buttons.If select file then click save button,it will be store a coresponding case.
But that time i am getting missing required field of body error.i am attaching my Vf Page and Apex code.will any one able to slove that ,it's very helps to me...
Thanks U in Advance....
Vf Page:
=======
<apex:page controller="AccountController12" >
<apex:sectionHeader title="Account" subtitle="Home" help="Help for this Page"/>
<apex:form >
<apex:pageBlock title="Recent Accounts">
<apex:selectList value="{!selectedAccId}" size="1">
<apex:selectOptions value="{!AccountNames}" />
<apex:actionSupport event="onchange" action="{!displaycaselist}"/>
</apex:selectList>
<apex:pageMessages />
<apex:pageBlockTable value="{!caselst}" var="cse">
<apex:column HeaderValue="Case Number" >
<apex:outputLink value="/apex/caseinformation?id={!cse.id}">
{!cse.caseNumber}
</apex:outputLink>
</apex:column>
<apex:column value="{!cse.Subject}" HeaderValue="Subject"/>
<apex:column value="{!cse.Status}" HeaderValue="Status"/>
<apex:column value="{!cse.createdDate}" HeaderValue="Created Date"/>
<apex:column value="{!cse.createdBy.name}" HeaderValue="CReated By"/>
<apex:column value="{!cse.account.name}" HeaderValue="Account Name"/>
<apex:column HeaderValue="Attachment">
<apex:commandButton image="/img/func_icons/util/link20.gif" action="{!showPopup1}" rerender="tstpopup1" >
<apex:param name="caseid" value="{!cse.id}" />
</apex:commandButton>
<apex:outputPanel id="tstpopup1">
<apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
<center>
<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" /><br/>
<apex:commandButton action="{!upload}" value="Select Attachment"/>
<apex:commandButton value="Cancle" action="{!closePopup}" />
</center>
</apex:outputPanel>
</apex:outputPanel>
</apex:column>
<apex:column HeaderValue="Comment" >
<apex:commandButton image="/img/icon/documents32.png" action="{!showPopup}" rerender="tstpopup" >
<apex:param name="caseid" value="{!cse.id}" />
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:outputPanel id="tstpopup">
<apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
<center>
<apex:inputTextarea value="{!textvalue}" /><br/>
<apex:commandButton value="Save" action="{!SaveComment}" />
<apex:commandButton value="Cancle" action="{!closePopup}" />
</center>
</apex:outputPanel>
</apex:outputPanel>
</apex:form>
<style type="text/css">
.custPopup{
background-color: yellow;
z-index: 9999;
left: 50%;
padding:10px;
position: absolute;
width: 700px;
margin-left: -250px;
top:100px;
border-style: none;
}
</style>
</apex:page>
Apex:
=====
public with sharing class AccountController12 {
public blob bodyfile{get; set;}
public boolean displayPopup {get; set;}
public string textvalue{get; set;}
public string showPopup1{get; set;}
public string showPopup{get; set;}
public attachment attachment { get {if (attachment == null) attachment = new Attachment(); return attachment; } set;}
public list<case> caselst { get; set; }
public String selectedAccId{get;set;}
//public string caseid {get; set { caseid = value; if (!displayPopup) { upload(); displayPopup = true; } } }
public string caseid {get; set ;}
public string keepvalue {get; set;}
public List<SelectOption> getAccountNames() {
List<SelectOption> accOptions = new List<SelectOption>();
accOptions.add( new SelectOption('','--Select--'));
for( Account acc : [select Id,name from Account ] ) {
accOptions.add( new SelectOption(acc.Id,acc.name));
}
return accOptions;
}
public void displaycaselist() {
caselst = new list<case>();
caselst=[SELECT id,CaseNumber,Subject,Account.name,createdBy.name,createdDate,Status,accountid FROM Case where accountid=:selectedAccId];
if(caselst == null || caselst.size() == 0){
ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'No Corresponding Case Record'));
}
}
public void showPopup1() {
displayPopup = true;
String caseid= System.currentPageReference().getParameters().get('caseid');
system.debug('========>'+caseid);
system.debug('=========>'+bodyfile);
keepvalue = caseid ;
bodyfile=attachment.body;
}
public PageReference upload() {
system.debug('=====>'+bodyfile);
attachment attachment1 = new Attachment();
attachment1.OwnerId = UserInfo.getUserId();
attachment1.parentid = keepvalue;
attachment1.name ='true';
attachment1.body = bodyfile;
insert attachment1 ;
PageReference pageRef = new PageReference('/apex/casesmmary3');
pageRef.setRedirect(true);
return pageRef ;
}
public AccountController12 (){
String caseid = System.currentPageReference().getParameters().get('caseid');
//String caseid = apexpages.currentpage().getparameters().get('caseid');
system.debug('========>'+caseid);
}
public void showPopup() {
displayPopup = true;
String caseid = System.currentPageReference().getParameters().get('caseid');
system.debug('========>'+caseid);
system.debug('========>'+textvalue);
keepvalue = caseid ;
}
public PageReference SaveComment(){
caseComment cc = new caseComment();
cc.CommentBody = textvalue;
cc.parentid = keepvalue;
insert cc;
PageReference pageRef = new PageReference('/apex/casesmmary3');
pageRef.setRedirect(true);
return pageRef ;
}
public void closePopup() {
displayPopup = false;
}
}
Hi Every one...Actually i getting System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body]
My task is,we have a button while clicking that popup should be open and having one input file component and two buttons.If select file then click save button,it will be store a coresponding case.
But that time i am getting missing required field of body error.i am attaching my Vf Page and Apex code.will any one able to slove that ,it's very helps to me...
Thanks U in Advance....
Vf Page:
=======
<apex:page controller="AccountController12" >
<apex:sectionHeader title="Account" subtitle="Home" help="Help for this Page"/>
<apex:form >
<apex:pageBlock title="Recent Accounts">
<apex:selectList value="{!selectedAccId}" size="1">
<apex:selectOptions value="{!AccountNames}" />
<apex:actionSupport event="onchange" action="{!displaycaselist}"/>
</apex:selectList>
<apex:pageMessages />
<apex:pageBlockTable value="{!caselst}" var="cse">
<apex:column HeaderValue="Case Number" >
<apex:outputLink value="/apex/caseinformation?id={!cse.id}">
{!cse.caseNumber}
</apex:outputLink>
</apex:column>
<apex:column value="{!cse.Subject}" HeaderValue="Subject"/>
<apex:column value="{!cse.Status}" HeaderValue="Status"/>
<apex:column value="{!cse.createdDate}" HeaderValue="Created Date"/>
<apex:column value="{!cse.createdBy.name}" HeaderValue="CReated By"/>
<apex:column value="{!cse.account.name}" HeaderValue="Account Name"/>
<apex:column HeaderValue="Attachment">
<apex:commandButton image="/img/func_icons/util/link20.gif" action="{!showPopup1}" rerender="tstpopup1" >
<apex:param name="caseid" value="{!cse.id}" />
</apex:commandButton>
<apex:outputPanel id="tstpopup1">
<apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
<center>
<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" /><br/>
<apex:commandButton action="{!upload}" value="Select Attachment"/>
<apex:commandButton value="Cancle" action="{!closePopup}" />
</center>
</apex:outputPanel>
</apex:outputPanel>
</apex:column>
<apex:column HeaderValue="Comment" >
<apex:commandButton image="/img/icon/documents32.png" action="{!showPopup}" rerender="tstpopup" >
<apex:param name="caseid" value="{!cse.id}" />
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:outputPanel id="tstpopup">
<apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
<center>
<apex:inputTextarea value="{!textvalue}" /><br/>
<apex:commandButton value="Save" action="{!SaveComment}" />
<apex:commandButton value="Cancle" action="{!closePopup}" />
</center>
</apex:outputPanel>
</apex:outputPanel>
</apex:form>
<style type="text/css">
.custPopup{
background-color: yellow;
z-index: 9999;
left: 50%;
padding:10px;
position: absolute;
width: 700px;
margin-left: -250px;
top:100px;
border-style: none;
}
</style>
</apex:page>
Apex:
=====
public with sharing class AccountController12 {
public blob bodyfile{get; set;}
public boolean displayPopup {get; set;}
public string textvalue{get; set;}
public string showPopup1{get; set;}
public string showPopup{get; set;}
public attachment attachment { get {if (attachment == null) attachment = new Attachment(); return attachment; } set;}
public list<case> caselst { get; set; }
public String selectedAccId{get;set;}
//public string caseid {get; set { caseid = value; if (!displayPopup) { upload(); displayPopup = true; } } }
public string caseid {get; set ;}
public string keepvalue {get; set;}
public List<SelectOption> getAccountNames() {
List<SelectOption> accOptions = new List<SelectOption>();
accOptions.add( new SelectOption('','--Select--'));
for( Account acc : [select Id,name from Account ] ) {
accOptions.add( new SelectOption(acc.Id,acc.name));
}
return accOptions;
}
public void displaycaselist() {
caselst = new list<case>();
caselst=[SELECT id,CaseNumber,Subject,Account.name,createdBy.name,createdDate,Status,accountid FROM Case where accountid=:selectedAccId];
if(caselst == null || caselst.size() == 0){
ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'No Corresponding Case Record'));
}
}
public void showPopup1() {
displayPopup = true;
String caseid= System.currentPageReference().getParameters().get('caseid');
system.debug('========>'+caseid);
system.debug('=========>'+bodyfile);
keepvalue = caseid ;
bodyfile=attachment.body;
}
public PageReference upload() {
system.debug('=====>'+bodyfile);
attachment attachment1 = new Attachment();
attachment1.OwnerId = UserInfo.getUserId();
attachment1.parentid = keepvalue;
attachment1.name ='true';
attachment1.body = bodyfile;
insert attachment1 ;
PageReference pageRef = new PageReference('/apex/casesmmary3');
pageRef.setRedirect(true);
return pageRef ;
}
public AccountController12 (){
String caseid = System.currentPageReference().getParameters().get('caseid');
//String caseid = apexpages.currentpage().getparameters().get('caseid');
system.debug('========>'+caseid);
}
public void showPopup() {
displayPopup = true;
String caseid = System.currentPageReference().getParameters().get('caseid');
system.debug('========>'+caseid);
system.debug('========>'+textvalue);
keepvalue = caseid ;
}
public PageReference SaveComment(){
caseComment cc = new caseComment();
cc.CommentBody = textvalue;
cc.parentid = keepvalue;
insert cc;
PageReference pageRef = new PageReference('/apex/casesmmary3');
pageRef.setRedirect(true);
return pageRef ;
}
public void closePopup() {
displayPopup = false;
}
}
In above scenario you are rerender the section which contains the <apex:inputfile> . But there is a limit that we can't rendered the section which contains the <apex:inputfile> . So for this issue we need to use actionRegion only once at the starting of form :
<apex:actionRegion>
<apex:actionFunction name="showPopup1" action="{!showPopup1}" reRender="tstpopup1" immediate="true">
<apex:param assignTo="{!cId}" name="nm1" value="" />
</apex:actionFunction>
</apex:actionRegion>
And for rendered functionality of outputpanel :
<apex:outputPanel style="{!if(displayPopup==false,'display:none','')}">
I am posting modified Vf page and Controller code so that it can easy to understand :
==================
<apex:sectionHeader title="Account" subtitle="Home" help="Help for this Page"/>
<script>
function jsFunc(va){
showPopup1(va);
}
</script>
<apex:form>
<apex:actionRegion>
<apex:actionFunction name="showPopup1" action="{!showPopup1}" reRender="tstpopup1" immediate="true">
<apex:param assignTo="{!cId}" name="nm1" value="" />
</apex:actionFunction>
</apex:actionRegion>
<apex:pageBlock title="Recent Accounts">
<apex:selectList value="{!selectedAccId}" size="1">
<apex:selectOptions value="{!AccountNames}" />
<apex:actionSupport event="onchange" action="{!displaycaselist}"/>
</apex:selectList>
<apex:pageMessages />
<apex:pageBlockTable value="{!caselst}" var="cse">
<apex:column HeaderValue="Case Number" >
<apex:outputLink value="/apex/caseinformation?id={!cse.id}">
{!cse.caseNumber}
</apex:outputLink>
</apex:column>
<apex:column value="{!cse.Subject}" HeaderValue="Subject"/>
<apex:column value="{!cse.Status}" HeaderValue="Status"/>
<apex:column value="{!cse.createdDate}" HeaderValue="Created Date"/>
<apex:column value="{!cse.createdBy.name}" HeaderValue="CReated By"/>
<apex:column value="{!cse.account.name}" HeaderValue="Account Name"/>
<apex:column HeaderValue="Attachment">
<apex:commandButton image="/img/func_icons/util/link20.gif" onclick="jsFunc('{!cse.id}');return false;" >
</apex:commandButton>
<apex:outputPanel id="tstpopup1">
{!displayPopup}
<apex:outputPanel style="{!if(displayPopup==false,'display:none','')}">
<apex:outputPanel styleClass="custPopup" layout="block" >
<center>
<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" /><br/>
<apex:commandButton action="{!upload}" value="Select Attachment"/>
<apex:commandButton value="Cancle" action="{!closePopup}" />
</center>
</apex:outputPanel>
</apex:outputPanel>
</apex:outputPanel>
</apex:column>
<apex:column HeaderValue="Comment" >
<apex:commandButton image="/img/icon/documents32.png" action="{!showPopup}" rerender="tstpopup" >
<apex:param name="caseid" value="{!cse.id}" />
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:outputPanel id="tstpopup">
<apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
<center>
<apex:inputTextarea value="{!textvalue}" /><br/>
<apex:commandButton value="Save" action="{!SaveComment}" />
<apex:commandButton value="Cancle" action="{!closePopup}" />
</center>
</apex:outputPanel>
</apex:outputPanel>
</apex:form>
<style type="text/css">
.custPopup{
background-color: yellow;
z-index: 9999;
left: 50%;
padding:10px;
position: absolute;
width: 700px;
margin-left: -250px;
top:100px;
border-style: none;
}
</style>
</apex:page>
Controller:
==========
public with sharing class AccountController12 {
public string fileName {set;get;}
public String cId {set;get;}
public blob bodyfile{get; set;}
public boolean displayPopup {get; set;}
public string textvalue{get; set;}
public string showPopup1{get; set;}
public string showPopup{get; set;}
public attachment attachment { get {if (attachment == null) attachment = new Attachment(); return attachment; } set;}
public list<case> caselst { get; set; }
public String selectedAccId{get;set;}
//public string caseid {get; set { caseid = value; if (!displayPopup) { upload(); displayPopup = true; } } }
public string caseid {get; set ;}
public string keepvalue {get; set;}
public List<SelectOption> getAccountNames() {
List<SelectOption> accOptions = new List<SelectOption>();
accOptions.add( new SelectOption('','--Select--'));
for( Account acc : [select Id,name from Account ] ) {
accOptions.add( new SelectOption(acc.Id,acc.name));
}
return accOptions;
}
public void displaycaselist() {
caselst = new list<case>();
caselst=[SELECT id,CaseNumber,Subject,Account.name,createdBy.name,createdDate,Status,accountid FROM Case where accountid=:selectedAccId];
if(caselst == null || caselst.size() == 0){
ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'No Corresponding Case Record'));
}
}
public void showPopup1() {
displayPopup = true;
keepvalue = cid ;
}
public PageReference upload() {
system.debug('=====>'+bodyfile);
system.debug('FileName == '+fileName);
system.debug('caseid ==' + keepvalue);
attachment attachment1 = new Attachment();
attachment1.OwnerId = UserInfo.getUserId();
attachment1.parentid = keepValue;
attachment1.name = attachment.name;
attachment1.body = attachment.body;
insert attachment1 ;
PageReference pageRef = new PageReference('/apex/casesmmary3');
pageRef.setRedirect(true);
return pageRef ;
}
public AccountController12 (){
String caseid = System.currentPageReference().getParameters().get('caseid');
//String caseid = apexpages.currentpage().getparameters().get('caseid');
system.debug('========>'+caseid);
}
public void showPopup() {
displayPopup = true;
String caseid = System.currentPageReference().getParameters().get('caseid');
system.debug('========>'+caseid);
system.debug('========>'+textvalue);
keepvalue = caseid ;
}
public PageReference SaveComment(){
caseComment cc = new caseComment();
cc.CommentBody = textvalue;
cc.parentid = keepvalue;
insert cc;
PageReference pageRef = new PageReference('/apex/casesmmary3');
pageRef.setRedirect(true);
return pageRef ;
}
public void closePopup() {
displayPopup = false;
}
}
Hope this helps !!
Regards,
Rohit Sethi