+ Start a Discussion
MMA_FORCEMMA_FORCE 

Override New button on Contact?Works sometimes ?? WHy Please Help??

This error comes up sometimes, and sometimes it does not... When I refresh the screen, it worked, ... Can someone tell me how to fix my code so that it works all the time...

I am overriding the New Contact button on the Account side...

so from Account click new contact and this is the code pointing to it:

System.QueryException: List has no rows for assignment to SObject????

Class.OverrideNewContactExtension.<init>: line 10, column 17
External entry point
 

 

public class OverrideNewContactbutton {

Account a{get;set;}
boolean gotaccount=false;
public OverrideNewContactbutton(ApexPages.StandardController stdController){
string ret=ApexPages.currentPage().getParameters().get('RetURL');
ret=ret.substring(1,ret.length());
if(ret.startswith('001')){

a = [Select name,recordtype.name,id
from Account where id=:ret];
gotaccount=true;

}
}


public PageReference init() {
String redirectUrl = '';
String recordTypeId = System.currentPageReference().getParameters().get('RecordType');
Id parterProfileId = [SELECT Id FROM Profile WHERE Name ='donation User'].Id;

if (UserInfo.getProfileId() == parterProfileId) {
return null;
}
else {

if(gotaccount) {
redirectUrl = '/003/e?accid='+a.id+'&RecordType='+recordtypeId+'&nooverride=1';
}

else {
redirectUrl = '/003/e?nooverride=1';
}



}
PageReference newContact = new PageReference(redirectUrl);
return newContact;

}


public PageReference wizard() {

PageReference Wizard = new PageReference('/apex/testpage');
return Wizard;
}

 

 

 

Message Edited by MMA_FORCE on 03-29-2010 05:25 PM
Best Answer chosen by Admin (Salesforce Developers) 
Shailesh DeshpandeShailesh Deshpande

i guess you are not getting any Id value matching to that of ret ...

 

try this....

 

a = [select fields from account where id := stdcontroller.getId()];

 

 

Message Edited by Shailesh on 03-31-2010 12:53 AM

All Answers

Shailesh DeshpandeShailesh Deshpande

this is probably because you are getting an empty list in you query

 

a = [Select name,recordtype.name,id 
from Account where id=:ret];

 

MMA_FORCEMMA_FORCE

But how come when I am on the Account itself and then I hit New Contact??

Shouldn't that query always not be empty??

 

Is there another way to do it?

Shailesh DeshpandeShailesh Deshpande

i guess you are not getting any Id value matching to that of ret ...

 

try this....

 

a = [select fields from account where id := stdcontroller.getId()];

 

 

Message Edited by Shailesh on 03-31-2010 12:53 AM
This was selected as the best answer