+ Start a Discussion
RepsGRepsG 

CommandLink not working, refreshing the page.

 

I have a problem with my command link in the code below. Everytime I click on it just refreshes the page and does not go to the next page.

 

<apex:pageBlocktitle="Possible Personal Customer(s)"rendered="{!DisplayPosPersonalRecords == true && checkCustomer = 'No'}">

<apex:pageBlockTablevalue="{!ListPossiblePersonalRecords}"var="per"columnsWidth="5px, 5px"border="1">

 

<apex:columnheaderValue="Options">

  <apex:commandLinkvalue="Selectd"style="font-weight:bold;"action="{!SubmitNewContactMoveToOpp}">

    <apex:paramname="paccId"value="{!per.Id}"assignTo="{!SelectedId}"/>

    <apex:paramname="paccType"value="Ppersonal"assignTo="{!SelectedType}"/>

   </apex:commandLink>

</apex:column>

<apex:columnheaderValue="Customer Name"value="{!per.aName}"width="14.285%"/>

<apex:columnheaderValue="Equation No"value="{!per.EQ}"width="10%"/>

<apex:columnheaderValue="Email"value="{!per.Email}"width="14.285%"/>

<apex:columnheaderValue="Date of Bith"value="{!day(per.DoB)}/{!month(per.DoB)}/{!year(per.DoB)}"width="14.285%"/>

<apex:columnheaderValue="Address"value="{!per.Address}"width="14.285%"/>

<apex:columnheaderValue="Account Officer"value="{!per.AccountOfficer}"width="19.65%"/>

<apex:columnheaderValue="Created Date"value="{!per.CreDate}"width="14.285%"/>

</apex:pageBlockTable>

</apex:pageBlock>

 

 

I have even simplified my apex code so that it only returns the page and still no joy.

 

 

 

public PageReference SubmitNewContactMoveToOpp(){

 

return page.NewLoanOpp_Page_02;

 

}

 

 

Help...pulling my hair out!!

Best Answer chosen by Admin (Salesforce Developers) 
RepsGRepsG

I found a solution to this and it was to do with my code in my Controller.

 

Here is my code: http://pastebin.com/hw1FYyhH post fix

 

In a nutshell my apex code in my controller was a bit messy even though it worked.

I believe for the Commandlink to work with a PageblockTable, the apex code should look like the example below:

 

----------------------------------------------------------------------------------------------

public List<accountset> getListPossiblePersonalRecords() {

 

accountlist = newList<accountset>();

 

List< Contact> Con = [selectId, Name, Email  fromContact  where email =: cemail

                                                                                                                                   and LastName =: cLastName

                                                                                                                                   and FirstName =: cFirstName];

 

for(Contactc:Con){

   accountset thelist = newaccountset();

    thelist.Id = c.Id;

    thelist.aName = c.Name;

    thelist.Email = c.Email;

    accountlist.add(thelist);

   }

returnaccountlist;

}

 

 

----------------------------------------------------------------------------------------------

 

 

I hope this helps. If there is a better way of explaining this or if anyone has any questions please feel free to reply.

 

Many thanks

All Answers

aballardaballard

Perhaps you are getting some kind of validation error on the page which would have this effect.   Try adding an <apex:messages> or apex:<pagemessages> to the top of your page to display any error messages....

RepsGRepsG

I have <apex:Messages/> but dont have any error/validation messages. I have looked in the debug log and tried to find the action method and still nothing!!

sfdcbynitesfdcbynite
I am having the exact same problem. I was about to post something. I have an apex:messages tag but no messages and I am just displaying information. Hope someone gets an answer to this.
RepsGRepsG

Can you post your code? I have theory but cant test it as am away from eclipse, however if i am able to look at your code, I hopefully can find a pattern.

sfdcbynitesfdcbynite
Unfortunately, no. For some reason the rich text editor is not coming up so when I put in HTML, it removes it. However I did figure out my problem. In my apex;page I have and action which was returning a PageReference to itself. So everytime the button executed, it ran the action first and returned the same page. I changed the method to a void and now it works. Hope this helps. Dovid
RepsGRepsG

I found a solution to this and it was to do with my code in my Controller.

 

Here is my code: http://pastebin.com/hw1FYyhH post fix

 

In a nutshell my apex code in my controller was a bit messy even though it worked.

I believe for the Commandlink to work with a PageblockTable, the apex code should look like the example below:

 

----------------------------------------------------------------------------------------------

public List<accountset> getListPossiblePersonalRecords() {

 

accountlist = newList<accountset>();

 

List< Contact> Con = [selectId, Name, Email  fromContact  where email =: cemail

                                                                                                                                   and LastName =: cLastName

                                                                                                                                   and FirstName =: cFirstName];

 

for(Contactc:Con){

   accountset thelist = newaccountset();

    thelist.Id = c.Id;

    thelist.aName = c.Name;

    thelist.Email = c.Email;

    accountlist.add(thelist);

   }

returnaccountlist;

}

 

 

----------------------------------------------------------------------------------------------

 

 

I hope this helps. If there is a better way of explaining this or if anyone has any questions please feel free to reply.

 

Many thanks

This was selected as the best answer