You need to sign in to do that
Don't have an account?
Sachin Prasad 16
unable to save trigger
Hi All,
I have written a class as below:
public class NumbersToWordsConversionClass {
public string wordText { get; set; }
public Integer numberVal { get; set; }
// Action method to be called by button or link
public void convert() { wordText = numberToEnglish(numberVal); } static String[] firstTwenty = new String[] { 'NIL','One','Two','Three','Four','Five','Six','Seven','Eight','Nine', 'Ten','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Ninteen' }; static String[] tens = new String[] { '','','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety' }; static String[] powers = new String[] { 'Crore','Lakh','Thousand','Hundred' }; static Integer[] thresholds = new Integer[] { 10000000, 100000, 1000, 100 };
static String[] convert(Integer value) {
String[] result = new String[0];
Boolean less20 = value < 20, less100 = value < 100;
if(less20) { result.add(firstTwenty[value]); }
else if(less100) {
Integer tenValue = value / 10, oneValue = Math.mod(value, 10);
result.add(tens[tenValue]);
if(oneValue > 0) {
result.add(firstTwenty[oneValue]); } }
if(less100) { return result; } if(value > 0) {
for(Integer index = 0; index < thresholds.size(); index++) {
if(thresholds[index] <= value) {
result.addAll(convert(value / thresholds[index]));
result.add(powers[index]);
value = Math.mod(value, thresholds[index]); } }
if(value > 0) { result.addAll(convert(value)); } }
return result; } public static String numberToEnglish(Integer value) { return value != null && value >= 0? String.join(convert(value),' '): ''; } }
however when i am trying to write the trigger as below it is failing please assist;
getting error as Compile Error: expecting a right parentheses, found 'Value' at line 5 column 101
trigger ConvertCurrencyToWords on Opportunity (before insert, before update)
{ for(Opportunity record: Trigger.new)
{ if(record.Amount != null)
{
record.Amount_in_Words__c = NumbersToWordsConversionClass.numberToEnglish(record.Amount.integer Value());
}
}
}
I have written a class as below:
public class NumbersToWordsConversionClass {
public string wordText { get; set; }
public Integer numberVal { get; set; }
// Action method to be called by button or link
public void convert() { wordText = numberToEnglish(numberVal); } static String[] firstTwenty = new String[] { 'NIL','One','Two','Three','Four','Five','Six','Seven','Eight','Nine', 'Ten','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Ninteen' }; static String[] tens = new String[] { '','','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety' }; static String[] powers = new String[] { 'Crore','Lakh','Thousand','Hundred' }; static Integer[] thresholds = new Integer[] { 10000000, 100000, 1000, 100 };
static String[] convert(Integer value) {
String[] result = new String[0];
Boolean less20 = value < 20, less100 = value < 100;
if(less20) { result.add(firstTwenty[value]); }
else if(less100) {
Integer tenValue = value / 10, oneValue = Math.mod(value, 10);
result.add(tens[tenValue]);
if(oneValue > 0) {
result.add(firstTwenty[oneValue]); } }
if(less100) { return result; } if(value > 0) {
for(Integer index = 0; index < thresholds.size(); index++) {
if(thresholds[index] <= value) {
result.addAll(convert(value / thresholds[index]));
result.add(powers[index]);
value = Math.mod(value, thresholds[index]); } }
if(value > 0) { result.addAll(convert(value)); } }
return result; } public static String numberToEnglish(Integer value) { return value != null && value >= 0? String.join(convert(value),' '): ''; } }
however when i am trying to write the trigger as below it is failing please assist;
getting error as Compile Error: expecting a right parentheses, found 'Value' at line 5 column 101
trigger ConvertCurrencyToWords on Opportunity (before insert, before update)
{ for(Opportunity record: Trigger.new)
{ if(record.Amount != null)
{
record.Amount_in_Words__c = NumbersToWordsConversionClass.numberToEnglish(record.Amount.integer Value());
}
}
}
First you need to check your Amount_in_Words__c field on Opportunity is Text Type so then this can store String information and when you'll call numberToEnglish(Integer value) Method then you need to pass only Integer type value. So you need to convert decimal value (record.Amount) to Integer value before passing as a parameter.
Now I give you a solution as below : Regards
Akshay
All Answers
NumbersToWordsConversionClass.numberToEnglish((Integer)record.Amount);
I tried it and it seems to work fine.
First you need to check your Amount_in_Words__c field on Opportunity is Text Type so then this can store String information and when you'll call numberToEnglish(Integer value) Method then you need to pass only Integer type value. So you need to convert decimal value (record.Amount) to Integer value before passing as a parameter.
Now I give you a solution as below : Regards
Akshay
Thanks for selecting my answer as a best answer. It's my pleasure to help you!
Regards,
Akshay