function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mick MuMick Mu 

URL Encode

Hi all,

 

I have a custom button on Opportunity which calls a VF Page which passes a number of parameters to a apex class. in the class i create a url set various text fiels and redirect the user to another object screen and the fields are pre populated. This works great for text and currency. 

 

The problem i have is Dates it seems that in the url dates are coming out as 2010-10-25. To put text into the url im using:

 

String AccName  = EncodingUtil.urlEncode(opportunity.Account.Name, 'UTF-8');

 

Does anyone know if there's anything similar for Dates?

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Hengky IlawanHengky Ilawan

Try 

 

opportunity.CloseDate.format()

 

Regards,

Hengky

All Answers

Hengky IlawanHengky Ilawan

Hi,

 

2010-10-25 is a valid URL actually.

 

Anyway, if you construct the URL using the getParameters method from PageReference class, the URL encoding will be handled automatically.

 

public PageReference redirect() {
    PageReference p = Page.MyPage;
    p.getParameters().put('param1', String.valueOf(123456789.0));
    p.getParameters().put('param2', 'SomeText');
    p.getParameters().put('param3', Date.today().format());
    p.setRedirect(true);
    return p;
}

 

Regards,

Hengky

Mick MuMick Mu

Hi thanks for your reply, its not that the url is wrong its when i try and assign it to a date field on the object, this is how im currently doing it...

 

 PageReference pageRef = new PageReference('/a0U/e?CF00NM0000000fO6D=' + oppName + '&CF00NM0000000fO6D_lkid=' + opportunity.Id +

            '&CF00NM0000000fO6P='+ AccName + '&CF00NM0000000fO6P_lkid=' + opportunity.AccountId +

            '&CF00NM0000000fO6h='+ OppOwner + '&CF00NM0000000fO6h_lkid=' + opportunity.OwnerId +

            '&00NM0000000fO7C='+ opportunity.Total_Margin__c + '&00NM0000000fO7D=' + opportunity.Total_Revenue__c +

            '&00NM0000000fO6m=' + opportunity.PS_Revenue__c + '&00NM0000000fO6l=' + opportunity.PS_Margin__c +

            '&00NM0000000fO6U=' + opportunity.CS_Revenue__c + '&00NM0000000fO6T=' + opportunity.CS_Margin__c +

            '&00NM0000000fO7A=' + opportunity.System_Revenue__c + '&00NM0000000fO79=' opportunity.System_Margin__c + '&00NM0000000fO6i=' + opportunity.CloseDate

            );

 

This works fine for all other fields, but the date is coming through as 2010-10-25 when it needs to be 25/10/2010

 

Am I missing something stupid here?

 

Thanks

Hengky IlawanHengky Ilawan

Try 

 

opportunity.CloseDate.format()

 

Regards,

Hengky

This was selected as the best answer
Mick MuMick Mu

AH! thats got it! cheers for your help!