+ 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(
        (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++) {
      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:-
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

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


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
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(
        (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){
      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