• Patti Abeyratne
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Following code doesn't update the custom object on contact anybody can me help to find error

global class calculateBooking implements Database.Batchable<sObject>{
  //global  Integer intNumberOfBooking ;
  
    global Database.QueryLocator start(Database.BatchableContext BC){
        //String gstrQuery = 'SELECT Contact_ID__c, Most_Recent_Booking__c, Name,Last_6_Months__c from Booking_Details__c';
        String gstrQuery = 'SELECT ID,Name,Salesforce_Contact_ID__c from Contact';
        return Database.getQueryLocator(gstrQuery);
    } 


global void execute(Database.BatchableContext BC, List<sObject> scope){
    
    
     List<Booking_Details__c> listBookingInsert = new List<Booking_Details__c>();
      List<Booking_Details__c> listBookingUpdate = new List<Booking_Details__c>();
      List<Booking_Details__c> listBooking= [SELECT Booking_Salesforce_Contact_ID__c, Most_Recent_Booking__c, Name,Last_6_Months__c from Booking_Details__c];
     //List<Contact> listContact = new List<Contact>();
      for(SObject objSObject : scope)
      {
          //Booking_Details__c objBooking = (Booking_Details__c)objSObject;
          Contact objContact = (Contact) objSObject;
          Integer intNumberOfBooking = [SELECT count()FROM Booking__c WHERE Contact__C = :objContact.ID AND Date_Time__c = LAST_N_DAYS:365];
          for(Booking_Details__c bd: listBooking)
          {
           if (bd.Contact_ID__c==objContact.ID)
           {
                bd.Last_6_Months__c = intNumberOfBooking+6;
                //bd.Booking_Salesforce_Contact_ID__c= objContact.Salesforce_Contact_ID__c;
                //objBooking.Name =;
                listBookingUpdate.add(bd);         
           }
           
           
          }
      }
      //insert listBookingInsert;
        update listBookingUpdate;
      //System.debug('Update');
      

     
}
  
global void finish(Database.BatchableContext BC){
  //  System.debug(intNumberOfBooking);   
    System.debug('Finish');
    /*//Send an email to the User after your batch completes
            AsyncApexJob a =[SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
        TotalJobItems, CreatedBy.Email
        FROM AsyncApexJob WHERE Id =
        :BC.getJobId()];
        // Send an email to the Apex job's submitter
        // notifying of job completion.
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {a.CreatedBy.Email};
        mail.setToAddresses(toAddresses);
        mail.setSubject('Record Clean Up Status: ' + a.Status);
        mail.setPlainTextBody
        ('The batch Apex job processed ' + a.TotalJobItems +
        ' batches with '+ a.NumberOfErrors + ' failures.');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        */}
}
Can anybody correct this code or give me a code which summerize number of contacts on account?

global class scheduledCalculatebookings implements Schedulable {
   global void execute(SchedulableContext sc) {
       /* System.debug('Schedule');
      calculateBooking b = new calculateBooking();
      database.executebatch(b);*/
  
  
  
  
   Map<Id, List<Contact>> AcctContactList = new Map<Id, List<Contact>>();
    Set<Id> AcctIds = new Set<Id>();   
    List<Account> AcctList = new List<Account>();
    List<Account> AcctOld = new List<Account>();
    List<Contact> ConList = new List<Contact>();
    AcctOld = [SELECT Id FROM Account];
   
    for(Account old : AcctOld)
    {
        AcctIds.add(old.Id);
       
    if(AcctIds.size() > 0){
        ConList = [SELECT Id, AccountId FROM Contact WHERE AccountId IN : AcctIds];
       
        for(Contact Con : ConList) {
            if(!AcctContactList.containsKey(Con.AccountId)){
                AcctContactList.put(Con.AccountId, new List<Contact>());
            }
            AcctContactList.get(Con.AccountId).add(Con);     
        }                          
       
        System.debug('Account Id and Contact List Map is ' + AcctContactList);
           
        AcctList = [SELECT Open_Activity_Count_c__c FROM Account WHERE Id IN : AcctIds];
       
        for(Account Acc : AcctList) {
            List<Contact> ContList = new List<Contact>();
            ContList = AcctContactList.get(Acc.Id);
            Acc.Open_Activity_Count_c__c = ContList.size();
        }   
       
        System.debug('Account List is ' + AcctList);
        update AcctList;  
     }

     }
   
  
       
    //Send an email to the User after your batch completes
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    String[] toAddresses = new String[] {'test@gmail.com'};
    mail.setToAddresses(toAddresses);
    mail.setSubject('Apex Batch Job Calculate Bookings');
    mail.setPlainTextBody('The batch Apex job processed ');
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
     }
}
Can anybody correct this code or give me a code which summerize number of contacts on account?

global class scheduledCalculatebookings implements Schedulable {
   global void execute(SchedulableContext sc) {
       /* System.debug('Schedule');
      calculateBooking b = new calculateBooking();
      database.executebatch(b);*/
  
  
  
  
   Map<Id, List<Contact>> AcctContactList = new Map<Id, List<Contact>>();
    Set<Id> AcctIds = new Set<Id>();   
    List<Account> AcctList = new List<Account>();
    List<Account> AcctOld = new List<Account>();
    List<Contact> ConList = new List<Contact>();
    AcctOld = [SELECT Id FROM Account];
   
    for(Account old : AcctOld)
    {
        AcctIds.add(old.Id);
       
    if(AcctIds.size() > 0){
        ConList = [SELECT Id, AccountId FROM Contact WHERE AccountId IN : AcctIds];
       
        for(Contact Con : ConList) {
            if(!AcctContactList.containsKey(Con.AccountId)){
                AcctContactList.put(Con.AccountId, new List<Contact>());
            }
            AcctContactList.get(Con.AccountId).add(Con);     
        }                          
       
        System.debug('Account Id and Contact List Map is ' + AcctContactList);
           
        AcctList = [SELECT Open_Activity_Count_c__c FROM Account WHERE Id IN : AcctIds];
       
        for(Account Acc : AcctList) {
            List<Contact> ContList = new List<Contact>();
            ContList = AcctContactList.get(Acc.Id);
            Acc.Open_Activity_Count_c__c = ContList.size();
        }   
       
        System.debug('Account List is ' + AcctList);
        update AcctList;  
     }

     }
   
  
       
    //Send an email to the User after your batch completes
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    String[] toAddresses = new String[] {'test@gmail.com'};
    mail.setToAddresses(toAddresses);
    mail.setSubject('Apex Batch Job Calculate Bookings');
    mail.setPlainTextBody('The batch Apex job processed ');
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
     }
}

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!!!