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

the bold line null point it seems the value is null , what is termstartdate here  pls suggest me

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); // this give null point error
    }
Surya GSurya G
Hi Sundar, 

seems like termStartDate has null value, can you check termStartDate has value before entering for loop, because null pointer error happens when we try to do any fucntion on null vale.

Thanks
Surya G
sundar s 24sundar s 24
Surya
    here what is the field in termstart date in the loop.
Surya GSurya G
Hi Sundar, 

termStartDate is date value which you are passing when you are calling this method 

getEndOfCurrentTerm(Date termStartDate, Date effectiveDate, Integer initialTerm)

 
sundar s 24sundar s 24
am not good in code from where this value is retrieved. 
Surya GSurya G
HI Sundar, 
post the full code where you are calling this method, we can see where it is going wrong
sundar s 24sundar s 24
surya pls find below code i highlithted in bold the error line

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);
      }
    }