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
sundar s 24sundar s 24 

null point error

the highlighted line in blod says null point excemption any idea?

private static void getDates(String quoteId, CVData data) {
    zqu__Quote__c quote = getQuote(quoteId);
    data.quote = quote;
    data.changeEffectiveDate = quote.zqu__StartDate__c;
    data.subscriptionTermStartDate = quote.zqu__SubscriptionTermStartDate__c;
    // end of current term
    data.endOfCurrentTerm = getEndOfCurrentTerm(
        quote.zqu__SubscriptionTermStartDate__c,
        quote.zqu__StartDate__c,
        (Integer) quote.zqu__InitialTerm__c
    );
  public static Date getEndOfCurrentTerm(
      Date termStartDate,
      Date effectiveDate,
      Integer initialTerm) {
    List<Date> terms = new List<Date>();

    Integer numberOfTerms = initialTerm / 12;

    // make the terms list based on the initialTerm
    for (Integer i = 1; i <= numberOfTerms + 1; i++) {
      terms.add(termStartDate);
      termStartDate = termStartDate.addYears(1);  // here it shows error
    }
    System.debug(LoggingLevel.INFO, 'terms: ' + terms);
    System.debug(LoggingLevel.INFO, 'EffectiveDate: ' + effectiveDate);

    // check if the effective date is less than each term start date
    for (Integer i = 0; i < terms.size(); i++) {
      if (effectiveDate <= terms[i]) {
        return terms[i].addDays(-1);
      }
    }
Suraj Tripathi 47Suraj Tripathi 47
Hi sundar,

Your code is fine. Maybe you are getting this error because you would not have been pass the parameter properly in getEndOfCurrentTerm method.
You can take reference from this below code and pass the parameter in method like this:-
ClassName.getEndOfCurrentTerm(date.parse('06/07/2012'),date.parse('06/07/2018'),50)
In case you find any other issue please mention. 
If you find your Solution then mark this as the best answer. 
Suraj Tripathi 47Suraj Tripathi 47

Hi,
Please find the solution.

I think there is no data inside termStartDate that's why you are not able to add 1 year to it.

Just debug termStartDate. i.e     System.debug(termStartDate);

or

Date datobj;
Integer dy = termStartDate.day();
Integer mon = termStartDate.month();
Integer yr = termStartDate.year();

integer year =yr+1;

String termsDate=dy+'/'+mon+'/'+yr;

Please mark is as the Best Answer if it helps You

Thank You

sundar s 24sundar s 24
suraj startdate termStartDate is zqu__SubscriptionTermStartDate__c and the value is 2020-06-30. initially i thought the value is null but when i query in soql is has value what am i missing
sundar s 24sundar s 24
i will check on UAT , can i modify the code on UAT apex class , do i need to run test class again? on UAT , i just add system debug and see
Suraj Tripathi 47Suraj Tripathi 47
System.debug(termStartDate)
is data coming in termStartDate after debugging??
sundar s 24sundar s 24
when i debugged its giving value of the termstartdate 
ravi soniravi soni
hi sundar,
try following code and check still you are facing the same error?
private static void getDates(String quoteId, CVData data) {
    zqu__Quote__c quote = getQuote(quoteId);
    data.quote = quote;
    data.changeEffectiveDate = quote.zqu__StartDate__c;
    data.subscriptionTermStartDate = quote.zqu__SubscriptionTermStartDate__c;
    // end of current term
    data.endOfCurrentTerm = getEndOfCurrentTerm(
        quote.zqu__SubscriptionTermStartDate__c,
        quote.zqu__StartDate__c,
        (Integer) quote.zqu__InitialTerm__c
    );
}
  public static Date getEndOfCurrentTerm(
      Date termStartDate,
      Date effectiveDate,
      Integer initialTerm) {
    List<Date> terms = new List<Date>();

    Integer numberOfTerms = initialTerm / 12;

    // make the terms list based on the initialTerm
    for (Integer i = 1; i <= (numberOfTerms + 1); i++) {
		if(termStartDate != null){
      terms.add(termStartDate);
      termStartDate = termStartDate.addYears(1);  // here it shows error
    }
	}
    System.debug(LoggingLevel.INFO, 'terms: ' + terms);
    System.debug(LoggingLevel.INFO, 'EffectiveDate: ' + effectiveDate);

    // check if the effective date is less than each term start date
    for (Integer i = 0; i < terms.size(); i++) {
      if (effectiveDate <= terms[i]) {
        return terms[i].addDays(-1);
      }
    }
	  }


let me know if it helps you and mark it as best answer.
Thank you
sundar s 24sundar s 24
some how i feel the startdate overwrite and become null , what could be the reason , the quote owner only cloning the quote and he can view all the fields