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
apple_saeapple_sae 

List has no rows for assignment to SObject

Hi All,

 

I try to send the param from Visualforce page to my controller I just want to deleted my record from list

 

 

List has no rows for assignment to SObject

Error is in expression '{!removePayment}' in component <apex:page> in page welcomecustomerportal


An unexpected error has occurred. Your development organization has been notified.

 

My Visualforce Page:

<apex:repeat value="{!lstAuthContacts}" var="AC">
  <apex:outputField value="{!AC.Name}"/>
  <apex:outputField value="{!AC.Contact_Type__c}"/>
   
  <apex:form>
   <apex:commandLink value="Remove" action="{!removeContact}">
    <apex:param name="delContact" value="{!AC.Id}" assignTo="{!cParam}"></apex:param>
   </apex:commandLink>
  </apex:form>

 

My Controller:

 

public class AccountProfileController {

    public list<Contact> lstAuthContacts{get;set;}
	public AccountProfileController(){
		getlstAuthContacts();			
	}    
	public void getlstAuthContacts(){    	
    	lstAuthContacts = [Select	Contact.Id,
                                        Contact.Name,
                                        Contact.Contact_Type__c,
                           From	        Contact
                           Where	Contact.AccountId = ::ApexPages.currentPage().getParameters().get('id')
                           And		Contact.Contact_Type__c = 'Authorized Contact'];
    	
    }

    public string cParam{get; set;}
    public PageReference removeContact(){
    	if(cParam != null || cParam != ''){
        Contact contact = [select Id from Contact where id=:cParam];            
        delete contact; 
    	}else{
    		system.assertEquals('removeContact', 'ContactId = '+cParam);
    	}    
        return null;
    }    
}

 

It's work, my record is deleted but on visualforce is Show the error around 5 minute, after that I refresh agian it work agian

 

What going on?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
apple_saeapple_sae

Thank you vishal@forc
I have tired like your suggestion, but still not working .

 

but I founded solution I changed my controller to be like this:

 

public class AccountProfileController {

        public list<Contact> lstAuthContacts = new list<Contact>();

	public AccountProfileController(){	
	}  
  
	public list<Contact> getlstAuthContacts(){    	
    	lstAuthContacts = [Select	Contact.Id,
                                        Contact.Name,
                                        Contact.Contact_Type__c,
                           From	        Contact
                           Where	Contact.AccountId = :ApexPages.currentPage().getParameters().get('id')
                           And		Contact.Contact_Type__c = 'Authorized Contact'];
       return lstAuthContacts ;    	
       }

    public string cParam{get; set;}
    public PageReference removeContact(){
    	if(cParam != null || cParam != ''){
        Contact contact = [select Id from Contact where id=:cParam];            
        delete contact; 
    	}else{
    		system.assertEquals('removeContact', 'ContactId = '+cParam);
    	}    
        return null;
    }    
}

 Thank you for you help

 

All Answers

vishal@forcevishal@force

Your code looks fine except for this one condition check,

 

if(cParam != null || cParam != ''){

 

Make it  - if(cParam != null && cParam != '')

 

Reason - If at all there's no parameter sent from the page, it can be blank or null and in either case you should not be querying. Rest all looks fine to me.

apple_saeapple_sae

Thank you vishal@forc
I have tired like your suggestion, but still not working .

 

but I founded solution I changed my controller to be like this:

 

public class AccountProfileController {

        public list<Contact> lstAuthContacts = new list<Contact>();

	public AccountProfileController(){	
	}  
  
	public list<Contact> getlstAuthContacts(){    	
    	lstAuthContacts = [Select	Contact.Id,
                                        Contact.Name,
                                        Contact.Contact_Type__c,
                           From	        Contact
                           Where	Contact.AccountId = :ApexPages.currentPage().getParameters().get('id')
                           And		Contact.Contact_Type__c = 'Authorized Contact'];
       return lstAuthContacts ;    	
       }

    public string cParam{get; set;}
    public PageReference removeContact(){
    	if(cParam != null || cParam != ''){
        Contact contact = [select Id from Contact where id=:cParam];            
        delete contact; 
    	}else{
    		system.assertEquals('removeContact', 'ContactId = '+cParam);
    	}    
        return null;
    }    
}

 Thank you for you help

 
This was selected as the best answer
Sfdc@SmithaSfdc@Smitha

HI apple_sae

 

iam new one to apex and visualforce i tried  your code but it showing error like

 

ErrorError: Compile Error: unexpected token: 'From' at line 12 column 27

how this code solve please help me?

apple_saeapple_sae

Hi, Sfdc@Smitha

 

Please shoe me your query, I'm not sure may be you for got to put a symbol like :

 

 Contact contact = [select Id from Contact where id=:cParam]; 

 

 

SLockardSLockard

That's because there is an extra comma in there. Try changing the query to this:

 

lstAuthContacts = [Select	Contact.Id,
                                        Contact.Name,
                                        Contact.Contact_Type__c
                           From	        Contact
                           Where	Contact.AccountId = :ApexPages.currentPage().getParameters().get('id')
                           And		Contact.Contact_Type__c = 'Authorized Contact'];