function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
QingsongQingsong 

Commandlink parameter pass problem

Hi, I do have a page which have pageBlock table, I want to click the link in one of the row then jump to the line item edit page, after complete the edit page, click save button, the page can get back to the view page, so there I am using apex-param to pass the line item Id to the line item edit page, there is no problem when I click the link, the edit page shows up with respect record, but the problem is coming when I click the save button, the system give me a error message "System.QueryException: List has no rows for assignment to SObject Class.InnovationExtension.getInnovationToolItem: line 25, column 49
External entry point

Line Item Edit Page <apex:page standardController="In__c" showHeader="true" extensions="InnovationExtension" tabStyle="In__c"> <apex:sectionHeader title="Commercialization/Timing Items Edit" subtitle="{!InnovationToolItem.Name}"></apex:sectionHeader> <apex:form > <apex:pageBlock title="Edit" mode="Edit"> <apex:pagemessages /> <apex:pageBlockButtons > <apex:commandButton action="{!checkListItemSave}" value="Save" /> <apex:commandButton action="{!checkListItemCancel}" value="Cancel" /> </apex:pageBlockButtons> <apex:pageBlockSection title="General Information" columns="1"> <apex:outputField value="{!InnovationToolItem.Name}" style="width: 325px; height: 18px"/> <apex:inputField value="{!InnovationToolItem.Needed_or_Not__c}" /> <apex:inputField value="{!InnovationToolItem.Owner__c}" style="width: 200px; height: 18px"/> <apex:inputField value="{!InnovationToolItem.Target_Completion_Date__c}" style="width: 200px; height: 18px"/> <apex:inputField value="{!InnovationToolItem.Actual_Completion_Date__c}" style="width: 200px; height: 20px"/> <apex:inputField value="{!InnovationToolItem.Status__c}" style="width: 300px; height: 18px"/> <apex:inputField value="{!InnovationToolItem.Comments__c}" style="width: 600px; height: 72px"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> <apex:relatedList subject="{!InnovationToolItem}" list="NotesAndAttachments" /> </apex:page>

 

"

master details - list view page:

 

<apex:page standardController="In__c" showHeader="true" extensions="InnovationExtension" tabStyle="In__c">
.......... 

<apex:pageBlock title="Commercialization Checklist" mode="view"> <!-- Display General Group --> <apex:pageBlockSection title="General" id="Generals" columns="1"> <apex:pageBlockTable value="{!Generals}" var="ge"> <apex:column value="{!ge.No__c}" width="50" /> <apex:column headervalue="Items" width="500"> <apex:commandLink action="{!checkListItem}" value="{!ge.Name}" > <apex:param name="Checklist" value="{!ge.id}"/> </apex:commandLink> </apex:column> <apex:column headerValue="Needed?" width="50" > <apex:outputField value="{!ge.Needed_or_Not__c}" /> </apex:column> <apex:column headerValue="Exist?" width="50" > <apex:outputField value="{!ge.Exist_or_Not__c}" /> </apex:column> <apex:column headerValue="Owner" width="150" > <apex:outputField value="{!ge.Owner__c}" /> </apex:column> <apex:column headerValue="Original Target Completion Date" width="150" > <apex:outputField value="{!ge.Target_Completion_Date__c}" /> </apex:column> <apex:column headerValue="Forecast/Actual Completion Date" width="150" > <apex:outputField value="{!ge.Actual_Completion_Date__c}" /> </apex:column> <apex:column headerValue="Status" width="150" > <apex:outputField value="{!ge.Status__c}" /> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection>

 

 

 

standard controller extension public class InnovationExtension { private final In__C Innovations; List<Innovation_Tool__c> Launchs; Innovation_Tool__c InnovationToolItem; public Innovation_Tool__c getInnovationToolItem(){

//Error here, when I click the save button in line item page, the system give the the error displayed above. Innovation_Tool__c InnovationToolItem = [Select Id, IsDeleted, Name, No__c, Innovation__c, Needed_or_Not__c, Exist_or_Not__c, Group__c, Owner__c, Target_Completion_Date__c, Actual_Completion_Date__c, Status__c, Comments__c FROM Innovation_Tool__c where Id = :ApexPages.currentPage().getParameters().get('Checklist')]; return InnovationToolItem; } public InnovationExtension(ApexPages.StandardController controller) { this.Innovations = (In__C)controller.getRecord(); InnovationsList = [Select Id, IsDeleted, Name, Market_Drivers_Trends__c FROM In__c where Id = :ApexPages.currentPage().getParameters().get('id') Limit 1]; Launchs = (List<Innovation_Tool__c>)[Select Id, IsDeleted, Name, No__c, Innovation__c, Needed_or_Not__c, Exist_or_Not__c, Group__c, Owner__c, Target_Completion_Date__c, Actual_Completion_Date__c, Status__c FROM Innovation_Tool__c where Innovation__c = :ApexPages.currentPage().getParameters().get('id') and Group__c='Launch' order by No__c]; } public PageReference checkListItem() { PageReference pdfPage = Page.ADPItemEdit; pdfpage.setRedirect(false); return pdfPage; } public PageReference checkListItemSave() { update InnovationToolItem; return Page.Innovation; } public PageReference checkListItemCancel() { return Page.Innovation; } }

 

 

I used same standard controller extension in both pages, as per the tips from Visualforce Page developer wazird guide line, the controll should not be rerender when I switched in different page but use same controller, not sure where wrong, Please save me!!!

 

Thanks a lot

 

 

Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler

That exception means that your query didn't return any results.  And since the page loads fine initially, I suspect that your parameter is null. The reason this is happening is because when you hit save,  you're doing a postback that first calls your getters, then your setters, and you query param is wiped out once you hit save -- you're no longer passing in the checklist parameter that you need.  To illustrate the issue, I suspect that this would fix it:

 

<apex:commandButton action="{!checkListItemSave}" value="Save"> <apex:param name="Checklist" value="{!$CurrentPage.parameters.Checklist}"/> </apex:commandButton>

Although this is not the solution I would suggest to you, I think it illustrates the issue.  We do not automatically forward your parameters for you, it wouldn't make sense to.

 

The real problem here is that you have no reason to be doing that query more than once.  Especially considering that you have several calls to InnovationToolItem in your page, it's going to call the getter for every expression that references it, and thus will run the query every time.  That's overkill.  What you should be doing is storing off the object once you load it the first time:

 

 

public Innovation_Tool__c getInnovationToolItem(){

if (InnovationToolItem == null) { InnovationToolItem = [Select Id, IsDeleted, Name, No__c, Innovation__c, Needed_or_Not__c, Exist_or_Not__c, Group__c, Owner__c,

Target_Completion_Date__c, Actual_Completion_Date__c, Status__c, Comments__c FROM Innovation_Tool__c

where Id = :ApexPages.currentPage().getParameters().get('Checklist')];

 

return InnovationToolItem;

}

 

 Much more efficient, and should also fix your issue.

 

 

 

All Answers

jwetzlerjwetzler

That exception means that your query didn't return any results.  And since the page loads fine initially, I suspect that your parameter is null. The reason this is happening is because when you hit save,  you're doing a postback that first calls your getters, then your setters, and you query param is wiped out once you hit save -- you're no longer passing in the checklist parameter that you need.  To illustrate the issue, I suspect that this would fix it:

 

<apex:commandButton action="{!checkListItemSave}" value="Save"> <apex:param name="Checklist" value="{!$CurrentPage.parameters.Checklist}"/> </apex:commandButton>

Although this is not the solution I would suggest to you, I think it illustrates the issue.  We do not automatically forward your parameters for you, it wouldn't make sense to.

 

The real problem here is that you have no reason to be doing that query more than once.  Especially considering that you have several calls to InnovationToolItem in your page, it's going to call the getter for every expression that references it, and thus will run the query every time.  That's overkill.  What you should be doing is storing off the object once you load it the first time:

 

 

public Innovation_Tool__c getInnovationToolItem(){

if (InnovationToolItem == null) { InnovationToolItem = [Select Id, IsDeleted, Name, No__c, Innovation__c, Needed_or_Not__c, Exist_or_Not__c, Group__c, Owner__c,

Target_Completion_Date__c, Actual_Completion_Date__c, Status__c, Comments__c FROM Innovation_Tool__c

where Id = :ApexPages.currentPage().getParameters().get('Checklist')];

 

return InnovationToolItem;

}

 

 Much more efficient, and should also fix your issue.

 

 

 

This was selected as the best answer
KuldeepKuldeep

Hi,

 

I do have same kind of issue. When I use commandLink in following :

 

<apex:variable var="forecastIndex" value="{!0}"/>

<apex:commandLink value="{!greaterThanSymbol}" action="{!copySalesQuantityToNext}">

<apex:param name="forecastIndex" value="{!forecastIndex}"/>

</apex:commandLink>

 

I can get value in 'forecastIndex' parameter from the controller, but when I use commandButton I can't.

 

<apex:variable var="forecastIndex" value="{!0}"/>

<apex:commandButton value="{!greaterThanSymbol}" action="{!copySalesQuantityToNext}">

<apex:param name="forecastIndex" value="{!forecastIndex}"/>

</apex:commandButton>

 

What can be the issue?

 

Thanks,

Kuldeep

sfdcFanBoysfdcFanBoy
Simplest and straighforward solution
public String selectedId{get;set;}
<apex:commandLink value="Check" action="{!Check}" >
     <apex:param assignTo="{!selectedId}" value="{!item.Id}" name="selectedId" />
</apex:commandLink>
public void Check(){
  	System.debug('selected Id-----'+selectedMatchId);
}

Cheers,
www.sfdcfanboy.com