Skip to content

Commit

Permalink
#299 changing logic so it gets all the result ids from the jobExcepti…
Browse files Browse the repository at this point in the history
…onId
  • Loading branch information
Daniel Ventura committed Dec 5, 2022
1 parent a80e128 commit bf46ae6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
15 changes: 10 additions & 5 deletions force-app/main/default/classes/mcdo_RunCopadoFunctionFromLWC.cls
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,24 @@ public with sharing class mcdo_RunCopadoFunctionFromLWC {
/**
* This function calls returns the last resultId from the received jobExecution
* @param jobExecutionId JobExecution Id from the jobExecution that we want to find the latest result id
* @return Returs the ID of the latest result created on the respective jobExecution
* @return Returs the list of IDs form the results created on the respective jobExecution
*/
@AuraEnabled
public static Id getResultId(String jobExecutionId) {
public static List<Id> getResultIds(String jobExecutionId) {
// get the newest result associated with this job execution
copado__Result__c result = [
copado__Result__c[] results = [
SELECT Id
FROM copado__Result__c
WHERE copado__JobStep__r.copado__JobExecution__c = :jobExecutionId
WITH SECURITY_ENFORCED
ORDER BY CreatedDate DESC
LIMIT 1
];
return result.Id;
List<Id> ids = new List<Id>();

for (copado__Result__c item : results) {
ids.add(item.Id);
}

return ids;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
// Apex functions to retrieve Recorddata from LWC
import ExecuteRetrieveFromCopado from "@salesforce/apex/mcdo_RunCopadoFunctionFromLWC.executeRetrieve";
import getMetadataFromEnvironment from "@salesforce/apex/mcdo_RunCopadoFunctionFromLWC.getMetadataFromEnvironment";
import getResultId from "@salesforce/apex/mcdo_RunCopadoFunctionFromLWC.getResultId";
import getResultIds from "@salesforce/apex/mcdo_RunCopadoFunctionFromLWC.getResultIds";

// "Commit Changes" Page Tab related
import COMMIT_PAGE_COMMUNICATION_CHANNEL from "@salesforce/messageChannel/copado__CommitPageCommunication__c";
Expand Down Expand Up @@ -157,7 +157,7 @@ export default class mcdo_RetrieveTable extends LightningElement {
showTable = false;
refreshButtonDisabled = true;
progressStatus = "Loading data";
progressResultId = undefined;
currentResultIds = undefined;

// Subscription related variables
getProgressSubscription = {};
Expand Down Expand Up @@ -334,9 +334,9 @@ export default class mcdo_RetrieveTable extends LightningElement {
* @returns {Promise<void>} resolves when the job is done
*/
async subscribeToCompletionEvent(jobExecutionId) {
// getting the last result id with this jobExecution
// get result ID from Job step related to job execution
try {
this.progressResultId = await getResultId({ jobExecutionId: jobExecutionId });
this.currentResultIds = await getResultIds({ jobExecutionId: jobExecutionId });
} catch (error) {
console.error(`ERROR STATUS: ${error.status} ${error.statusText}`);
}
Expand All @@ -345,8 +345,11 @@ export default class mcdo_RetrieveTable extends LightningElement {
if (response.data.payload.copado__Progress_Status__c === "Refresh done") {
this.unsubscribeThisSubscription(this.getProgressSubscription);
this.progressStatus = "Completed!";
} else if (response.data.payload.copado__ResultId__c === this.progressResultId) {
this.progressStatus = response.data.payload.copado__Progress_Status__c;
} else if (
this.currentResultIds.includes(response?.data?.payload?.copado__ResultId__c) &&
response?.data?.payload?.copado__Progress_Status__c
) {
this.progressStatus = response?.data?.payload?.copado__Progress_Status__c;
}
};

Expand Down

0 comments on commit bf46ae6

Please sign in to comment.