+ Start a Discussion
ShikibuShikibu 

retURL funny behavior

I have the following code: 

 

public String retURL() {
    return Page.DupeChecker.getUrl();
}

public PageReference createLead() {
    String leadPrefix = Schema.getGlobalDescribe().get('Lead').getDescribe().getKeyPrefix();
    
    PageReference p = new PageReference('/' + leadPrefix + '/e');
    p.setRedirect(True);
    p.getParameters().put('nooverride', '1');
    
    p.getParameters().put('retURL', EncodingUtil.urlEncode(retURL(), 'UTF-8'));
    
    return p;
}

 It produces an url as follows:

 

https://cs7.salesforce.com/00Q/e?nooverride=1&retURL=%252Fapex%252Fdupechecker

 This url opens a lead page for editing, which is what I wanted.

 

However, if the user hits cancel, the browser returns to an url like this, which is invalid. Why is there a '00Q/' at the beginning of hte url?

 

https://cs7.salesforce.com/00Q/%2Fapex%2FDupeChecker

 

 

Best Answer chosen by Admin (Salesforce Developers) 
b-Forceb-Force

Hello,

 

please try this

I dont think we need to perform URL encoding here

 

public String retURL() {
    return Page.DupeChecker.getUrl();
}

public PageReference createLead() {
    String leadPrefix = Schema.getGlobalDescribe().get('Lead').getDescribe().getKeyPrefix();
    
    PageReference p = new PageReference('/' + leadPrefix + '/e');
    p.setRedirect(True);
    p.getParameters().put('nooverride', '1');
    
    p.getParameters().put('retURL', retURL());
    
    return p;
}



This works for me

 

Thanks,

Bala