You need to sign in to do that
Don't have an account?
Andrey Bolkonsky
Trouble Converting Method that Returns String into Invocable Method
This is my second post trying to figure this out. I have a method of the return type string with one integer Parameter. It is my first Apex class so I want to make it invocable so that if something goes wrong with it I can just deactivate the flow.
However I can't wrap my head around the invocable method annotation, specifically turning everything in my method into some kind of list. Can anyone explain how I might do this?
However I can't wrap my head around the invocable method annotation, specifically turning everything in my method into some kind of list. Can anyone explain how I might do this?
//@InvocableMethod(label='Write Number' description='Writes the Number' category='Opportunity') public static String writeNumber(Integer Amt) { Integer Amount=Amt; Integer Len; String spelledAmount; Map<Integer, String> numberName=new Map<Integer, String> { }; String amountString=String.valueOf(Amount); Len=amountString.Length(); List<Integer> arrayNumber=new List<Integer>(); String[] chars=amountString.split(''); for(String c:chars) { arrayNumber.add(Integer.valueOf(c)); } Switch on Len { } //Body of method return spelledAmount; }
Method processing logic has to be changed to bulk.
Try something like this :
@InvocableMethod(label='Write Number' description='Writes the Number' category='Opportunity')
public static List<String> writeNumber(List<Integer> Amts) {
List<String> spelledAmounList = new List<String>();
for(integer Amt : amts){ //Process input in loop
Integer Amount=Amt;
Integer Len;
String spelledAmount;
Map<Integer, String> numberName=new Map<Integer, String> { };
String amountString=String.valueOf(Amount);
Len=amountString.Length();
List<Integer> arrayNumber=new List<Integer>();
String[] chars=amountString.split('');
for(String c:chars) {
arrayNumber.add(Integer.valueOf(c));
spelledAmounList.add(spelledAmount); //Add individual items to return List
}
Switch on Len { } //Body of method
}
return spelledAmounList ;
}
Not sure what logic goes into loop, it can be optimized for bulk processing.
Thanks
All Answers
Method processing logic has to be changed to bulk.
Try something like this :
@InvocableMethod(label='Write Number' description='Writes the Number' category='Opportunity')
public static List<String> writeNumber(List<Integer> Amts) {
List<String> spelledAmounList = new List<String>();
for(integer Amt : amts){ //Process input in loop
Integer Amount=Amt;
Integer Len;
String spelledAmount;
Map<Integer, String> numberName=new Map<Integer, String> { };
String amountString=String.valueOf(Amount);
Len=amountString.Length();
List<Integer> arrayNumber=new List<Integer>();
String[] chars=amountString.split('');
for(String c:chars) {
arrayNumber.add(Integer.valueOf(c));
spelledAmounList.add(spelledAmount); //Add individual items to return List
}
Switch on Len { } //Body of method
}
return spelledAmounList ;
}
Not sure what logic goes into loop, it can be optimized for bulk processing.
Thanks
This worked! Thanks so much for your help!