Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I'm using a Developer Force example to recreate that Visualforce page. It works except for the fact that clicking on the "view" link only works once. How do I make it work for each and every link / case?

Visualforce:

<apex:page controller="MyConsoleController">
    <apex:form >

    <apex:sectionHeader title="Cases Cockpit"/>

    <div id="caseInfo" style="float:left;width:25%">
        <apex:pageBlock title="My Cases">
            <apex:pageBlockTable value="{!myCases}" var="case">
                <apex:column >
                    <apex:commandLink value="View" action="{!viewCase}">
                        <apex:param name="caseId" value="{!case.Id}"/>
                    </apex:commandLink>
                </apex:column>
                <apex:column headerValue="Subject" value="{!case.Subject}"/>
                <apex:column headerValue="Status" value="{!case.Status}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </div>

    <div style="float:right;width:73%">
        <apex:detail id="caseDetail" subject="{!selectedCase.Id}" relatedList="false" title="false"/>
    </div>

    <div style="width:100%">
        <apex:pageBlock title="Solutions">
            <apex:pageBlockTable value="{!solutions}" var="sol">
                <apex:column >
                    <apex:commandLink value="View" action="{!viewSolution}">
                        <apex:param name="caseId" value="{!sol.Id}"/>
                    </apex:commandLink>
                </apex:column>
                <apex:column headerValue="Solution #" value="{!sol.SolutionNumber}"/>
                <apex:column headerValue="Name" value="{!sol.SolutionName}"/>
                <apex:column headerValue="Status" value="{!sol.Status}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </div>

    </apex:form>
</apex:page>

Controller:

public class MyConsoleController {

    public Case selectedCase { get; set; }

    public Solution[] getSolutions() {
        return [SELECT Id, SolutionNumber, SolutionName, Status FROM Solution];
    }

    public Case[] getMyCases() {
        return [SELECT Id, Subject, Status FROM Case WHERE OwnerId = :UserInfo.getUserId()
            AND Status != 'Closed'];
    }

    public PageReference viewCase() {
        String caseId = ApexPages.currentPage().getParameters().get('caseId');
        selectedCase = [SELECT Id FROM Case WHERE Id = :caseId];
        return null;
    }

    public PageReference viewSolution() {
        String solId = ApexPages.currentPage().getParameters().get('solId');
        return new PageReference('/' + solId);
    }
}
share|improve this question
    
What happens when you click it a second time? Also, can you cut down the vf and controller a bit to just what you need to reproduce the issue. –  Greg Grinberg Dec 18 '12 at 19:23
    
I just copied the code directly from the wiki article and it worked without any issue. Can you try this under an admin user? –  Greg Grinberg Dec 18 '12 at 19:29
    
@grigriforce really? hmm, i did the same and it didn't work. I'll try again maybe. Well when i click on one case when the page just loaded, it shows the detail view, but after that none of the other links works, when I click on them it just does nothing at all. –  user988 Dec 18 '12 at 19:34
    
Can you add the debug log from when you click the view link the second time? –  Greg Grinberg Dec 18 '12 at 19:39
    
@grigriforce I checked the debug log and there's nothing there, so it's not erroring out. –  user988 Dec 18 '12 at 20:09

1 Answer 1

up vote 2 down vote accepted

The issue that I see is on lines 27 - 31 (copied below) and causes it so that you cannot view solutions. I was able to reproduce that error; however there's no error for the case links. I can click those without any problems just like @grigriforce.

  <apex:column >
    <apex:commandLink value="View" action="{!viewSolution}"> 
        <apex:param name="caseId" value="{!sol.Id}"/>
    </apex:commandLink>
  </apex:column>

Note that it is assigning solution Id to a parameter of caseId. Then in the controller viewSolution method it has:

 String solId = ApexPages.currentPage().getParameters().get('solId');

So, solId is null and it gives you the not found / no longer exists URL. Change the Visualforce to:

<apex:param name="solId" value="{!sol.Id}"/>

After you make that change the controller method will have a value of the clicked Solution's ID for solId instead of null and the PageReference that is constructed will go to the Solution's detail page.

Update There is another error if the detail page (from the page layout) has the Submit for Approval button on it because it has an html name attribute of submit which conflicts with the form's submit function.

A solution for that is to break the page up in to two forms, leaving the detail page out of the forms.

The Visualforce page would be changed to:

<apex:page controller="MyConsoleController">

    <apex:sectionHeader title="Cases Cockpit"/>

<!-- One form begins here -->
<apex:form >
    <div id="caseInfo" style="float:left;width:25%">
        <apex:pageBlock title="My Cases">
            <apex:pageBlockTable value="{!myCases}" var="case">
                <apex:column >
                    <apex:commandLink value="View" action="{!viewCase}">
                        <apex:param name="caseId" value="{!case.Id}"/>
                    </apex:commandLink>
                </apex:column>
                <apex:column headerValue="Subject" value="{!case.Subject}"/>
                <apex:column headerValue="Status" value="{!case.Status}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </div>
</apex:form>
<!-- One form ends here, leaving the detail page out -->
    <div style="float:right;width:73%">
        <apex:detail id="caseDetail" subject="{!selectedCase.Id}" relatedList="false" title="false"/>
    </div>
<!-- Second form begins here, leaving the detail page out -->
<apex:form >
    <div style="width:100%">
        <apex:pageBlock title="Solutions">
            <apex:pageBlockTable value="{!solutions}" var="sol">
                <apex:column >
                    <apex:commandLink value="View" action="{!viewSolution}">
                        <apex:param name="caseId" value="{!sol.Id}"/>
                    </apex:commandLink>
                </apex:column>
                <apex:column headerValue="Solution #" value="{!sol.SolutionNumber}"/>
                <apex:column headerValue="Name" value="{!sol.SolutionName}"/>
                <apex:column headerValue="Status" value="{!sol.Status}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </div>
</apex:form>
<!-- Second form ends here -->
</apex:page>
share|improve this answer
    
i ran google dev tool console and this is the error: Uncaught TypeError: Property 'submit' of object #<HTMLFormElement> is not a function testcase:36 jsfcljs testcase:36 onclick –  user988 Dec 19 '12 at 0:47
    
I cannot reproduce your HTMLFormElement error with the copy and pasted code; however, that error means that there is something else on the page that is a property of the form that is named submit. For example, if I add <input type="text" name="submit" /> to the page within the form I get that error. SF is using JavaScript behind the scenes to submit the form and I suspect at some point there's a form.submit() call. When you name something 'submit' it tries to call that, but it's not a function; hence the error. –  Peter Knolle Dec 19 '12 at 1:00
    
I found out that when I remove the "Submit for approval" button from the page layout it works. That button was made by someone else as part of a workflow I think. Thoughts? –  user988 Dec 19 '12 at 20:31
    
@user988 - That does it for me too. I didn't have the Submit for approval button. I added it and then I inspected the HTML source and saw the Submit for Approval button's name attribute is submit. I have updated my answer with a solution for that. –  Peter Knolle Dec 20 '12 at 1:08
    
Awesome, that worked! Wow, thanks for the help. I really appreciate it, was cracking my head with this one! Just could not figure it out. Cheers! –  user988 Dec 20 '12 at 22:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.