• thekid12345
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 20
    Replies
The goal is to gather all completed tasks who record type is Implementation Worklog. For example, say I have 3 tasks that are of the type 'Troubleshooting' and each task has a number of hours associated with each task. (i.e. Task 1 6hrs troubleshooting, Task 2 5hrs troubleshooting, Task 3 2hrs torubleshooting.) . I want to sum up the tasks so 14 hours and put the sum into a field on the parent record, which I believe I am doing in the code below. The issue is that not all appropriate parent records are being aggregated correctly. When I check Apex Jobs, it says only 9 jobs have ran when executing anonymous.
global class ProServAutomationBatch implements Database.Batchable<SObject>, Schedulable, Database.Stateful{

Id TaskLogRecordTypeId = Schema.SObjectType.Task.getRecordTypeInfosByName().get('Implementation Worklog').getRecordTypeId();
String comp = 'Completed';

private static Map<Id, Decimal> proServ_HoursSpent = new Map<Id, Decimal>();
private static Map<Id, Decimal> onBoarding_HoursSpent = new Map<Id, Decimal>();
private static Map<Id, Decimal> troubleShooting_HoursSpent = new Map<Id, Decimal>();
private static Map<Id, Decimal> internal_HoursSpent = new Map<Id, Decimal>();


Decimal proServ_currentHoursSpent; 
Decimal onBoarding_currentHoursSpent; 
Decimal troubleShooting_currentHoursSpent;
Decimal internal_currentHoursSpent;

 Decimal proServ_hoursPerProject = 0;
    Decimal totalProServ = 0;
//Decimal proServ_HoursSpent;
//Decimal onBoarding_HoursSpent;
//Decimal troubleShooting_HoursSpent;
//Decimal internal_HoursSpent;
//Set<Id> impProjectIds = new Set<Id>();

global Database.QueryLocator start(Database.BatchableContext BC){ //Queries for all Task whose status is completed and where the Task record type is Implementation Worklog
//return Database.getQueryLocator([SELECT ProServ_Hours_Spent__c, WhatId, Implementation_Type__c FROM Task WHERE Status = :comp AND WhatId IN :implementationProjectToTask.keySet() AND RecordTypeId = :TaskLogRecordTypeId]);
return Database.getQueryLocator([SELECT ProServ_Hours_Spent__c, WhatId, Implementation_Type__c FROM Task WHERE Status = :comp AND RecordTypeId = :TaskLogRecordTypeId ORDER BY WhatId]);
}

// Execute Logic
global void execute(Database.BatchableContext BC, List<Task> workLogTasks){


    Set<Id> impProjectIds = new Set<Id>();
    List<Implementation_Project__c> iP = [SELECT ProServ_Hours_Spent__c,Implementation_Hours_Spent__c, Troubleshooting_Hours__c,Internal_Project_Hours_Spent__c FROM Implementation_Project__c WHERE id in :impProjectIds];
    for(Task t : workLogTasks){
        Decimal hoursTotal = proServ_HoursSpent.get(t.WhatId) == null ? 0 :  proServ_HoursSpent.get(t.WhatId);
        Decimal hoursTotal2 = troubleShooting_HoursSpent.get(t.WhatId) == null ? 0 :  troubleShooting_HoursSpent.get(t.WhatId);
        Decimal hoursTotal3 = onBoarding_HoursSpent.get(t.WhatId) == null ? 0 :  onBoarding_HoursSpent.get(t.WhatId);
        Decimal hoursTotal4 = internal_HoursSpent.get(t.WhatId) == null ? 0 :  internal_HoursSpent.get(t.WhatId);
        if(t.Implementation_Type__c == 'ProServ')
        {   
            proServ_currentHoursSpent = t.ProServ_Hours_Spent__c;
            //impProjectIds.add(t.WhatId);
            if (proServ_HoursSpent != null){
                proServ_HoursSpent.put(t.WhatId, hoursTotal + proServ_currenthoursSpent);
                System.debug('ProServ:' + proServ_HoursSpent);
            }
            impProjectIds.add(t.WhatId);
        }


         //System.debug('ProServ:' + proServ_currentHoursSpent);

        if(t.Implementation_Type__c == 'Troubleshooting')
        {
            troubleShooting_currentHoursSpent = t.ProServ_Hours_Spent__c;
            //impProjectIds.add(t.WhatId);
            if (troubleShooting_HoursSpent != null){
                troubleShooting_HoursSpent.put(t.WhatId, hoursTotal2 + troubleShooting_currentHoursSpent);
            }
            impProjectIds.add(t.WhatId);
        }

        System.debug('TroubleShooting:' + troubleShooting_HoursSpent);

        if(t.Implementation_Type__c == 'Onboarding')
        {
            onBoarding_currentHoursSpent = t.ProServ_Hours_Spent__c;
            //impProjectIds.add(t.WhatId);
             if (onBoarding_HoursSpent != null){
                onBoarding_HoursSpent.put(t.WhatId, hoursTotal3 + onBoarding_currentHoursSpent);
            }
            impProjectIds.add(t.WhatId);
        }
        System.debug('Onboarding:' + onBoarding_HoursSpent);

        if(t.Implementation_Type__c == 'Internal')
        {
            internal_currentHoursSpent = t.ProServ_Hours_Spent__c;
            //impProjectIds.add(t.WhatId);
             if (internal_HoursSpent != null){
                internal_HoursSpent.put(t.WhatId, hoursTotal4 + internal_currentHoursSpent);
            }  
            impProjectIds.add(t.WhatId);
        }
        System.debug('Internal:' + internal_HoursSpent);
    }


    for(Implementation_Project__c impProject : iP){

            impProject.ProServ_Hours_Spent__c = NULL;
            impProject.Implementation_Hours_Spent__c = NULL;
            impProject.Troubleshooting_Hours__c = NULL;
            impProject.Internal_Project_Hours_Spent__c = NULL;

            impProject.ProServ_Hours_Spent__c = proServ_HoursSpent.get(impProject.Id);
            impProject.Implementation_Hours_Spent__c = onBoarding_HoursSpent.get(impProject.Id);
            impProject.Troubleshooting_Hours__c = troubleShooting_HoursSpent.get(impProject.Id);
            impProject.Internal_Project_Hours_Spent__c = internal_HoursSpent.get(impProject.Id);

            //System.debug('Internal' + internal_currentHoursSpent);
            System.debug('ProServ' + proServ_currentHoursSpent);
            //System.debug('Onboarding' + onBoarding_currentHoursSpent);
            //System.debug('Troubleshooting' + troubleShooting_currentHoursSpent);


    }
    Database.update(iP, false);
}

global void execute(SchedulableContext sc){

}

   global void finish(Database.BatchableContext BC){
        // Logic to be Executed at finish
   }
}

 
For Example, below is my class that I want to reference in the batch class.  Is there a way where I can schedule the class called Test and reference it in the Batch class?
public class Test{
//Code to do updates
}
global class ExampleBatchClass implements Database.Batchable<sObject>{

        global ExampleBatchClass(){
                   // Batch Constructor
        }
       
        // Start Method
        global Database.QueryLocator start(Database.BatchableContext BC){
         return Database.getQueryLocator(query);
        }
      
      // Execute Logic
       global void execute(Database.BatchableContext BC, List<sObject>scope){
              // Logic to be Executed batch wise      
     
       }
     
       global void finish(Database.BatchableContext BC){
            // Logic to be Executed at finish
       }
    }


 
global class AcrUpdateContact implements Database.Batchable<SObject>, Schedulable{
     public Database.QueryLocator start(Database.BatchableContext BC)
    {
        //String query = 'SELECT ContactId FROM AccountContactRole WHERE Role := Primary Contact';
        String query = 'Select Id, (SELECT ContactId,Role FROM AccountContactRoles WHERE Role =: Primary Contact) from Account WHERE Id IN(Select AccountID from AccountContactRole)';
      
        return Database.getQueryLocator(query);
    }
    public void execute(Database.BatchableContext BC, List<Contact> cont)
    {
        for(Contact c : cont)
        {
            c.Status__c = 'Open';
            system.debug(c);
        }
        update cont;
    }
    global void execute(SchedulableContext sc){
        //Database.executeBatch(this);
    }
    global void finish(Database.BatchableContext BC) {
        
    }
}
The goal is when an account contact role is set to Primary Contact, update the associated Contact's status field to open.  I know that account contact roles is very limited in that we can not trigger anything off of that object.  Was wondering if the code above is correct.
 
What would be the best way to go about this?  IMO, I would have a trigger off the AccountContactRole.  Any other ideas / templates?
In my Class I have this method 
global class Queue{

public static void send(List<ListRequests> requests){...}

}
In my Trigger, I initialize the class and want to call the Apex class method
Queue sendToQueue = new Queue();

List<String> lead = new List<String>();

sendToQueue.send(leads);
It is throwing an error saying 

Method does not exist or incorrect signature
Is there a way in the Process builder where you can convert the WhoId to the name of a Lead or Contact. 
I am trying to create a workflow formula that parses the Comments section on a Task. Comments on the Task object will always have 'Dialed: (999)925 - 1234'. I want to extract (999)999 - 1234 and have that map to another custom field I have on the task object.
So far I have: IF(Comments(Contains('Dialed'(
not sure if this is the right way to go about this.
For Example, below is my class that I want to reference in the batch class.  Is there a way where I can schedule the class called Test and reference it in the Batch class?
public class Test{
//Code to do updates
}
global class ExampleBatchClass implements Database.Batchable<sObject>{

        global ExampleBatchClass(){
                   // Batch Constructor
        }
       
        // Start Method
        global Database.QueryLocator start(Database.BatchableContext BC){
         return Database.getQueryLocator(query);
        }
      
      // Execute Logic
       global void execute(Database.BatchableContext BC, List<sObject>scope){
              // Logic to be Executed batch wise      
     
       }
     
       global void finish(Database.BatchableContext BC){
            // Logic to be Executed at finish
       }
    }


 
I am trying to create a workflow formula that parses the Comments section on a Task. Comments on the Task object will always have 'Dialed: (999)925 - 1234'. I want to extract (999)999 - 1234 and have that map to another custom field I have on the task object.
So far I have: IF(Comments(Contains('Dialed'(
not sure if this is the right way to go about this.