[SalesForce] Date arithmetic expressions must use Integer or Long arguments

I'm having trouble with something I think should be really simple! I have two fields: ts2__Start_Date__c and End_Date__c that are of Date type.

I've got the following variables:

public Date startDate {
  get;
  set;
}

public Date endDate {
  get;
  set;
}

The following query:

projectQuery = 'SELECT Name, List__c, Objectives__c, ts2__Start_Date__c, End_Date__c FROM ts2__Project_Job__c WHERE ts2__Project_Manager__c = \'' + user + '\' AND Project_Status__c != \'Completed\' LIMIT 1';

And the following loop which should simply assign the values of the one queried row to the variables.

for (ts2__Project_Job__c p : Database.query(projectQuery)) {
  accountsList += p.List__c;
  objectives += p.Objectives__c;
  startDate += p.ts2__Start_Date__c;
  endDate += p.End_Date__c;
}

For some reason though, I'm getting the error:

Date arithmetic expressions must use Integer or Long arguments

Any reason why I'd be getting this error?

Thanks!

Best Answer

Embarrassing to answer you own question but I figured I'd leave a response just in case someone else needs it!

Because I was using...

startDate += p.ts2__Start_Date__c;
endDate += p.End_Date__c;

... Using "+=" rather than "=", Salesforce is appending the date to what I assume is "null".

Rookie mistake but hopefully this might help someone!

Thanks.

Related Topic