• Justin Cairns 9
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
We have a batch process that updates the # of business days in the current month on our account records.  It is returning a value of 21 for January even though the number of business days in January is 22.  We don't have any holidays built in our system for January.  Any suggestions as to what we are doing wrong would be appreciated.  

 global void execute(Database.BatchableContext BC, List<Account> scope) {
    
        if(scope.size()>0){
            list<Account> accountList = new list<Account>();
            list<BusinessHours> busHoursList = new list<BusinessHours>();
            busHoursList  = [SELECT ID FROM BusinessHours WHERE isActive = TRUE ORDER BY LastModifiedDate DESC LIMIT 1];
            if(busHoursList.size()>0){
                try{                
                    Date startDateMonth = Date.Today().toStartofMonth();
                    Date endDateMonth   = startDateMonth.addMonths(1).addDays(-1);
                    DateTime startTime = DateTime.newInstance(startDateMonth.year(), startDateMonth.month(), startDateMonth.day());
                    DateTime endTime = DateTime.newInstance(endDateMonth.year(), endDateMonth.month(), endDateMonth.day());
                    Decimal noOfWorkingDays = BusinessHours.diff(busHoursList[0].Id, startTime, endTime)/(3600*1000*24);
                    for(Account accObj : scope){
                        accObj.TAFS_Total_Business_Days_This_Month__c = noOfWorkingDays;
                        accountList.add(accObj);
                    }
                    if(!accountList.isEmpty()){
                        update accountList;
                    }                    
                }catch(DmlException dmlExcep){
                    //Do Nothing
                }
                catch(Exception excep){
                    //Do Nothing
                }           
            }               
        }
    }
Regex Ends with and Special Characters Questions
I'm currently using regex to determine if a value begins with certain characters like this.  (?i)^(BN|LID).*   This would match a string beginning with BN or LID and be case insensitive.  

I'm struggling with the syntax to apply the same logic to ends with.  I know you use the $ for ends with but I'm not sure of the order.  would this be correct?  *.(?i)(BN|LID)$

Also does anyone know how I could include a dash in the logic?  So I would want to know if a string begins with "A-" or ends with "A-1"  
Has anyone create a Activities List View Custom Console Component?  I would like to make the Activities List available in a Sales Console App but since Activities don't have a tab I can't just add it.  I think the best way would be to build a custom console component for the App.  Has anyone attempted this?  
We have a batch process that updates the # of business days in the current month on our account records.  It is returning a value of 21 for January even though the number of business days in January is 22.  We don't have any holidays built in our system for January.  Any suggestions as to what we are doing wrong would be appreciated.  

 global void execute(Database.BatchableContext BC, List<Account> scope) {
    
        if(scope.size()>0){
            list<Account> accountList = new list<Account>();
            list<BusinessHours> busHoursList = new list<BusinessHours>();
            busHoursList  = [SELECT ID FROM BusinessHours WHERE isActive = TRUE ORDER BY LastModifiedDate DESC LIMIT 1];
            if(busHoursList.size()>0){
                try{                
                    Date startDateMonth = Date.Today().toStartofMonth();
                    Date endDateMonth   = startDateMonth.addMonths(1).addDays(-1);
                    DateTime startTime = DateTime.newInstance(startDateMonth.year(), startDateMonth.month(), startDateMonth.day());
                    DateTime endTime = DateTime.newInstance(endDateMonth.year(), endDateMonth.month(), endDateMonth.day());
                    Decimal noOfWorkingDays = BusinessHours.diff(busHoursList[0].Id, startTime, endTime)/(3600*1000*24);
                    for(Account accObj : scope){
                        accObj.TAFS_Total_Business_Days_This_Month__c = noOfWorkingDays;
                        accountList.add(accObj);
                    }
                    if(!accountList.isEmpty()){
                        update accountList;
                    }                    
                }catch(DmlException dmlExcep){
                    //Do Nothing
                }
                catch(Exception excep){
                    //Do Nothing
                }           
            }               
        }
    }