Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close recruitment optimization #126

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

Robjar816
Copy link

The following are the changes made:

  • BZ_CloseRecruimentController code was optimized to avoid CPU Limit exceptions.
  • Created BZ_CloseRecruimentBatchJob and BZ_CloseRecruimentScheduler to schedule the batch job
  • Test classes were implemented.

Robjar816 added 11 commits March 4, 2019 14:55
Batch job to move campaign members to new campaign.
Test Classes for BZ_CloseRecruitmentBatchJob and BZ_CloseRecruitmentSchedule
Updated test class for BZ_CloseRecrutimentController_TEST
Added new fields to VF page to populate fields in the new campaign.
/**
* Handles BZ_CloseRecruitmentController actions of the campaign related CampaignMembers processing for large records.
*/
global class BZ_CloseRecruitmentBatchJob implements Database.Batchable<sObject> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this have to be global? Isn't public sufficient?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standard syntax for a batch class use to be global but I have updated the access modifier to public.

* Handles BZ_CloseRecruitmentController actions of the campaign related CampaignMembers processing for large records.
*/
global class BZ_CloseRecruitmentBatchJob implements Database.Batchable<sObject> {
global final String Query;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we declare the variable Query global, doesn't that mean everywhere in all Apex code across the entire org this can only exist once? That seems messy. Shouldn't we declare the access level to be the minimum amount possible? E.g. if the Query variable only needs to be accessed inside the BZ_CloseRecruitmentBatchJob, then it should be private.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes have been completed.

* Handles BZ_CloseRecruitmentController actions of the campaign related CampaignMembers processing for large records.
*/
global class BZ_CloseRecruitmentBatchJob implements Database.Batchable<sObject> {
global final String Query;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why is this capitalized? The general convention we use in the code base is that classes are capitalized, all class member variables start with m_ and are private, if we need to expose a class member publicly, we use a property with a get; set;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes have been completed.

* Used to collect the records or objects to be passed to the interface method execute for processing.
*/
global Database.QueryLocator start(Database.BatchableContext batchableContext){
return Database.getQueryLocator(query);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the query parameter passed to getQueryLocator(query) defined? Is this the same Query variable set in the constructor? If so, let's be consistent with the case of the variables.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is referring to the same variable as apex code is not case sensitive. Changes have been made to be consistent.


//Check if campaign members List is not null and size is greater than zero
if(campaigns!=null && campaigns.size()>0){
system.debug('campaigns list--'+campaigns.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all system.debug() calls, can we prefix the call with the name of the class and method it was logged from? Have a look at all the other places we use system.debug() in the code. This example would be BZ_CloseRecruitmentBatchJob.execute(): 'campaigns list size='+campaigns.size()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes have been completed.

@sadleb
Copy link
Contributor

sadleb commented Mar 21, 2019

Generally, the extensions we use are .apxc for Apex classes, .apxt for Apex triggers, and .vfp for Visualforce pages. Can we be consistent? Can you rename the .cls classes to .apxc ?

}
System.Debug('BZ_CloseRecruitmentDatabaseChangesQueueable.execute(): end');
catch(Exception ex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why catch and throw? Why not just let it bubble up?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by bubble up?

try{
if(m_campaign!=null)
{
// Campaign Details Section
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not nearly as maintainable as the prior code. Before, when we used the BZ_ClonePlusController it dynamically copied all Tasks/Activities/CampaignMembers/Fields. Now, whenever we add a new field to a Campaign that we want preserved, we have to update this code. If copying over every field manually is the only way we can do this with the new approach, we need a way to detect when a new field is added to the Campaign but not added to this section. Maybe add a test that looks at all the fields on a Campaign Member, excludes any we know we don't care about, and then tests that all those left are copied over after CloseRecruitement? That way, if we add a new field and forget to add a line here, the test fails unless we either copy it or explicitly exclude it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made major changes to this part of code. BZ_ClonePlusController is being used to dynamically copy only the campaign.

Boolean foundNoTimeTask = false;
Boolean foundWaitlistReinviteTask = false;
Boolean foundNoTimeReinviteTask = false;
for (Task t : tasksNotPurged)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to all the tests around the proper Tasks/Activities being copied over?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functionality is tested in BZ_CloseRecruitmentControllerBatchJob_Test.

campaign.EndDate=Date.today();
insert campaign;
// insert 100 CampaignMembers
List<CampaignMember> campaignMembersToInsert = new List<CampaignMember>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a more maintainable way to handle this is to get the list of CampaignMembers that should be copied over to the new Campaign and running ClonePlusController on each of them to clone their Activities/Tasks/Fields and then put them in the new campaign.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants