Find your content:

Search form

You are here

CommandButton action method doesn't display expected page

 
Share

I have a custom controller and a visualforce page that works perfectly besides when there isn't a duplicate and the user needs to be taken to the account edit page (which is written in the controller). For some reason, when there isn't a duplicate the "click to Proceed" button does not take you to that page. Help would be much appreciated! Thank you :)

Account Duplicate VF Page

 <apex:page standardController="Account" extensions="AccountDupeCatch6">
    <apex:pageBlock title="Account Information">
   <apex:form >
      <table cellpadding="2" cellspacing="2">
       <tr>
       <td style="font-weight:bold;">Account Name<br/>
       <apex:inputField value="{!NewAccount.Name}"/>
       </td>
       </tr>
       <td style="font-weight:bold;">Shipping Street<br/>
       <apex:inputField value="{!NewAccount.ShippingStreet}"/>
       </td>
       <td style="font-weight:bold;">City<br/>
       <apex:inputField value="{!NewAccount.ShippingCity}" required="true"/>
       </td>
       <td style="font-weight:bold;">State<br/>
       <apex:inputField value="{!NewAccount.ShippingState}" required="true"/>
       </td>
       <td style="font-weight:bold;">Zip<br/>
       <apex:inputField value="{!NewAccount.ShippingPostalCode}"/>
       </td>
    </table>

         <apex:commandButton action="{!Next}" value="Click here to proceed" status="status" reRender="ProceedPanel" />  


     <!-- Display error message -->
     <apex:outputPanel id="ProceedPanel">
         <apex:pagemessage strength="2" title="Duplicate!!" severity="error" detail="This Account Name Already Exists !!!" rendered="{!errormsg}"/><!-- End of error message -->
           <apex:pageblocktable rendered="{!NOT(ISNULL(existingaccountlist))}" value="{!existingaccountlist}" var="acct">
                          <apex:column headervalue="Select">
                                   <apex:commandlink action="{!SelectName}">
                                       <input type="radio" name="AccountSel" onclick="changeValue(this,'{!$Component.RadioButtonValue}')"/>
                                       <apex:param name="accID" value="{!acct.id}" assignTo="{!accId}"/>
                                   </apex:commandlink>                                         
                          </apex:column>
                          <apex:column headervalue="Account Name"> <apex:outputtext value="{!acct.Name}"/>  </apex:column>
                          <apex:column headervalue="Type"> <apex:outputtext value="{!acct.recordtype.name}"/>  </apex:column>
                          <apex:column headervalue="Flag"> <apex:outputfield value="{!acct.Status_Flag__c}" />  </apex:column>
                          <apex:column headervalue="Customer ID"> <apex:outputtext value="{!acct.CustomerMasterID__c}"/>  </apex:column>
                          <apex:column headervalue="Shipping Street"> <apex:outputtext value="{!acct.shippingstreet}"/>  </apex:column>
                          <apex:column headervalue="City"> <apex:outputtext value="{!acct.shippingcity}"/>  </apex:column>
                          <apex:column headervalue="State"> <apex:outputtext value="{!acct.shippingstate}"/>  </apex:column>
                          <apex:column headervalue="Zip"> <apex:outputtext value="{!acct.shippingpostalcode}"/>  </apex:column>
                          <apex:column headervalue="Parent Account"> <apex:outputtext value="{!acct.parent.name}"/>  </apex:column>         
           </apex:pageblocktable>

            <apex:commandButton action="{!Proceed}" value="Create Prospect Anyway" id="proceedButton" rendered="{!IF(chkdup.size > 0, true, false)}"/>
            <apex:actionSupport event="onkeydown" disabled="false"/>
     </apex:outputPanel>
 </apex:form>
</apex:pageBlock>

</apex:page>

Apex Class:

public class AccountDupeCatch6 {

public boolean errormsg=false;
public String AccountId=System.currentPageReference().getParameters().get('id');
public String aname;
public String ashippingstreet;
public String acity;
public String astate;
public String azip;
public Id accId {get; set;}
public List<Account> chkdup {get; set;}
public Account newaccount= new Account();

 public AccountDupeCatch6(ApexPages.StandardController controller)
   {
     chkdup = new list<account>();
   }
 public account getnewaccount()
   {
     return newaccount;
   }
 public account getexistingaccount()
  {
     if (chkdup!= NULL)
  {
     if(chkdup.size()>0)
        return chkdup[0];
   else
         return null;
  }
   else
         return null;
}

 public list<account> getexistingaccountlist()
   {
     if (chkdup!= NULL)
   {
     if(chkdup.size()>0)
        return chkdup;
    else
        return null;
   }
    else
        return null;
}

 public pagereference Next()
   {          
      chkdup=Database.query('Select name,id,recordtype.name,CustomerMasterID__c,status_flag__c,shippingstreet,shippingcity,shippingstate,shippingpostalcode,parent.name from Account where Name like \'%' + newaccount.name + '%\' AND (ShippingStreet like \'%' + newaccount.shippingstreet + '%\' OR ShippingCity like \'%' + newaccount.shippingcity + '%\' OR ShippingState like \'%' + newaccount.shippingstate + '%\' OR  ShippingPostalCode like \'%' + newaccount.shippingpostalcode + '%\') Order By Status_Flag__c');       
if(chkdup.size()==0)

 {
      System.debug('Hello');
      String aname=newaccount.Name;
      String ashippingstreet=newaccount.shippingstreet;
      String acity=newaccount.shippingcity;
      String astate=newaccount.shippingstate;
      String azip=newaccount.shippingpostalcode;
      Pagereference newaccount1 = new Pagereference('/001/e?nooverride=true&acc2='+aname+'&acc18street='+ashippingstreet+'&acc18city='+acity+'&acc18state='+astate+'&acc18zip='+azip);
       newaccount1.setredirect(true);
       return newaccount1;
 }
  else
 {
       errormsg=true;
       return null;
 }

 }

public pagereference SelectName() {
    return new Pagereference('/' + accId);

   //Pagereference chkdup = new Pagereference('/' + chkdup[0].Id);
   //return chkdup;
}


public pagereference Proceed() {
      String aname=newaccount.Name;
      String ashippingstreet=newaccount.shippingstreet;
      String acity=newaccount.shippingcity;
      String astate=newaccount.shippingstate;
      String azip=newaccount.shippingpostalcode;
      Pagereference newaccount2 = new Pagereference('/001/e?nooverride=true&acc2='+aname+'&acc18street='+ashippingstreet+'&acc18city='+acity+'&acc18state='+astate+'&acc18zip='+azip+'');
      return newaccount2; 
          }

public boolean geterrormsg()
{
  return errormsg;
}  

}

Attribution to: NewbieDeveloper27

Possible Suggestion/Solution #1

The code fragment in your next() action method

Pagereference newaccount1 = new Pagereference('/001/e?nooverride=1&acc2='+aname+'&acc18street='+ashippingstreet+'&acc18city='+acity+'&acc18state='+astate+'&acc18zip='+azip+'');
  return newaccount1;

is missing the redirect

Pagereference newaccount1 = new Pagereference('/001/e?nooverride=1&acc2='+aname+'&acc18street='+ashippingstreet+'&acc18city='+acity+'&acc18state='+astate+'&acc18zip='+azip);
  newAccount1.setRedirect(true);
  return newaccount1;

BTW - best practice would be to use variable names like newAcctPg for variables of type PageReference

BTW2 - I changed the nooverride=true to nooverride=1 in your URL; see this post . This will ensure you are going to the standard Account New page which I believe is your intent

BTW3 - Removed your trailing single quote


Attribution to: cropredy
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/34133

My Block Status

My Block Content