0

I have to pass a percentage value with 2 decimal places through URL hacking in lightning, for French locale the decimal point is replaced with comma, now when I send the value containing comma, salesforce is not able to parse the URL and it is considering the later part of decimal as a field that is passed in URL.

if(UserInfo.getUiThemeDisplayed() == 'Theme4d'){
        url = '/lightning/o/Contract/new?defaultFieldValues=AccountId=' + accId;
        url = url + ',' + 'ZTS_EU_Related_Contract_Template__c' + '=' + contractTemplateDetail.Id;
        if(contractTemplateDetail.ZTS_EU_Discount_Type__c == 'Fixed Discount'){
            url = url + ',' + 'ZTS_EU_Discount__c' + '=' + discountValueFinal;
        }
        
        if(contractTemplateDetail.ZTS_EU_CTBusiness_Unit__c != null){
            url = url + ',' + 'ZTS_EU_BusinessUnit__c' + '=' + contractTemplateDetail.ZTS_EU_CTBusiness_Unit__c;
        }
        
        url = url  + ',' + 'ZTS_EU_Type__c' + '=' + contractTemplateDetail.ZTS_EU_Type__c;
        url = url + ',' + 'ZTS_EU_Discount_Type__c' + '=' + contractTemplateDetail.ZTS_EU_Discount_Type__c;
        url = url + ',' + 'ZTS_EU_Fiscal_Year__c' + '=' + contractTemplateDetail.ZTS_EU_Fiscal_Year__c;
        url = url + ',' + 'ZTS_EU_End_Date__c' + '=' + date.parse(endDateString);
        url = url + ',' + 'StartDate' + '=' + date.parse(startDateString);
    }

Now the variable "discountValueFinal" contains the comma for french locale, the URL is created as -

/lightning/o/Contract/new?defaultFieldValues=AccountId=001F000001IgAPH,ZTS_EU_Related_Contract_Template__c=a1V3k000005AKO7EAO,ZTS_EU_Discount__c=1,00,ZTS_EU_BusinessUnit__c=a0oF000000DYx9UIAT,ZTS_EU_Type__c=Annexe,ZTS_EU_Discount_Type__c=Fixed Discount,ZTS_EU_Fiscal_Year__c=2020,ZTS_EU_End_Date__c=2020-10-31 00:00:00,StartDate=2020-10-01 00:00:00

Here you can see ",00" is present inside it which is creating problem.

No access to field 00. Either the field was removed from the entity or access to this field was removed

Please help to get rid of this.

2 Answers 2

1

I would suggest using the PageReference class to encode URL parameters on your behalf safely rather than attempting to handle it manually.

Here is the equivalent of your code using this pattern.

if (UserInfo.getUiThemeDisplayed() == 'Theme4d') {
     
    PageReference pr = new PageReference('/lightning/o/Contract/new');

    Map<String, String> params = pr.getParameters();
    params.put('AccountId', accId);
    params.put('ZTS_EU_Related_Contract_Template__c', contractTemplateDetail.Id);
    params.put('ZTS_EU_Type__c', contractTemplateDetail.ZTS_EU_Type__c);
    params.put('ZTS_EU_Discount_Type__c', contractTemplateDetail.ZTS_EU_Discount_Type__c);
    params.put('ZTS_EU_Fiscal_Year__c', contractTemplateDetail.ZTS_EU_Fiscal_Year__c);
    params.put('ZTS_EU_End_Date__c', date.parse(endDateString));
    params.put('StartDate', date.parse(startDateString));

    if (contractTemplateDetail.ZTS_EU_Discount_Type__c == 'Fixed Discount') {
        params.put('ZTS_EU_Discount__c', discountValueFinal);
    }   
    
    if (contractTemplateDetail.ZTS_EU_CTBusiness_Unit__c != null) {
        params.put('ZTS_EU_BusinessUnit__c', contractTemplateDetail.ZTS_EU_CTBusiness_Unit__c);
    }

    url = pr.getUrl(); // let the pagereference class urlencode the parameters for you

    system.debug(url);
0

You can include commas in the defaultfieldvalues in a lightning URL by replacing them with %2c.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .