6

Controller:

 public PageReference redirectScheduleApex(){
 PageReference yourPage = new PageReference('/ui/setup/apex/batch/ScheduleBatchApexPage?ac=scheduledDeltaBatchable&retURL=/apex/mailtent');
 yourpage.setRedirect(true);
 return yourPage ;

In test class assert:

PageReference q =gbd.redirectScheduleApex();
system.assertEquals(q.getURL(),'/ui/setup/apex/batch/ScheduleBatchApexPage?ac=scheduledDeltaBatchable&retURL=/apex/mailtent');

when I use the same page ref as used in controller I am getting this 'failed assertion'error.Any idea about why %2Fapex%2F(as html)is needed while asserting?and how can I modify the assert to get the exact value?

Assertion Fails:

System.AssertException: Assertion Failed:

Expected:

/ui/setup/apex/batch/ScheduleBatchApexPage?ac=scheduledDeltaBatchable&retURL=%2Fapex%2Fmailtent, 

Actual:

/ui/setup/apex/batch/ScheduleBatchApexPage?ac=scheduledDeltaBatchable&retURL=/apex/mailtent
3
  • If you try to escape them like this \/ in assert method ?
    – SF_user
    Dec 30 '15 at 14:55
  • it is because it is urlencoded url when you do q.getURL();
    – Himanshu
    Dec 30 '15 at 14:58
  • On another note, unrelated to your question. Your expected and actual are in the wrong places. Just as an FYI :) Dec 30 '15 at 15:17
7

In Salesforce URL parameters are automatically encoded so if you want to assert the url replace your assert statement with following statement where EncodingUtil.urlEncode method is used to encode the parameters

system.assertEquals(q.getURL(),
'/ui/setup/apex/batch/ScheduleBatchApexPage?ac=scheduledDeltaBatchable&retURL=' +
 EncodingUtil.urlEncode('/apex/mailtent','UTF-8'));
1
  • Yea,Its working fine now.. Dec 30 '15 at 15:41

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.