• Matt Gajda
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hi all,
 I am getting this error from a scheuled job. I understand that it is taking to much time to process and was hoping someone could take a look at the code for this job and make some reccomendations.

" Scheduler: failed to execute scheduled job: jobId: 707E000003iHjqz, class: common.apex.async.AsyncApexJobObject, reason: Apex CPU time limit exceeded"



Here is the Apex  Code:


global class FindLeadsScheduler implements Schedulable {
    
    global void execute(SchedulableContext ctx) {
        Integer Days = 31; //number of days after Leads becoming inactive
        Date lastDay = Date.Today() - Days;

        
        List<Lead> inactiveLeads = [
            SELECT Id, Project_Site__r.Unprotected_queue_name__c
            FROM Lead
            WHERE isConverted = false AND unprotected__c = false AND Lead.Date_of_last_contact__c < :lastDay
        ];
        
        List<Group> queues = [
            SELECT id, name
            FROM Group
        ];
        Map<String, Id> qMap = new Map<String, Id>();
        for(Group g:queues){
            qMap.put(g.name, g.id);
        }
        for(Lead l:inactiveLeads){
            Id leadQueue = qMap.get(l.Project_Site__r.Unprotected_queue_name__c);
            if(leadQueue != null){
                l.ownerid = leadQueue;
            }
        }
        
        update inactiveLeads;
    }

}



 Any help would be greatly appreciated.

Thanks,

Matt
Hello,
  I am the admin for a company that has an instance of SFDC that has a lot of customizations and my experience with apex is minimal, so until now i have been making a lot of declarative changes to complete tasks that are given to me. Most recently, i have been asked to not let anyone back date calls that they are making. I am hoping it is a subtle change to the code that i can make. Also, i will be using a Sandbox enviroment to test the changes. Here are some screen shots to give you an idea of my under standing of what is happening with the code. First is a screen shot of what the log a call VF page looks like to the end users. Second is what i am presuming to the be the code that makes that page. Also, would it be difficult to remove the reminder date/ time and reminder notes fields?
 I am open to all suggestions and words of wisdom that may help me understand why this works the way it does. 

Thanks in advance,

Matt
User-added image
User-added image
Hello,
  I am the admin for a company that has an instance of SFDC that has a lot of customizations and my experience with apex is minimal, so until now i have been making a lot of declarative changes to complete tasks that are given to me. Most recently, i have been asked to not let anyone back date calls that they are making. I am hoping it is a subtle change to the code that i can make. Also, i will be using a Sandbox enviroment to test the changes. Here are some screen shots to give you an idea of my under standing of what is happening with the code. First is a screen shot of what the log a call VF page looks like to the end users. Second is what i am presuming to the be the code that makes that page. Also, would it be difficult to remove the reminder date/ time and reminder notes fields?
 I am open to all suggestions and words of wisdom that may help me understand why this works the way it does. 

Thanks in advance,

Matt
User-added image
User-added image