+ Start a Discussion
mramosmramos 

Issue passing currency value to URL hack

Hello,

I am at a loss, I have tried everyhting I know to try and get a Custom button in the Contract to pass a currency value in the URL but I keep getting "System.TypeException: Invalid decimal: " error. I first tried passing in the CurrencyIsoCode along with the currency field in the URL, but I still get the error:

"/apex/OppOverrideEdit?contrId={!Contract.Id}&returl={!Contract.Id}&accId={!Contract.AccountId}&paroppid={!Contract.OpportunityId__c}&pps={!Contract.Price_Per_Slide_in_contract__c}&CurrencyIsoCode={!Contract.CurrencyIsoCode}";

The issue is that it is passing the currency and also a comma value, for example: value in field 12.34, shown in the contract page as 12,34 due to user locale settings is passed as  USD 12,34 instead of the decimal value.

Then I tried to add some code in the OppOverrideEdit controller to try and remove both the currency and the comma replacing it with a period as so:
 
String strNewPPS   = ApexPages.currentPage().getParameters().get('pps');
        if(strNewPPS != null){
            strNewPPS = strNewPPS.normalizeSpace();
            strNewPPS = strNewPPS.contains(',') ? strNewPPS.replace(',', '.') : strNewPPS;
            strNewPPs = strNewPPS.right(strNewPPs.length()-3);
            system.debug('### strNewPPS: ' + strNewPPS);
        }
        mOpportunity.fcNew_PPS__c    = strNewPPS != null ? Decimal.valueOf(strNewPPS) : null;

But now I get the same error but this time the value is 12.34, it is still giving an error no matterwhat I put in it. How can I pass this value in the URL without getting this error???
ericmonteericmonte
Did you try encoding the values into URL format?
mramosmramos
No actually I didn't. Should I encode only the field or the entire url string ???
ericmonteericmonte
So when you click the link what is the URL that is being passed?
I did something similar as you,

/apex/Amount?id={!Opportunity.Id}&amount={!Opportunity.Amount}

and the URL that is passed is this:
/apex/Amount?id=006i000000G7Nrn&amount=%24235%2C000.00

Are you getting something similar to this?
ericmonteericmonte
I think I found your issue. so in your link:

try doing this:

"/apex/OppOverrideEdit?contrId={!Contract.Id}&returl={!Contract.Id}&accId={!Contract.AccountId}&paroppid={!Contract.OpportunityId__c}&pps={!TEXT(Contract.Price_Per_Slide_in_contract__c)}&CurrencyIsoCode={!Contract.CurrencyIsoCode}";


Then check to see if you are still getting the ',' or not. Let me know how it turns out.