You need to sign in to do that
Don't have an account?
satakshi
How can we add date automatically in the records?
Hi,
I want functionality where according to month and year date will automatically added into record. How can we achive it?
public with sharing class Calender {
public List<DTP__c> mydtpList{get;set;}
public MTP__c obj{get;set;}
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);
obj = [Select Id, Month__c, Year__c, February__c, NumberOfDays__c from MTP__c where id=:tid ];
dy= obj.NumberOfDays__c;
if(obj.February__c !=null)
{
String str=obj.February__c;
dy=Decimal.ValueOf(str);
}
else
{
Decimal str= obj.NumberOfDays__c;
dy=str;
}
/*
for(MTP__c mt:obj)
{
if(mt.Month__c=='February')
{
String str=mt.February__c;
dy=Decimal.ValueOf(s
System.debug('***************in IF dy size******************'+dy);
}
else
{
Decimal str= mt.NumberOfDays__c;
dy=str;
System.debug('***************in else dy size******************'+dy);
}
}*/
List<DTP__c> newdtp= new List<DTP__c>();
System.debug('***************dy size******************'+dy);
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;
}
}
Regards,
Satakshi
I want functionality where according to month and year date will automatically added into record. How can we achive it?
public with sharing class Calender {
public List<DTP__c> mydtpList{get;set;}
public MTP__c obj{get;set;}
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);
obj = [Select Id, Month__c, Year__c, February__c, NumberOfDays__c from MTP__c where id=:tid ];
dy= obj.NumberOfDays__c;
if(obj.February__c !=null)
{
String str=obj.February__c;
dy=Decimal.ValueOf(str);
}
else
{
Decimal str= obj.NumberOfDays__c;
dy=str;
}
/*
for(MTP__c mt:obj)
{
if(mt.Month__c=='February')
{
String str=mt.February__c;
dy=Decimal.ValueOf(s
System.debug('***************in IF dy size******************'+dy);
}
else
{
Decimal str= mt.NumberOfDays__c;
dy=str;
System.debug('***************in else dy size******************'+dy);
}
}*/
List<DTP__c> newdtp= new List<DTP__c>();
System.debug('***************dy size******************'+dy);
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;
}
}
Regards,
Satakshi
As much as i can understand with this code i think based on your Month__c and Year__c of MTP__c Object you want to genreat a date so for that you can use below code: Replace year and month with your variable name: For more methods look on below link:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_date.htm
I am facing error that variable does not exist
Regards & thanks,
Satakshi
Create myDate variable on the top.
and then access it :