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
dotnet developedotnet develope 

how to assign value for date of month() to integer value?

hi all,
i have written a class in eclipse 3.3x and i want to deploy into production.
for that i have tested the code ,but i that code it is giving error.
      -:the code is in below:-
lead l=new lead();
l=[Select id,Start_date__c from lead where lastname=:'test1'];
date date1=l.Start_date__c;
Integer imon=date1.month();       ------------- here it is giving error
pls help me to solve the issue. and give me the suggestion for how to get month value to an integer variable.
Thanks & Regards
Mahesh Chilaka
Ron HessRon Hess
I'm guessing that start_date__c is null, and you are dereferencing without checking for null first.

i have to guess, unless you can share the error message produced by eclipse run tests.
dotnet developedotnet develope

hi ron,

i am in critical situation, as per client requirement i have written a class in sandbox. its working fine.

when it come to test coverage in eclipse. it was not giving more then 15% .

i want to give the whole code but blog is not supporting more the 20000 characters.

a sample of that code is in below.


global class LeadtoContactConversionClass{
WebService static String leadconvert(string id) {

Lead l = new Lead();
Contact c= new Contact();
Contact c_update=new Contact();
Contact c_create =new Contact();
Account a= new Account();
Contact_Commitment__c cust_Commit = new Contact_Commitment__c();
String str,strid='',FName='',LName='',fiscalyear='';
Integer commit_val=0,ival=0,count_c=0;
string csi_tags,comm_sub,commit_name,info,csi_tag,commsub,lead_commsub,l_csi;
boolean ser_email;
Integer len_l,len_c;
string email1='',email2='';
Integer imon=0,iyear=0; 
//string id
//string id='00QT0000004S0y7';
 //Date date1;
l=[Select Address_type_1__c, Address_Type_2__c, City, City_1__c, City_2__c,Communications_Subscriptions__c, Company,Country, Country_1__c, Country_2__c, CreatedDate,CSI_Events_email_list__c, CSI_Tag__c, Description,Commitment_Type__c,Email, Email_1__c, Email_2__c, Email_2_type__c, email_type__c,Commitment_Comments__c,Commitment_Description__c,Commitment_Manager__c,commitment_name__c,Commitment_Role__c,Start_Date__c,End_Date__c, Event_2__c, Fax,Fax_2__c, FirstName, Forces_For_Good__c, HasOptedOutOfEmail, Id, Industry,Information_request__c, LastName, LeadSource, MobilePhone, Name, Phone,Phone_2__c, Phone_2_type__c, phone_type__c, PostalCode, Preferred_Address__c, RecordTypeId,Salutation, SER_email_list__c,State, State_2__c, State_Province_1__c, Status,Stage__c,Street, Street_Address__c, Street_Address_1__c, Street_Address_2__c, SUID__c, SystemModstamp, Title, Website,Zip_Code_2__c, Zip_Postal_Code_1__c from Lead where Id =:id];
//c=[Select Name,FirstName,LastName from Contact where and (( Account.Name=:l.Company) or (Email=:l.Email or Email_2__c=:l.Email_2__c) or (Email=:l.Email_2__c or Email_2__c=:l.Email) )];
//count_c=[Select Count() from Contact where and (( Account.Name=:l.Company) or(Email=:l.Email or Email_2__c=:l.Email_2__c) or (Email=:l.Email_2__c or Email_2__c=:l.Email) )];
date date1 = l.Start_Date__c;
//date date1 = Date.newInstance(l.Start_Date__c.year(),l.Start_Date__c.month(),;//

 //date date1 = l.Start_Date__c;
 imon =date1.month();             ---------- error is this line is not covered.
 iyear =date1.year();       ---------- error is this line is not covered.


 if(imon>8)  ---------- error is this line is not covered.

  fiscalyear=''+(iyear+1); ---------- error is this line is not covered.


 string l_commsub='',csi_events='',commsub_str;
 if(l.LeadSource=='Online Registration')    ---------- error is this line is not covered.
    l_commsub = l.Communications_Subscriptions__c+';CSI Newsletter';---------- error is this line is not covered.
    l_commsub = 'CSI Newsletter'; 
   l_commsub = l.Communications_Subscriptions__c; ---------- error is this line is not covered.


static testMethod void myTest()
  Lead l1=new Lead();
  l1=[Select Id,FirstName,LastName from Lead where LastName=:'Test1'];
  leadconvert(l1.Id); }

 in this class the test method is myTest(). the record of 'Test1' have all the field have full data.

for any  more clarification. my emaild ''.


thanks & regards,

Mahesh Chilaka.