0

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

}
3
  • I suggest you add System.debug(chkdup); straight after the query in the Next method to see what the actual result is including the field values (as it is probably not what your are expecting). That is only thing I can see in that method that would cause your problem.
    – Keith C
    Apr 30, 2014 at 22:04
  • I added a system.debug('hello'); to my class and I received the message in the debug log, so that tells me the soql query is working May 1, 2014 at 21:10
  • OK. Looks like you are making progress on the URL so good luck.
    – Keith C
    May 2, 2014 at 8:24

1 Answer 1

4

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

9
  • I did add the newAccount1.setRedirect(true); where you had told me and it still didn't work May 1, 2014 at 20:27
  • @NewbieDeveloper27 - please update your code in the original post
    – cropredy
    May 1, 2014 at 20:57
  • updated my answer
    – cropredy
    May 1, 2014 at 21:41
  • I tried your updated answer by switching that out, but it didn't work. I think this error in my chrome developer console might be the problem, but I don't know how to fix it: Refused to display 'cs9.salesforce.com/001/…' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'. May 1, 2014 at 21:45
  • When I inspected that URL - it looks like https://cs9.salesforce.com/001/e?acc18city=Minneapolis&acc18state=MN&acc18street=null&acc18zip=null&acc2=Shasta+Hospital&nooverride=true%27 Why is there a trailing %27 (single quote) ?
    – cropredy
    May 1, 2014 at 23:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .