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
Brad007Brad007 

Illegal format string to date .

Config ObjectHi, this is my custom object. i need to pull the survey date value from here to my class where i need to update a field. the code is below the object. please suggest. Config Object HostFamily_Survey
 
Config Object Detail
Survey_NameHostFamily_SurveyOwner
Used In..Survey Code  
HF Survey CodeHF1MoArv  
SOQL_QuerySelect o.Id, o.Account.Id, o.AccountId, o.Account.Survey_Opp_Id__c, o.Account.Survey_Dt__c, o.Account.Survey_Code__c,
o.Survey_Opp_Id_Match__c ,
o.Account.Name
From Opportunity o
where o.StageName='Active'
AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30
AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60
AND o.Survey_Opp_Id_Match__c='No'
  
SurveyDateToday()  
Created By2/7/2011 11:31 AMLast Modified By

3/28/2011 1:06 PM

 

 

 

public class HFSendSurveyClass {
    public void SendSurvey()
    {
        
        Date hfsurvey;        
      //Get the most recently created config object.
     Config_Object__c config = [Select HFSurveyCode__c, SurveyDate__C, SOQL_Query__C from Config_Object__C
                                where Name ='HostFamily_Survey'];
       
     List<Opportunity> oppList = Database.query(config.SOQL_Query__c);        
     
     List<Account> accList = new List<Account>();             
           for(Opportunity opp:oppList)
             {
                if(opp.AccountId!= null)
                {
                  Account acc = opp.Account;
                  hfsurvey = Date.valueOf(config.SurveyDate__c);
                  if(opp.Survey_Opp_Id_Match__c== 'No')
                  {
                     string oppcode= opp.Id;
                     acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c);
                     acc.Survey_Dt__c = hfsurvey;
                     acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                  }
                                     
            else  if(acc.Survey_Code__c != String.valueOf(config.HFSurveyCode__c))    
                   {
                     string oppcode= opp.Id;
                     acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c);
                     acc.Survey_Dt__c =  hfsurvey;
                     acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                   }
                  
                 accList.add(acc);
                 //System.assertEquals(acc.Survey_Dt__c,Date.valueOf(config.SurveyDate__c) ) ;
                }
             }
       update accList;                            
     }    
}

 

 

 

 

 

The marked field is where i should be update the value frim the custome object. The surveydate in custom object is string type and the Survey_Dt__c field is a date field. and should be able to add days or change the date so i want to pass the line of code for date as a string and pick it up in my class to update it with that date.

 

Please suggest thanks in advance.

 

 


 

 

Ritesh AswaneyRitesh Aswaney

You might want to check the format in which the string dates are stored. Possibly also add a not null check, because if the string dates happened to be null on any records, they would return an Invalid Date Exception.

Salesforce accepts the YYYY-MM-DD as a valid format for dates (though there is something about locales and valid date formats)

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_date.htm