• Qasim
  • NEWBIE
  • 25 Points
  • Member since 2015
  • Cloud Solutions Consultant


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies
Hi
I wonder if anybody can put me in the right direction.

I have a requirements to manage courses for volunteers. So there is a difinitive list of course from which a vlunteer ma be required to complete some depending on their skills and area in whcih they will be working. So at the time of creating a volunteer record the staff member will tick the courses that are applicable for that volunteer. For each course then some monitoring is required regarding when they complete the course, pass the exam, the validity of the course (from date of pasing) and when the course is next due.

Volunteers are setup as contacts unders a master Volunteer Account.

What would be recommended way to manage the above? 

many thanks

Qasim
  • May 25, 2017
  • Like
  • 0
Hi

Need help with writing a test on the following apex class. Basically what it does is that it checks all contacts for meeting criteria on two fields (Days_DBS_Submitted__c and GW_Volunteers__Volunteer_Status__c) and if condition is met it creates a task for the owner of the contact. - Thank you.

global class ContactProcessingBatch implements Database.Batchable<sObject>, Schedulable, Database.Stateful {

    //Variable Section
    global FINAL String strQuery;
    global List<String> errorMessages = new List<String>();
    
    global ContactProcessingBatch() { 
        this.strQuery = getBatchQuery();
    }
    
    //Returns the Query String to Batch constructor to fetch right records.
    private String getBatchQuery() {
        String strQuery = 'SELECT Id, Name, OwnerId FROM Contact WHERE Days_DBS_submitted__c > 30 AND GW_Volunteers__Volunteer_Status__c = \'New Sign Up\''; 
        return strQuery;
    }
    
    //Batch Start method
    global Database.QueryLocator start(Database.BatchableContext BC) {
        return Database.getQueryLocator(strQuery);
    }

    //Batch Execute method
    global void execute(Database.BatchableContext BC, List<sObject> scopeList) {
        System.debug(LoggingLevel.INFO, '== scopeList size ==' + scopeList.size());
        
        List<Contact> conList = (List<Contact>) scopeList;
        List<Task> taskList = new List<Task>();
        if(!conList.isEmpty()) {             
            for(Contact con: conList) {
                Task DBStask = New Task();
                DBSTask.Subject = 'Overdue DBS';
                DBSTask.Priority = 'Normal';
                DBSTask.Status = 'In Pogress';
                DBSTask.ActivityDate = system.today();
                DBStask.WhoId = con.id;
                DBStask.OwnerId=con.ownerId;
                taskList.add(DBSTask);
            }
            
            try {                    
                Database.SaveResult[] saveResults = Database.insert(taskList, false);
                for (Database.SaveResult sr : SaveResults) {
                    if(!sr.isSuccess()) {
                        for (Database.Error err : sr.getErrors()) {
                            errorMessages.add('Error: ' + err.getStatusCode() + ': ' + err.getMessage());
                        }
                        system.debug(sr.getErrors()[0].getMessage());
                    }
                }
                System.debug('errorMessages: '+errorMessages);
            } catch (System.Exception ex) {
                System.debug('An error occurred when inserting the Tasks: ' + ex.getMessage());
                return;
            }
        }
    }  

    //Batch Finish method for after execution of batch work
    global void finish(Database.BatchableContext BC) { 
        AsyncApexJob aaj = [Select Id, Status, NumberOfErrors, JobItemsProcessed, MethodName, 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[] {aaj.CreatedBy.Email};
        mail.setToAddresses(toAddresses);
        mail.setSubject('JOB Salesforce Contact Processing Batch: ' + aaj.Status);
        String bodyText='Total Job Items ' + aaj.TotalJobItems + ' Number of records processed ' + aaj.JobItemsProcessed + ' with '+ aaj.NumberOfErrors + ' failures.\n';
        bodyText += 'Number of Error Messages ' + errorMessages.size() + '\n';
        bodyText += 'Error Message' + String.join(errorMessages, '\n');
        mail.setPlainTextBody(bodyText);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
    
    //Method which schedules the ContactProcessingBatch
    global void execute(SchedulableContext sc) {        
        ContactProcessingBatch cpBatch = new ContactProcessingBatch();
        ID batchprocessid = Database.executeBatch(cpBatch);
    }
}
  • March 07, 2016
  • Like
  • 0
Hi
New to Apex coding and stuck on another problem, grateful for any help:

I need to run a scheduled job every day that looks at a field (Days_DBS_submitted_c) for all contacts and if value is over 30 it creates a task. It needs to do this for all contacts that meet this criteria but only once, it shouldnt create a task if the task was already cerated the previous day. I have some code below which I was using as a trigger but this need to be converted to a Apex class to be run as a scheduled job. Would be grateful for any help. 


trigger QM on Contact (after insert, after update) {
List<Task> taskToInsert = new list<Task>();
for (Contact Con : Trigger.New) {
if(con.Days_DBS_submitted_c>30){
Task DBStask = New Task ();
DBSTask.Subject = 'Overdue DBS';
DBSTask.Priority = 'Normal';
DBSTask.Status = 'In Pogress';
DBStask.WhoId = con.id;
DBStask.OwnerId=con.ownerId;
taskToInsert.add(DBSTask);
}
}
if(taskToInsert.size()>0){
insert taskToInsert;
}
}
 
  • March 06, 2016
  • Like
  • 0
Hi

I am very new to Apex and this is my first code so bound to have school boy errors, would appreciate help and direction:

Need to create a trigger on Contact, on create and update, where Number_Field__c is greater than 30 (This is a formula field that is created to accumulate the days passed since a certain form was submitted , which is a date field.

Task need to be created with some data; Subject, Priority, Status, Contact Name, Task to be assigned to Contact Owner

Here is the code which does create a task, but doesnt check the condition and docesnt insert the Contact Name in the Related to field:

1
2
3
4
5
6
7
8
9
10
11
trigger QM on Contact (after insert, after update) {
for (Contact Con : Trigger.New) {
List <Contact> DBSCheck = new List<Contact>();
DBSCheck = [SELECT Id, Name FROM Contact WHERE Number_Field__c > 30];
Task DBStask = New Task ();
DBSTask.Subject = 'Overdue DBS';
DBSTask.Priority = 'Normal';
DBSTask.Status = 'In Pogress';
DBStask.WhoId = (Con.Name);
Insert DBSTask;
}}


Thanks a lot for your help.


 




 
  • March 06, 2016
  • Like
  • 0
Hi
New to Apex coding and stuck on another problem, grateful for any help:

I need to run a scheduled job every day that looks at a field (Days_DBS_submitted_c) for all contacts and if value is over 30 it creates a task. It needs to do this for all contacts that meet this criteria but only once, it shouldnt create a task if the task was already cerated the previous day. I have some code below which I was using as a trigger but this need to be converted to a Apex class to be run as a scheduled job. Would be grateful for any help. 


trigger QM on Contact (after insert, after update) {
List<Task> taskToInsert = new list<Task>();
for (Contact Con : Trigger.New) {
if(con.Days_DBS_submitted_c>30){
Task DBStask = New Task ();
DBSTask.Subject = 'Overdue DBS';
DBSTask.Priority = 'Normal';
DBSTask.Status = 'In Pogress';
DBStask.WhoId = con.id;
DBStask.OwnerId=con.ownerId;
taskToInsert.add(DBSTask);
}
}
if(taskToInsert.size()>0){
insert taskToInsert;
}
}
 
  • March 06, 2016
  • Like
  • 0
Hi

I am very new to Apex and this is my first code so bound to have school boy errors, would appreciate help and direction:

Need to create a trigger on Contact, on create and update, where Number_Field__c is greater than 30 (This is a formula field that is created to accumulate the days passed since a certain form was submitted , which is a date field.

Task need to be created with some data; Subject, Priority, Status, Contact Name, Task to be assigned to Contact Owner

Here is the code which does create a task, but doesnt check the condition and docesnt insert the Contact Name in the Related to field:

1
2
3
4
5
6
7
8
9
10
11
trigger QM on Contact (after insert, after update) {
for (Contact Con : Trigger.New) {
List <Contact> DBSCheck = new List<Contact>();
DBSCheck = [SELECT Id, Name FROM Contact WHERE Number_Field__c > 30];
Task DBStask = New Task ();
DBSTask.Subject = 'Overdue DBS';
DBSTask.Priority = 'Normal';
DBSTask.Status = 'In Pogress';
DBStask.WhoId = (Con.Name);
Insert DBSTask;
}}


Thanks a lot for your help.


 




 
  • March 06, 2016
  • Like
  • 0