global with sharing class CalculatePrice {
@invocableMethod(label='Custom Calculate Price')
global static List<SVMXA360.CalculatePriceApexAction.PriceCalRequest> calculatePrice(List<SVMXA360.CalculatePriceApexAction.PriceCalRequest> lstInputParams) {
system.debug(LoggingLevel.INFO, 'calculatePrice() - enter.');
List<SVMXA360.CalculatePriceApexAction.PriceCalRequest> lstResponse = new List<SVMXA360.CalculatePriceApexAction.PriceCalRequest>();
try {
if (lstInputParams == null || lstInputParams.isEmpty()) {
//throw new SvmxSystem.SvmxNestedException(ErrorMessage.MISSING_REQUIRED_PARAMETER);
}
List<SObject> lstAllRecords = new List<SObject>();
for (SVMXA360.CalculatePriceApexAction.PriceCalRequest eachReq : SVMXA360.CalculatePriceApexAction.calculatePrice(lstInputParams)) {
if (eachReq.lstProductConsumedRecords != null && !eachReq.lstProductConsumedRecords.isEmpty()) {
lstAllRecords.addAll(eachReq.lstProductConsumedRecords);
for (SObject eachRecord : eachReq.lstProductConsumedRecords) {
SVMXA360.CalculatePriceApexAction.PriceCalRequest response = new SVMXA360.CalculatePriceApexAction.PriceCalRequest();
response.lstProductConsumedRecords = new List<SObject>();
response.lstProductConsumedRecords.add(eachRecord);
lstResponse.add(response);
}
}
if (eachReq.lstWOLIRecords != null && !eachReq.lstWOLIRecords.isEmpty()) {
lstAllRecords.addAll(eachReq.lstWOLIRecords);
for (SObject eachRecord : eachReq.lstWOLIRecords) {
SVMXA360.CalculatePriceApexAction.PriceCalRequest response = new SVMXA360.CalculatePriceApexAction.PriceCalRequest();
response.lstWOLIRecords = new List<SObject>();
response.lstWOLIRecords.add(eachRecord);
lstResponse.add(response);
}
}
if (eachReq.lstExpenseRecords != null && !eachReq.lstExpenseRecords.isEmpty()) {
lstAllRecords.addAll(eachReq.lstExpenseRecords);
for (SObject eachRecord : eachReq.lstExpenseRecords) {
SVMXA360.CalculatePriceApexAction.PriceCalRequest response = new SVMXA360.CalculatePriceApexAction.PriceCalRequest();
response.lstExpenseRecords = new List<SObject>();
response.lstExpenseRecords.add(eachRecord);
lstResponse.add(response);
}
}
}
if (lstInputParams[0].isUpdateRecords) {
Database.update(lstAllRecords);
}
} catch (DmlException ex) {
system.debug(LoggingLevel.INFO, 'calculatePrice(). Exception in updating source records: ' + ex);
throw ex;
}
catch (Exception ex) {
system.debug(LoggingLevel.INFO, 'calculatePrice(). Exception in price calculation: ' + ex);
throw ex;
}
system.debug(LoggingLevel.INFO, 'calculatePrice() - exit. lstResponse = ' + lstResponse);
return lstResponse;
}
}
|
|
Do not use the packaged apex action for price calculation. Create the apex class as per the above code.
|






