You need to sign in to do that
Don't have an account?
List has no rows for assignment
Im getting error like List has no rows for assignment to SObject here im giving the code plse tell me what s the error in that controller.
public class AAFControl {
private ApexPages.StandardController con;
private Application_Form__c objAAF;
private Application_Form__c aaf = new Application_Form__c();
//public List<Application_Form__c> aaform{get;set;}
public String LDate{get;set;}
public String EDate{get;set;}
public String BDate{get;set;}
private String AfName{get;set;}
public String sDate{get;set;}
public String stDate{get;set;}
public String cDate{get;set;}
public String dyDate{get;set;}
public String oDate{get;set;}
public String eyDate{get;set;}
public String tDate{get;set;}
public String fDate{get;set;}
public Id pid;
public Id aafId;
public AAFControl(ApexPages.StandardController controller) {
con=controller;
aafId=con.getRecord().id;
system.debug('iddddddddddddddddddddddd'+aafId);
aaf=[select Id,Date_of_Issue__c,Expiry_Date__c,Date_of_Birth__c,SPM_O_Level_or_equivalent_Year_of_Comp__c,STPM_A_Level_UEC_or_equivalent_Year__c,Certificate_Year_if_Completion__c,Diploma_Year_if_Completion__c,Others_Year_if_Completion__c,English_1119_Year_of_Completion__c,TOEFL_IELT_Year_of_Completion__c,Form__c from Application_Form__c where id=:aafId];
system.debug('testtttttttttttttttttt'+aaf);
//aaf = [select Id,Date_of_Issue__c,Expiry_Date__c,Date_of_Birth__c,SPM_O_Level_or_equivalent_Year_of_Comp__c,STPM_A_Level_UEC_or_equivalent_Year__c,Certificate_Year_if_Completion__c,Diploma_Year_if_Completion__c,Others_Year_if_Completion__c,English_1119_Year_of_Completion__c,TOEFL_IELT_Year_of_Completion__c,Form__c from Application_Form__c where id=:ApexPages.currentPage().getParameters().get('id')][0];
//aaf = aaform.get(0);
// aafform=aaf.get(0);
// system.debug('AAFFFFFFFFFFFFFF'+aafform);
// pid = aaform.id;
system.debug('pid'+pid);
DateTime dt=aaf.Date_of_Issue__c;
DateTime ed=aaf.Expiry_Date__c;
DateTime dob=aaf.Date_of_Birth__c;
DateTime spm=aaf.SPM_O_Level_or_equivalent_Year_of_Comp__c;
DateTime stpm=aaf.STPM_A_Level_UEC_or_equivalent_Year__c;
DateTime cyc=aaf.Certificate_Year_if_Completion__c;
DateTime dyc=aaf.Diploma_Year_if_Completion__c;
DateTime oyc=aaf.Others_Year_if_Completion__c;
DateTime eyc=aaf.English_1119_Year_of_Completion__c;
DateTime toe=aaf.TOEFL_IELT_Year_of_Completion__c;
DateTime frm=aaf.Form__c;
sDate=' ';
stDate=' ';
dyDate=' ';
cDate=' ';
oDate=' ';
tDate=' ';
fDate=' ';
eyDate=' ';
LDate=dt.format('dd-MM-yyyy');
EDate=ed.format('dd-MM-yyyy');
BDate=dob.format('dd-MM-yyyy');
sDate=spm.format('dd-MM-yyyy');
stDate=stpm.format('dd-MM-yyyy');
cDate=cyc.format('dd-MM-yyyy');
dyDate=dyc.format('dd-MM-yyyy');
oDate=oyc.format('dd-MM-yyyy');
eyDate=eyc.format('dd-MM-yyyy');
tDate=toe.format('dd-MM-yyyy');
fDate=frm.format('dd-MM-yyyy');
}
public PageReference saveSB() {
con.save();
objAAF = new Application_Form__c();
PageReference pr=null;
String ObjectPrefix =Application_Form__c.sObjectType.getDescribe().getKeyPrefix();
pr = new PageReference('/' + ObjectPrefix + '/o');
pr.setRedirect(true);
insert objAAF;
return pr;
}
public PageReference getdummyAction() {
return null;
}
public static testMethod void testAccount () {
Account a= new Account(Name='Test Account1');
insert a;
ApexPages.currentPage().getParameters().put('Id1',a.Id);
ApexPages.StandardController controller2 = new ApexPages.StandardController(a);
AAFControl afc1 = new AAFControl(controller2);
Application_Form__c aaf1= new Application_Form__c(name='demoapplicationform');
insert aaf1;
ApexPages.currentPage().getParameters().put('Id',aaf1.Id);
ApexPages.StandardController controller1 = new ApexPages.StandardController(aaf1);
AAFControl afc = new AAFControl(controller1);
}
}
Hey Amrit, Can you provide details as to which line is it throwing this error?
Sure.in the given below hightlighted lines its showing list has no rows for assignment to SobjectExternal entry point.
where is wrong in my code.plse give me solution
public class AAFControl {
private ApexPages.StandardController con;
private Application_Form__c objAAF;
private Application_Form__c aaf = new Application_Form__c();
//public List<Application_Form__c> aaform{get;set;}
public String LDate{get;set;}
public String EDate{get;set;}
public String BDate{get;set;}
private String AfName{get;set;}
public String sDate{get;set;}
public String stDate{get;set;}
public String cDate{get;set;}
public String dyDate{get;set;}
public String oDate{get;set;}
public String eyDate{get;set;}
public String tDate{get;set;}
public String fDate{get;set;}
public Id aafId;
public AAFControl(ApexPages.StandardController controller) {
con=controller;
aafId=con.getRecord().id;
system.debug('iddddddddddddddddddddddd'+aafId);
aaf=[select Id,Date_of_Issue__c,Expiry_Date__c,Date_of_Birth__
c,SPM_O_Level_or_equivalent_Year_of_Comp__c,STPM_A_Level_UEC_or_equivalent_Year__c,Certificate_Year_if_Completion__c,Diploma_Year_if_Completion__c,Others_Year_if_Completion__c,English_1119_Year_of_Completion__c,TOEFL_IELT_Year_of_Completion__c,Form__c from Application_Form__c where id=:aafId];
DateTime dt=aaf.Date_of_Issue__c;
DateTime ed=aaf.Expiry_Date__c;
DateTime dob=aaf.Date_of_Birth__c;
DateTime spm=aaf.SPM_O_Level_or_equivalent_Year_of_Comp__c;
DateTime stpm=aaf.STPM_A_Level_UEC_or_equivalent_Year__c;
DateTime cyc=aaf.Certificate_Year_if_Completion__c;
DateTime dyc=aaf.Diploma_Year_if_Completion__c;
DateTime oyc=aaf.Others_Year_if_Completion__c;
DateTime eyc=aaf.English_1119_Year_of_Completion__c;
DateTime toe=aaf.TOEFL_IELT_Year_of_Completion__c;
DateTime frm=aaf.Form__c;
sDate=' ';
stDate=' ';
dyDate=' ';
cDate=' ';
oDate=' ';
tDate=' ';
fDate=' ';
eyDate=' ';
LDate=dt.format('dd-MM-yyyy');
EDate=ed.format('dd-MM-yyyy');
BDate=dob.format('dd-MM-yyyy');
sDate=spm.format('dd-MM-yyyy');
stDate=stpm.format('dd-MM-yyyy');
cDate=cyc.format('dd-MM-yyyy');
dyDate=dyc.format('dd-MM-yyyy');
oDate=oyc.format('dd-MM-yyyy');
eyDate=eyc.format('dd-MM-yyyy');
tDate=toe.format('dd-MM-yyyy');
fDate=frm.format('dd-MM-yyyy');
}
public PageReference saveSB() {
con.save();
objAAF = new Application_Form__c();
PageReference pr=null;
String ObjectPrefix =Application_Form__c.sObjectType.getDescribe().getKeyPrefix();
pr = new PageReference('/' + ObjectPrefix + '/o');
pr.setRedirect(true);
insert objAAF;
return pr;
}
public PageReference getdummyAction() {
return null;
}
public static testMethod void testAccount () {
Account a= new Account(Name='Test Account1');
insert a;
ApexPages.currentPage().getParameters().put('Id1',a.Id);
ApexPages.StandardController controller2 = new ApexPages.StandardController(a);
AAFControl afc1 = new AAFControl(controller2);
Application_Form__c aaf1= new Application_Form__c(name='demoapplicationform');
insert aaf1;
ApexPages.currentPage().getParameters().put('Id',aaf1.Id);
ApexPages.StandardController controller1 = new ApexPages.StandardController(aaf1);
AAFControl afc = new AAFControl(controller1);
}
}
Account a= new Account(Name='Test Account1');
insert a;
ApexPages.currentPage().getParameters().put('Id1',
a.Id);
ApexPages.StandardController controller2 = new ApexPages.StandardController(a);
AAFControl afc1 = new AAFControl(controller2);
Here you are inserting an account, and creating a controller using that account object.
aaf=[select Id,Date_of_Issue__c,Expiry_Date__c,Date_of_Birth__ c,SPM_O_Level_or_equivalent_Year_of_Comp__c,STPM_A_Level_UEC_or_equivalent_Year__c,Certificate_Year_if_Completion__c,Diploma_Year_if_Completion__c,Others_Year_if_Completion__c,English_1119_Year_of_Completion__c,TOEFL_IELT_Year_of_Completion__c,Form__c from Application_Form__c where id=:aafId];
Here you are querying for an Application_Form__c, and you are looking for the Account ID that you just created.