Skip to content

Commit

Permalink
Merge pull request #946 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
modularize code
  • Loading branch information
ashitsalesforce authored Jan 14, 2024
2 parents b82efb5 + ff1385b commit 39e2666
Showing 1 changed file with 37 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,7 @@ public PartnerLoadVisitor(Controller controller, ILoaderProgress monitor, DataWr
@Override
protected void loadBatch() throws DataAccessObjectException, LoadException {
Object[] results = null;
Config config = this.controller.getConfig();
OwnerChangeOption keepAccountTeamOption = new OwnerChangeOption();
OwnerChangeOption[] ownerChangeOptionArray;
if (config.getBoolean(Config.PROCESS_KEEP_ACCOUNT_TEAM)
&& "Account".equalsIgnoreCase(config.getString(Config.ENTITY))) {
// Support for Keeping Account keepAccountTeam during Account ownership change
// More details at https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_header_ownerchangeoptions.htm
keepAccountTeamOption.setExecute(true);
keepAccountTeamOption.setType(OwnerChangeOptionType.KeepAccountTeam); // Transfer Open opportunities owned by the account's owner
ownerChangeOptionArray = new OwnerChangeOption[] {keepAccountTeamOption};
} else {
// clear ownerChangeOptions from the existing connection otherwise.
ownerChangeOptionArray = new OwnerChangeOption[] {};
}
this.controller.getPartnerClient().getClient().setOwnerChangeOptions(ownerChangeOptionArray);

setHeaders();
try {
results = executeClientAction(getController().getPartnerClient(), dynaArray);
} catch (ApiFault e) {
Expand All @@ -85,7 +70,20 @@ protected void loadBatch() throws DataAccessObjectException, LoadException {
handleException(e);
}

// set the current processed
writeOutputToWriter(results);
setLastRunProperties(results);

// update Monitor
getProgressMonitor().worked(results.length);
getProgressMonitor().setSubTask(getRateCalculator().calculateSubTask(getNumberOfRows(), getNumberErrors()));

// now clear the arrays
clearArrays();

}

private void setLastRunProperties(Object[] results) throws LoadException {
// set the last processed row number in the config (*_lastRun.properties) file
int currentProcessed;
try {
currentProcessed = getConfig().getInt(LastRun.LAST_LOAD_BATCH_ROW);
Expand All @@ -102,16 +100,28 @@ protected void loadBatch() throws DataAccessObjectException, LoadException {
getLogger().error(errMsg, e);
handleException(errMsg, e);
}

writeOutputToWriter(results);

// update Monitor
getProgressMonitor().worked(results.length);
getProgressMonitor().setSubTask(getRateCalculator().calculateSubTask(getNumberOfRows(), getNumberErrors()));

// now clear the arrays
clearArrays();

}

private void setHeaders() {
setKeepAccountTeamHeader();
}

private void setKeepAccountTeamHeader() {
Config config = this.controller.getConfig();
OwnerChangeOption keepAccountTeamOption = new OwnerChangeOption();
OwnerChangeOption[] ownerChangeOptionArray;
if (config.getBoolean(Config.PROCESS_KEEP_ACCOUNT_TEAM)
&& "Account".equalsIgnoreCase(config.getString(Config.ENTITY))) {
// Support for Keeping Account keepAccountTeam during Account ownership change
// More details at https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_header_ownerchangeoptions.htm
keepAccountTeamOption.setExecute(true);
keepAccountTeamOption.setType(OwnerChangeOptionType.KeepAccountTeam); // Transfer Open opportunities owned by the account's owner
ownerChangeOptionArray = new OwnerChangeOption[] {keepAccountTeamOption};
} else {
// clear ownerChangeOptions from the existing connection otherwise.
ownerChangeOptionArray = new OwnerChangeOption[] {};
}
this.controller.getPartnerClient().getClient().setOwnerChangeOptions(ownerChangeOptionArray);
}

private void writeOutputToWriter(Object[] results)
Expand Down

0 comments on commit 39e2666

Please sign in to comment.