0

I have a custom button on oppty which when clicked is redirected to a VF page. The page clones existing fields and presents an edit window with prefilled fields to the user. The button works fine for all the records except 1 record.

For a specific opportunity the URL is being redirected to the new button URL( The new button is also overriden to a VF page). I can see that the button is redirecting me to the new button URL

HOW CAN RECORD DATA AFFECT URL REDIRECT (or) is this a SFDC bug?

VF Page:

    <apex:page standardController="opportunity" extensions="clone_button_controller" action="{!clone_oppty}">
    </apex:page>

Controller:

public class clone_button_controller {
  Opportunity oppty;
  string oppUrl = '';
  Expected_Close_Quarter__c ExpectedCloseQuarter = new Expected_Close_Quarter__c(); 
  Date currDate = Date.today();

    public clone_button_controller(ApexPages.StandardController controller) {
       oppty = (Opportunity)controller.getRecord();
    }
    public pagereference clone_oppty(){
    oppty = [select ... from opportunity where ID =: oppty.Id];
    //Period period;          
    for(Expected_Close_Quarter__c closeQtr : 
            [SELECT Expected_Close_Date__c, Name 
                 FROM Expected_Close_Quarter__c 
                 WHERE Quarter_Start_Date__c <= :currDate.addMonths(integer.valueof(oppty.term__c))  
                 AND  Expected_Close_Date__c > :currDate.addMonths(integer.valueof(oppty.term__c))]){

          ExpectedCloseQuarter = closeQtr;              
    }                
    oppUrl += '/006/e?CF00Nd00000056Fnw='+oppty.parent_account__r.name+'&CF00Nd00000056Fnw='+oppty.parent_account__c;
    oppUrl += '&opp4='+oppty.account.name+'&opp4_lkid='+oppty.accountid;
    oppUrl += '&opp3=Name create when saved';
    oppUrl += '&nooverride=1';
    oppUrl += '&RecordType='+oppty.RecordtypeId;
    Pagereference pg = new Pagereference(oppUrl);
    pg.setredirect(true);
    return pg;
    }

}
0

It could be because you're not encoding the values of the account names that you're concatenating while building the url and that is messing up the whole URL. You could use the EncodingUtil.urlEncode method to encode the url parameters something like this:

oppUrl += '/006/e?CF00Nd00000056Fnw='+EncodingUtil.urlEncode(oppty.parent_account__r.name, 'UTF-8')+'&CF00Nd00000056Fnw='+oppty.parent_account__c;
    oppUrl += '&opp4='+EncodingUtil.urlEncode(oppty.account.name,'UTF-8')+'&opp4_lkid='+oppty.accountid;
    oppUrl += '&opp3='+EncodingUtil.urlEncode('Name create when saved','UTF-8');
    oppUrl += '&nooverride=1';
    oppUrl +='&RecordType='+oppty.RecordtypeId;

or even better your could use the pageReference's getParameter() method to put in all the paramenters and that its care of the encoding.

pg .getParameters().put('opp4_lkid',oppty.accountId);
1
  • Spot on, there was an & that was messsing up the url as stated in the answer
    – Swathi
    Jun 12 '15 at 8:29

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.