• M Rahman
  • NEWBIE
  • 5 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi
I'm trying to setup some test data for functional testing using Apex. The code needs to be run as with another user. Do you have any suggestion on this? I've tried System.runAs which cannot be used as the data setup class is not a test class.

Error: Compile Error: Illegal assignment from LIST<AggregateResult> to Date at line 9 column 7

 

trigger update_expiry_date on opportunity (after insert, after update) {
if (trigger.isUpdate) {
  List<Opportunity> opptemp = new List<Opportunity>();
  for(Opportunity o : trigger.new){
    String oppid = o.id;
    if ([SELECT COUNT(license_term_end__c) FROM opportunitylineitem WHERE opportunityid = :oppid] > 0) {
      String accid = o.accountid;
      Account updateacc = [SELECT id, expiry_date_2__c FROM account WHERE id = :accid];
      updateacc.expiry_date_2__c = [SELECT MAX(license_term_end__c) FROM opportunitylineitem WHERE opportunityid =:oppid];
      Database.update(updateacc);
      }
    }
  }
}

 Both of the fields expiry_date_2__c and license_term_end__c are date fields. Does the Max command just not work on this. That could be it I suppose. Please help thanks. I'm pretty much just trying to do a max roll-up and have it write the value to the date field expiry_date_2__c.

 

Thanks!!!