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;
}
}