+ Start a Discussion
Shantanu MahajanShantanu Mahajan 

Apex problem

I am having requirment like 
I am using Pageblocktable in which i have some data and in one column i have given the link called view after clicking on view that particular detail should be viewd..
But it is not working correctly..
I am sharing my code with you

Visualforce
<apex:PageBlockSection columns="1" >
     <apex:pageBlockTable value="{!getc}" var="a">
         <apex:column value="{!a.Name}"/>
         <apex:column value="{!a.customer__c}"/>
         <apex:column value="{!a.E_mail__c}"/>
         <apex:column value="{!a.Phone_Number__c}"/>
         <apex:column headerValue="Action">
         <apex:commandLink value="view" reRender="imagepopup" action="{!addcomp}">
             <apex:param id="custid" value="{!a.id}"/>
         </apex:commandLink>
         </apex:column>
     </apex:pageBlockTable>
 </apex:PageBlockSection>

apex code
public Complaint__c add{get;set;}

public List<Shan__Complaint__c> getc{get;set;}

  public refreshctrl ()
    {
         
        
         getc= [Select id,Name,Shan__customer__c,Shan__E_mail__c,Shan__Phone_Number__c,Shan__Issue_Details__c,Shan__Issue_Summary__c from Shan__Complaint__c]; 
          
    }

public void addcomp()
    {
        ID fid=ApexPages.currentpage().getparameters().get('custid');
        add=[Select id,name,customer__c,E_mail__c,Phone_Number__c,Issue_Summary__c,Issue_Details__c from Complaint__c where id=:fid];
        displayPopUp=true;
       // return new Pagereference('/apex/viewcomp?id='+lid);
        
        
    
    }

It is giving me error:
Visualforce ErrorHelp for this Page
System.QueryException: List has no rows for assignment to SObject
Error is in expression '{!addcomp}' in page shan:cust_complaint: Class.Shan.refreshctrl.addcomp: line 37, column 1
Class.Shan.refreshctrl.addcomp: line 37, column 1     
 
ManojjenaManojjena
Hey Shantanu ,
Change the return type of the method .
public pageReference  addcomp(){

}
Shantanu MahajanShantanu Mahajan
i have commenetd that line
Himanshu ParasharHimanshu Parashar
Hi Shantanu,

This error coming only in two condition

1. ID fid=ApexPages.currentpage().getparameters().get('custid');  in this line custid value is null from the page (solution: put system.debug just after this line and check whether value is coming or not)

2. If custid value is coming try to run query in query editor. Selectid,name,customer__c,E_mail__c,Phone_Number__c,Issue_Summary__c,Issue_Details__c fromComplaint__c where id=:fid
this query returning 0 records from the database so make sure you have record in that object.

Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
sandeep sankhlasandeep sankhla
Hi Shantanu, 
You have not initalized your object and list..Please initalize all of them in constructor because if query return no result then same error it throws..

Please re-initalize and let me know if this helps..

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer 
Ravikant kediaRavikant kedia
Use public List<Complaint__c> add{get;set;} to remove your error.
Shantanu MahajanShantanu Mahajan
@Ravikant kedia: Thank you, But i can't use this.
sandeep sankhlasandeep sankhla
Hi Shantanu,

Did you try initalizing your object and lists ?
Shantanu MahajanShantanu Mahajan
@Sandeep sankhla
Yes
Himanshu ParasharHimanshu Parashar
do you have record with that id in your object ?
 
Shantanu MahajanShantanu Mahajan
@Himanshu Parashar:
Yes