function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Harsha508Harsha508 

updating date

Hi guys i am new to salesforce when i tried to update the date its showing Method does not exist or incorrect signature: TODAY()

please let me know how to do

here its my code

public class updatedate
{

public date update1()
{
Student__c s1 = [ select Closed_Date__c from Student__c];

if(s1.Closed_Date__c == null)
{
s1.Closed_Date__c = TODAY();
upsert s1;

}
}
public updatedate()
{
updatedate u = new updatedate();
u.update1();
}
}

thanks advance

neeedhelpneeedhelp

Replace Today() with System.Today(). In SF to get todays date we have to use as System.Today();.

 

Can you post your Vf page also.Seems there are mistakes in your class

Harsha508Harsha508
no sir i didn't create any vf page i am trying to update custom object field when the value is equal to null
and now its saying that non void method might not return a value might have statement after return statement
Harsha508Harsha508

i changed the code but still it saying non-void method might not return a value or might have statement after a return statement i not able to get it can any one please tell me why its saying

public class updatedate
{
public Student__c update1()
{
list<Student__c> st = new list<Student__c>();
for(Student__c s:[select Closed_Date__c from Student__c where Closed_Date__c = null])
{
s.Closed_Date__c = System.Today();
insert s;
return null;
}
}
public updatedate()
{
updatedate u = new updatedate();
u.update1();
}
}

neeedhelpneeedhelp
public Student__c update1()
{
list<Student__c> st = new list<Student__c>();
for(Student__c s:[select Closed_Date__c from Student__c where Closed_Date__c = null])
{
s.Closed_Date__c = System.Today();
insert s;
}
return null;

}

 Your return value should be outside the for loop. How you are going to use this class?