You need to sign in to do that
Don't have an account?
satakshi
REQUIRED_FIELD_MISSING error
Hello,
I am writing code to create calender records. I am facing this error.
Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [MTP]: [MTP]
Error is in expression '{!createdtp}' in component <apex:page> in page createdtp: Class.Calender.createdtp: line 40, column 1
An unexpected error has occurred. Your development organization has been notified.
Can anyone please help me to sort it out. MTP is master detail field
My code is:
Controller:
public with sharing class Calender {
public Calender(ApexPages.StandardController controller)
{
tid = ApexPages.currentPage().getParameters().get('id');
System.debug('***************dtp added*******************'+tid);
}
public Decimal dy;
public id tid{get;set;}
public PageReference createdtp() {
System.debug('***************tid tid*******************'+tid);
List<MTP__c> obj = [Select Id, Month__c, Year__c, February__c, NumberOfDays__c from MTP__c];
for(MTP__c mt:obj)
{
if(mt.Month__c=='February')
{
String str=mt.February__c;
dy=Decimal.ValueOf(str);
}
else
{
Decimal str= mt.NumberOfDays__c;
dy=str;
}
}
List<DTP__c> newdtp= new List<DTP__c>();
for(Integer i = 1; i<=dy; i++)
{
DTP__c dt = new DTP__c();
dt.MTP__c=tid;
newdtp.add(dt);
System.debug('***************dtp added*******************'+tid);
//insert newdtp;
}
insert newdtp;
return null;
}
public List<DTP__c> getMydtpList(){
mydtpList =[select Name, Expenses__c, MTP__c, Food_Expenses__c, Date__c, Visit_type__c from DTP__c where id=:tid];
return mydtpList ;
}
List<DTP__c> mydtpList = [select Expenses__c, Name, MTP__c, Food_Expenses__c, Visit_type__c from DTP__c where id=:tid];
}
VF Page:
<apex:page standardController="MTP__c" extensions="Calender" action="{!createdtp}">
<apex:pageBlock title="All Dtp">
<apex:pageblockTable value="{!mydtpList}" var="item">
<apex:column value="{!item.Name}"/>
<apex:column value="{!item.Date__c}"/>
<apex:column value="{!item.Visit_type__c}"/>
<apex:column value="{!item.Food_Expenses__c}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:page>
Thanks & Regards,
Satakshi
I am writing code to create calender records. I am facing this error.
Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [MTP]: [MTP]
Error is in expression '{!createdtp}' in component <apex:page> in page createdtp: Class.Calender.createdtp: line 40, column 1
An unexpected error has occurred. Your development organization has been notified.
Can anyone please help me to sort it out. MTP is master detail field
My code is:
Controller:
public with sharing class Calender {
public Calender(ApexPages.StandardController controller)
{
tid = ApexPages.currentPage().getParameters().get('id');
System.debug('***************dtp added*******************'+tid);
}
public Decimal dy;
public id tid{get;set;}
public PageReference createdtp() {
System.debug('***************tid tid*******************'+tid);
List<MTP__c> obj = [Select Id, Month__c, Year__c, February__c, NumberOfDays__c from MTP__c];
for(MTP__c mt:obj)
{
if(mt.Month__c=='February')
{
String str=mt.February__c;
dy=Decimal.ValueOf(str);
}
else
{
Decimal str= mt.NumberOfDays__c;
dy=str;
}
}
List<DTP__c> newdtp= new List<DTP__c>();
for(Integer i = 1; i<=dy; i++)
{
DTP__c dt = new DTP__c();
dt.MTP__c=tid;
newdtp.add(dt);
System.debug('***************dtp added*******************'+tid);
//insert newdtp;
}
insert newdtp;
return null;
}
public List<DTP__c> getMydtpList(){
mydtpList =[select Name, Expenses__c, MTP__c, Food_Expenses__c, Date__c, Visit_type__c from DTP__c where id=:tid];
return mydtpList ;
}
List<DTP__c> mydtpList = [select Expenses__c, Name, MTP__c, Food_Expenses__c, Visit_type__c from DTP__c where id=:tid];
}
VF Page:
<apex:page standardController="MTP__c" extensions="Calender" action="{!createdtp}">
<apex:pageBlock title="All Dtp">
<apex:pageblockTable value="{!mydtpList}" var="item">
<apex:column value="{!item.Name}"/>
<apex:column value="{!item.Date__c}"/>
<apex:column value="{!item.Visit_type__c}"/>
<apex:column value="{!item.Food_Expenses__c}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:page>
Thanks & Regards,
Satakshi
So you must have to provide MTP__c object's record id in url. Just after your page name in URL add ?id=recordId.
(replace recordId with 15 digit id of that parent record)
All Answers
Can you please check is there MTP__c object's record Id is present on browser's URL after your page name?
i.e. https://ap1.visual.force.com/apex/myVfPage?id=recordId
Have a look on Image:
https://www.google.co.in/imgres?imgurl=http%3A%2F%2F3.bp.blogspot.com%2F-CPfMDOXoFu8%2FVdoUYB0mzcI%2FAAAAAAAAAok%2F8Yh5FZjK3G0%2Fs1600%2Fscreenshot_Sun_Aug_23_23.26.15.png&imgrefurl=http%3A%2F%2Fwww.sfdcgurukul.com%2F2015%2F08%2Fvisualforce-page-vs-controller-scenario.html&docid=3oEJ3YJVdDsgMM&tbnid=UwuLie1ppDWQ3M%3A&w=984&h=586&bih=667&biw=1366&ved=0ahUKEwjY8s6lppvPAhVPwmMKHVncChoQMwghKAQwBA&iact=mrc&uact=8
So you must have to provide MTP__c object's record id in url. Just after your page name in URL add ?id=recordId.
(replace recordId with 15 digit id of that parent record)