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

[EDA] Allow Customers The Ability To Backfill Missing Affiliation on Existing Student Course Connection #1068

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
31b5f71
initial commit
kdy618 Jan 27, 2020
aaefab6
test
kdy618 Jan 27, 2020
887695c
test2
kdy618 Jan 27, 2020
2f07ff9
batch class
kdy618 Jan 27, 2020
ea8ef28
fix format
kdy618 Jan 28, 2020
9124b08
removed log
kdy618 Jan 28, 2020
3c24537
removed extra spaces
kdy618 Jan 28, 2020
f6cd940
Merge dca551b3b0eb0b07ac2bf13be839787e88e8d84f into feature/kdy/backf…
salesforce-org-metaci[bot] Jan 28, 2020
131a50c
fix build error
kdy618 Jan 28, 2020
1dadd85
fixed field typo
kdy618 Jan 28, 2020
841f2b2
fixed typo 2
kdy618 Jan 28, 2020
4ed9918
fixed label issue
kdy618 Jan 28, 2020
b699ade
just fixed some tabbing issues, they are now spaces
Jan 29, 2020
a0dc81c
Merge ade28c87e216a5a32886d5578dc8e57904196e99 into feature/kdy/backf…
salesforce-org-metaci[bot] Jan 30, 2020
1e12322
updates from feedback
kdy618 Jan 30, 2020
fa4dab0
updated to the correct field
kdy618 Jan 30, 2020
7063790
added escapeSingleQuotes
kdy618 Jan 30, 2020
65c3201
just removing some tabbing and replacing with space
Jan 30, 2020
5ce33f5
Merge 74acfff8fe25dcf8873d691f9f68e3a3ad786431 into feature/kdy/backf…
salesforce-org-metaci[bot] Jan 30, 2020
81c0901
Merge a16df477ce0a7c7a19684a98c1901b25c06d4bf7 into feature/kdy/backf…
salesforce-org-metaci[bot] Jan 31, 2020
0baa0e6
Merge a2e6137a95ded2b7b55f10db5b3e93bdd56d2fbb into feature/kdy/backf…
salesforce-org-metaci[bot] Feb 2, 2020
423abba
Merge e7b3e2d5a5868a165e228b63acc64ba974587f9a into feature/kdy/backf…
salesforce-org-metaci[bot] Feb 6, 2020
48ef1e8
Merge 818db78c93b55dfc094b582e74489514d9d59537 into feature/kdy/backf…
salesforce-org-metaci[bot] Feb 7, 2020
b3a619b
Merge eded3ea3867508ba2116c20aef26754252c90df1 into feature/kdy/backf…
salesforce-org-metaci[bot] Feb 13, 2020
18a1395
Merge branch 'master' into feature/kdy/backfillAfifliationOnStudentCC
lifewithryan Feb 18, 2020
1d5f045
Merge f0d06f81f1bb6f1cff42176e45b2f6c881b6f734 into feature/kdy/backf…
salesforce-org-metaci[bot] Feb 20, 2020
3e70c7e
Merge branch 'master' of https://github.com/SalesforceFoundation/EDA …
kdy618 Feb 24, 2020
08cafbf
Merge 27b1f85feaa28f8af9680e8a6b16a3810fcaccec into feature/kdy/backf…
salesforce-org-metaci[bot] Feb 26, 2020
e65d41f
Merge 2cbe767e59016a4507721d922163d310ba154e2f into feature/kdy/backf…
salesforce-org-metaci[bot] Feb 26, 2020
f47aa37
Merge a88fe2498348c90c073741b6d8d2c81ce58f3946 into feature/kdy/backf…
salesforce-org-metaci[bot] Feb 28, 2020
efe039f
Merge 2b8d4560636044d7426d7c71ba864b0bf3c00145 into feature/kdy/backf…
salesforce-org-metaci[bot] Feb 29, 2020
320f9c1
Merge e1592703e204eaf8150b4882061b12f99483179a into feature/kdy/backf…
salesforce-org-metaci[bot] Mar 3, 2020
2876ce0
Merge branch 'master' into feature/kdy/backfillAfifliationOnStudentCC
lifewithryan Mar 9, 2020
d85152d
Merge 5db6eed5104cca1c5cf663eb849e89080ebfffbe into feature/kdy/backf…
salesforce-org-metaci[bot] Mar 10, 2020
43169a6
Merge 87ba97a357904f6ebcd3980c344db91c611da984 into feature/kdy/backf…
salesforce-org-metaci[bot] Mar 11, 2020
32a2450
Merge d4058834f1355611302d72bd47cb3dc399399ba4 into feature/kdy/backf…
salesforce-org-metaci[bot] Mar 11, 2020
fd13cee
Merge 34b58efee05c9d690d2e139958ab4dbb2cfbbe74 into feature/kdy/backf…
salesforce-org-metaci[bot] Mar 11, 2020
205dc45
Merge 5acc1db2e7c215bf09604d998d26d8792fd05093 into feature/kdy/backf…
salesforce-org-metaci[bot] Mar 11, 2020
401d1c3
Merge 16ba4c2d9039f79fd7ee0750c39fe180417d6fe3 into feature/kdy/backf…
salesforce-org-metaci[bot] Mar 13, 2020
b92a59e
Merge cba2d89183f8964f34e8c5c49a0b531b11e576dd into feature/kdy/backf…
salesforce-org-metaci[bot] Mar 16, 2020
4dea574
Merge 23bd5207c14deecb7694f755779e53b5278bfa52 into feature/kdy/backf…
salesforce-org-metaci[bot] Mar 17, 2020
841901f
Merge aa7858e650da129640c80909e5a8d8ded945eb50 into feature/kdy/backf…
salesforce-org-metaci[bot] Mar 18, 2020
a7e5dc7
Merge 4e7a0c0dc3cd3699848fb7f6e08837da4a90340d into feature/kdy/backf…
salesforce-org-metaci[bot] Mar 18, 2020
8d8e543
Merge 0b41d34ac0a6f1e29cfaef17fe46a6a990e9e120 into feature/kdy/backf…
salesforce-org-metaci[bot] Mar 23, 2020
dea6bac
Merge 1dc4d3631968160820b2d80c145dfaee805832dd into feature/kdy/backf…
salesforce-org-metaci[bot] Mar 27, 2020
cdf993b
Merge cd9398f5d552958dacd6b36dd2b4b54123916512 into feature/kdy/backf…
salesforce-org-metaci[bot] Apr 2, 2020
203dbb6
Merge 1404d08e21ac81c739292439850594e9fbbb6397 into feature/kdy/backf…
salesforce-org-metaci[bot] Apr 6, 2020
dccbfa7
Merge 1b1dfb37f3baef96cec94213262d6d9193198769 into feature/kdy/backf…
salesforce-org-metaci[bot] Apr 9, 2020
56c6761
Merge f6599f5b5b3ce6767f170376796f809f633370a8 into feature/kdy/backf…
salesforce-org-metaci[bot] Apr 10, 2020
328d028
Merge 23189ae5ad6a05a1f3a2468da2334c44d0f23325 into feature/kdy/backf…
salesforce-org-metaci[bot] Apr 20, 2020
9147e64
Merge 35f27fa7389df55612095bf88d47cbd974fa5c60 into feature/kdy/backf…
salesforce-org-metaci[bot] Apr 21, 2020
740b04e
Merge dc904f579ba1d4c4b2d87849d3972dd8f9bb5b67 into feature/kdy/backf…
salesforce-org-metaci[bot] Apr 23, 2020
7d53fbb
Merge 2c0061d137d1d9cec256cb6f17b820ac218c9fcd into feature/kdy/backf…
salesforce-org-metaci[bot] Apr 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/aura/STG_CMP_CourseConnections/STG_CMP_CourseConnections.cmp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<aura:component extends="c:STG_CMP_Base" controller="STG_CourseConnections">

<aura:attribute name="courseConnectionRecTypes" type="Map" />

<aura:attribute name="studentRecTypeId" type="String" />
<aura:attribute name="facultyRecTypeId" type="String" />
<aura:attribute name="studentRecTypeName" type="String" />
Expand All @@ -11,7 +9,7 @@
<aura:attribute name="startBackfillMessage" type="String" default="" />
<aura:attribute name="backFillToastIcon" type="String" default="" />
<aura:attribute name="backFillToastClass" type="String" default="" />

<div class="slds-hide" id="backFillToast" aura:id="backFillToast">
<div class="slds-box">
<div class="slds-notify_container slds-notify_container--inline">
Expand All @@ -31,7 +29,7 @@
</div>
</div>
</div>
</div>
</div>

<div id="relTabs" class="slds-tabs--scoped">
<ul class="slds-tabs--scoped__nav" role="tablist">
Expand All @@ -44,7 +42,6 @@
</ul>

<div aura:id="settsTabContent" class="slds-tabs__content" role="tabpanel">

<span class="{!and(not(v.isView), not(v.hierarchySettings.Enable_Course_Connections__c)) ? '' : 'slds-hide ' }">
<div class="slds-m-bottom--medium">
<div class="slds-notify_container">
Expand Down Expand Up @@ -79,6 +76,7 @@
<div class="slds-col slds-size--1-of-1">
<ui:outputText value="{!$Label.c.stgHelpEnableCourseConnections}" class="slds-text-body--small" />
</div>

<div class="slds-col slds-grid slds-m-top--medium">
<div class="slds-col slds-size--1-of-2">
{!$Label.c.stgDefaultStudentTypeTitle}
Expand Down Expand Up @@ -132,6 +130,7 @@
</div>
</div>
</span>

<div class="slds-grid slds-wrap">
<div class="slds-col slds-size--1-of-1">
<ui:outputText value="{!$Label.c.stgTitleCourseConnectionBackfill}" class="slds-text-body--small" />
Expand All @@ -157,6 +156,28 @@
<ui:button class="slds-button slds-button--neutral settings-edit-bttn" disabled="{!or(not(v.allowBackfill), v.backfillStarted)}" label="{!$Label.c.stgBtnRunBackfill}" press="{!c.startBackfill}"/>
</div>
</div>
<div class="slds-grid slds-grid--align-center slds-m-top--medium">
<div>
<ui:outputText value="{!v.startBackfillMessage}" class="slds-text-body--small" />
</div>
</div>

<hr/>

<div class="slds-grid slds-wrap">
<div class="slds-col slds-size--1-of-2">
{!$Label.c.stgTitleAffiliationBackfill}
<div class="slds-col slds-size--1-of-1">
<ui:outputText value="{!$Label.c.stgHelpAffilBackfill}" class="slds-text-body--small" />
</div>
</div>
<div class="slds-grid slds-grid--align-center slds-m-top--medium">
<lightning:button
label="Run Affiliation Backfill"
title="backfillAffiliation"
onclick="{!c.handleAffiliationBackfill}"/>
</div>
</div>
</div>
</div>
</aura:component>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
helper.startBackfill(component);
},

handleAffiliationBackfill : function(component, event, helper) {
helper.handleAffiliationBackfill(component);
},

closeBackFillToast: function(component, event, helper) {
helper.closeBackFillToast(component);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,74 @@
var action = component.get("c.getEnqueueCourseConnectionsBackfill");
action.setCallback(this, function(response) {
if(response.getState() === "SUCCESS") {
var successMessage = $A.get("$Label.c.stgCourseConnBackFillSuccess");
component.set('v.startBackfillMessage', successMessage);
component.set('v.backFillToastIcon', 'success');
component.set('v.backFillToastClass', 'slds-notify slds-notify_toast slds-theme_success');
var successMessage = $A.get("$Label.c.stgCourseConnBackFillSuccess");
component.set('v.startBackfillMessage', successMessage);
component.set('v.backFillToastIcon', 'success');
component.set('v.backFillToastClass', 'slds-notify slds-notify_toast slds-theme_success');
var tst = component.find("backFillToast");
$A.util.removeClass(tst, "slds-hide");
$A.util.addClass(tst, "slds-show");
window.setTimeout(
$A.getCallback(function() {
$A.util.removeClass(tst, "slds-show");
$A.util.addClass(tst, "slds-hide");
}), 5000
);
} else if(response.getState() === "ERROR") {
var errorMessage = $A.get("$Label.c.stgCourseConnBackFillError");
component.set('v.startBackfillMessage', errorMessage);
component.set('v.backFillToastIcon', 'error');
component.set('v.backFillToastClass', 'slds-notify slds-notify_toast slds-theme_error');
var tst = component.find("backFillToast");
$A.util.removeClass(tst, "slds-hide");
$A.util.addClass(tst, "slds-show");

window.setTimeout(
$A.getCallback(function() {
$A.util.removeClass(tst, "slds-show");
$A.util.addClass(tst, "slds-hide");
}), 5000
$A.getCallback(function() {
$A.util.removeClass(tst, "slds-show");
$A.util.addClass(tst, "slds-hide");
}), 5000
);

} else if(response.getState() === "ERROR") {
var errorMessage = $A.get("$Label.c.stgCourseConnBackFillError");
component.set('v.startBackfillMessage', errorMessage);
component.set('v.backFillToastIcon', 'error');
component.set('v.backFillToastClass', 'slds-notify slds-notify_toast slds-theme_error');
var tst = component.find("backFillToast");
$A.util.removeClass(tst, "slds-hide");
$A.util.addClass(tst, "slds-show");

window.setTimeout(
$A.getCallback(function() {
$A.util.removeClass(tst, "slds-show");
$A.util.addClass(tst, "slds-hide");
}), 5000
);
}
}
});
$A.enqueueAction(action);
},


handleAffiliationBackfill : function(component, event, helper) {
var action = component.get("c.executeAffiliationBackfillOnCourseConnection");
action.setCallback(this, function(response) {
if(response.getState() === "SUCCESS") {
var successMessage = $A.get("$Label.c.stgBackfillQueuedEmailSent");
component.set('v.startBackfillMessage', successMessage);
omponent.set('v.backFillToastIcon', 'success');
component.set('v.backFillToastClass', 'slds-notify slds-notify_toast slds-theme_success');
var tst = component.find("backFillToast");
$A.util.removeClass(tst, "slds-hide");
$A.util.addClass(tst, "slds-show");
window.setTimeout(
$A.getCallback(function() {
$A.util.removeClass(tst, "slds-show");
$A.util.addClass(tst, "slds-hide");
}), 5000
);
} else if(response.getState() === "ERROR") {
var errorMessage = $A.get("$Label.c.stgCourseConnBackFillError");
component.set('v.startBackfillMessage', errorMessage);
component.set('v.backFillToastIcon', 'error');
component.set('v.backFillToastClass', 'slds-notify slds-notify_toast slds-theme_error');
var tst = component.find("backFillToast");
$A.util.removeClass(tst, "slds-hide");
$A.util.addClass(tst, "slds-show");
window.setTimeout(
$A.getCallback(function() {
$A.util.removeClass(tst, "slds-show");
$A.util.addClass(tst, "slds-hide");
}), 5000
);
}
kdy618 marked this conversation as resolved.
Show resolved Hide resolved
});
$A.enqueueAction(action);
},

closeBackFillToast: function(component) {
var tst = component.find("backFillToast");
$A.util.removeClass(tst, "slds-show");
Expand Down
95 changes: 95 additions & 0 deletions src/classes/CCON_AffiliationBackfill_BATCH.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Copyright (c) 2020, Salesforce.org
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Salesforce.org nor the names of
its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author Salesforce.org
* @date 2020
* @group Course Enrollments
* @group-content ../../ApexDocContent/CourseEnrollments.htm
* @description This is a batch class that backfills existing Student Course Connection with missing Affiliation.
*/
public class CCON_AffiliationBackfill_BATCH implements Database.Batchable<SObject>{

public Database.Querylocator start(Database.BatchableContext bc) {
Id studentCCRecordTypeId = UTIL_CustomSettingsFacade.getSettings().Student_RecType__c;
String query = 'SELECT Id, Program_Enrollment__c, Affiliation__c ' +
'FROM Course_Enrollment__c ' +
'WHERE Affiliation__c = NULL AND Program_Enrollment__c != NULL AND RecordTypeId = :studentCCRecordTypeId';

return Database.getQueryLocator(String.escapeSingleQuotes(query));
}

public void execute(Database.BatchableContext bc, List<Course_Enrollment__c> returnCourseEnrollments){
Copy link
Contributor

Choose a reason for hiding this comment

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

What would be really cool and perhaps something for a future tech-debt item would be to be able to write this code once and have our triggerTDTM use it, as well as the BATCH process use it. Or at least parts of it. So something like a CourseEnrollmentService, etc. Don't have to do it now but definitely the types of things we should be thinking about. (Maybe the way we currently have it written wouldn't allows us to do it very easily. #ThinkingOutLoud

List<Id> pEnrollmentID = new List<Id>();
List<Course_Enrollment__c> courseEnrollmentsToUpdate = new List<Course_Enrollment__c>();

if (returnCourseEnrollments.size () > 0) {

for (Course_Enrollment__c enroll : returnCourseEnrollments) {
if (enroll.Program_Enrollment__c != NULL) {
pEnrollmentID.add(enroll.Program_Enrollment__c);
}
}

if (pEnrollmentID.size () > 0) {
List<Program_Enrollment__c> queryPE = [SELECT Id, Affiliation__c, Account__c
FROM Program_Enrollment__c
WHERE Id = :pEnrollmentID];
Map<Id, Program_Enrollment__c> pEnrollmentsMap = new Map<Id, Program_Enrollment__c>(queryPE);

for (Course_Enrollment__c courseEnroll : returnCourseEnrollments) {
kdy618 marked this conversation as resolved.
Show resolved Hide resolved
courseEnroll.Affiliation__c = pEnrollmentsMap.get(courseEnroll.Program_Enrollment__c).Affiliation__c;
courseEnroll.Account__c = pEnrollmentsMap.get(courseEnroll.Program_Enrollment__c).Account__c;
courseEnrollmentsToUpdate.add(courseEnroll);
}

}
}

if (courseEnrollmentsToUpdate.size() > 0) {
update courseEnrollmentsToUpdate;
}
}

public void finish(Database.BatchableContext bc) {
AsyncApexJob a = [SELECT Id, Status, JobType, NumberOfErrors,
JobItemsProcessed, TotalJobItems, CompletedDate,
ExtendedStatus, CreatedById, CreatedBy.Email
FROM AsyncApexJob
WHERE Id =:bc.getJobId()];

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: the spacing looks wonky here as well.

List<String> toAddresses = new List<String> {a.CreatedBy.Email};
mail.setToAddresses(toAddresses);
mail.setSubject('Backfill of Affiliation on Student Course Connection Status : ' + a.Status);
mail.setPlainTextBody('The batch Apex job processed ' + a.TotalJobItems +
' batches with '+ a.NumberOfErrors + ' failures.');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
5 changes: 5 additions & 0 deletions src/classes/CCON_AffiliationBackfill_BATCH.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>47.0</apiVersion>
<status>Active</status>
</ApexClass>
Loading