1

Has anyone else come up with a solution by Trigger for this? I have been trying to figure this out for a few weeks now but to no avail.

for e.g Amount -  200$

        Amount in words - Two hundred Dollar only.

I found apex class from this website http://salesforcewithkiran.blogspot.in/2013/05/number-to-words-in-apex.html

that works fine for apex class but not for apex trigger.

and I found another site check this here with trigger program to convert but they calling a NumbersToWords apex class but there is no code for that class.

Need a Trigger to convert numbers/currency to words

Anyone have idea about this?

Thanks!

1

The class you reference in your question works on a single number that must be a positive Long value. So in your trigger you will have to loop over what can be the many (bulk) values passed to the trigger via the Trigger.new list of the trigger context, convert the value to a Long and then assign the resulting String. Because it is a before trigger, the result will automatically be saved to the database.

You don't name the object and fields, but if it were a couple of custom fields on Contact, the code would look something like this:

trigger MyTrigger on Contact (before insert, before update) {
    for (Contact c : Trigger.new) {
        if (c.Number__c != null && c.Number__c >= 0) {
            Long n = c.Number__c.longValue();
            c.Text__c = NumberToWord.english_number(n);
        } else {
            c.Text__c = null;
        }
    }
}

(You will also have to copy and add the NumberToWord class to your org before you create the trigger.)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.