Created
February 17, 2012 19:36
-
-
Save sbob909/1855055 to your computer and use it in GitHub Desktop.
Apex Plug-In for Force.com Cloud Flow Designer Workbook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global class MortgageCalculator implements Process.Plugin | |
{ | |
global Process.PluginResult invoke(Process.PluginRequest request) | |
{ | |
Double amount = (Double)request.inputParameters.get('Amount'); | |
Double term = (Double)request.inputParameters.get('Term'); | |
// Magic here | |
Double cMonthlyPayment; | |
cMonthlyPayment=2750; | |
Map<String, Object> result = new Map<String, Object>(); | |
result.put('MonthlyPayment', cMonthlyPayment); | |
return new Process.PluginResult(result); | |
} | |
global Process.PluginDescribeResult describe() | |
{ | |
Process.PluginDescribeResult result = new Process.PluginDescribeResult(); | |
result.description='This plug-in generates a monthly payment quote given the term and amount.'; | |
result.tag='Mortgage Quote'; | |
result.inputParameters = new List<Process.PluginDescribeResult.InputParameter> { | |
new Process.PluginDescribeResult.InputParameter('Amount', | |
Process.PluginDescribeResult.ParameterType.DOUBLE, true), | |
new Process.PluginDescribeResult.InputParameter('Term', | |
Process.PluginDescribeResult.ParameterType.DOUBLE, true) | |
}; | |
result.outputParameters = new List<Process.PluginDescribeResult.OutputParameter> { | |
new Process.PluginDescribeResult.OutputParameter('MonthlyPayment', | |
Process.PluginDescribeResult.ParameterType.DOUBLE) | |
}; | |
return result; | |
} | |
public static testmethod void testAll() | |
{ | |
MortgageCalculator plugin = new MortgageCalculator(); | |
Map<String,Object> inputParams = new Map<String,Object>(); | |
Double amount = 100000; | |
Double term = 25; | |
inputParams.put('Amount', amount); | |
inputParams.put('Term', term); | |
Process.PluginRequest request = new Process.PluginRequest(inputParams); | |
Process.PluginResult aresult = Plugin.invoke(request); | |
Double monthlyAmount = (Double) aresult.outputParameters.get('MonthlyPayment'); | |
System.assertEquals(monthlyAmount,2750); | |
Process.PluginDescribeResult describe = plugin.describe(); | |
System.assertEquals(describe.InputParameters.size(), 2); | |
System.assertEquals(describe.InputParameters[0].name, 'Amount'); | |
System.assertEquals(describe.InputParameters[1].name, 'Term'); | |
System.assertEquals(describe.OutputParameters.size(), 1); | |
System.assertEquals(describe.OutputParameters[0].name, 'MonthlyPayment'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you add a third input parameter called 'interest' then the following will work to change the amount in the appropriate way (monthly payments increase as interest rate increases and term decreases but total payment decreases as term decreases) albeit not fully mathematically correctly.
Double monthlyPayment;
monthlyPayment=amount_(1+interest/100_term/12)/term;
You will need to make a few other changes as needed to account for the new input parameter and to change the output to the new calculated variable.