+ Start a Discussion
Dewakar Reddy Karra 9Dewakar Reddy Karra 9 

Hi All. Iam new to Visualforce pages and when i'm trying to get the preview of my visualforce pages it gives me an error

System.QueryException: List has no rows for assignment to SObject 
Class.IITStudyAbroadAppTrackerController.<init>: line 21, column 1

Below is my Apex class 

public with sharing class IITStudyAbroadAppTrackerController {
    
    Public id contactID {get; set;}
    Public id studyAbroadApplicationID {get; set;}
    Public Study_Abroad_Application__c studyAbroadApplication {get; set;}
    Public List<TargetX_SRMb__Essay__c> essayList {get; set;}
    Public List<Study_Abroad_Interest__c> studyAbroadInterestList {get; set;}
    Public Study_Abroad_Application__c enroll {get; set;}
    Public Study_Abroad_Application__c essay {get; set;}
    Public Study_Abroad_Application__c AppEssay{get; set;}
    Public Study_Abroad_Application__c ConEssay{get; set;}
    Public TargetX_SRMb__Application__c getapplication() {
        return null;
    }
    //Public Boolean accessError{get;set}
     
    Public IITStudyAbroadAppTrackerController(ApexPages.StandardController controller) {
        this.studyAbroadApplicationID = controller.getRecord().id;
        this.contactID = ([SELECT ID, Contact__c,Name
                           FROM Study_Abroad_Application__c
                          WHERE id = :studyAbroadApplicationID LIMIT 1]).Contact__c;
        this.studyAbroadApplication = this.queryStudyAbroadApplication();
        this.essayList = this.queryEssayList();
        this.studyAbroadInterestList = this.queryStudyAbroadInterestList();
    }
       
    Public Study_Abroad_Application__c queryStudyAbroadApplication(){
        // queryStudyAbroadApplication queries for a list of Study Abroad Application records that match the application ID, then takes the first record to return
        List<Study_Abroad_Application__c> appList = [
            SELECT ID,
            IIT_Study_Abroad_Application_Status__c,
            IIT_Study_Abroad_Advisor_Approval_Date__c,
            IIT_Banner_ID__c,
            Name
            FROM Study_Abroad_Application__c
            WHERE ID = :studyAbroadApplicationID    
        ];
        
        if(appList.size() > 0) {
            return appList[0];
        } else {
            // If the query fails to find a record, return null.  This shouldn't occur since the method uses an ID 
            return null;
        }
    }
    
    Public List<TargetX_SRMb__Essay__c> queryEssayList() {
        // queryEssayList queries for a list of Essay records that match the contact and study abroad application ID
        List<TargetX_SRMb__Essay__c> essayList = [
            SELECT ID,
            TargetX_SRMb__Contact__c,
            TargetX_SRMb__Application__c,
            TargetX_SRMb__Essay_File_URL__c,
            TargetX_SRMb__Essay_Key__c,
            TargetX_SRMb__Personal_Essay_Type__c,
            TargetX_SRMb__SRM_ETL_ID__c,
            TargetX_SRMb__Complete__c,
            TargetX_SRMb__IsRequired__c,
            TargetX_SRMb__RequirementID__c,
            TargetX_SRMb__Type__c,
            IIT_Insufficiency_ID__c,
            IIT_Insufficiency_ID_Desc__c
          
            FROM TargetX_SRMb__Essay__c
            WHERE TargetX_SRMb__Contact__c = :contactID AND IIT_Study_Abroad_Application__c = :studyAbroadApplicationID
        ];
        return essayList;
    }
    
    Public List<Study_Abroad_Interest__c> queryStudyAbroadInterestList() {
        // queryStudyAbroadInterestList queries for a list of Study Abroad Interest records that match the study abroad application ID
        List<Study_Abroad_Interest__c> studyAbroadInterestList = [
            SELECT ID,
            IIT_Contact__c,
            IIT_Available_Fall__c,
            IIT_Available_Spring__c,
            IIT_Available_Summer__c,
            Elevate_Study_Abroad_Opportunities__c,
            IIT_Opportunity_Type__c,
            IIT_Study_Abroad_Program_Start_Date__c,
            IIT_Study_Abroad_Program_End_Date_del__c
            FROM Study_Abroad_Interest__c
            WHERE IIT_Study_Abroad_Application__c = :studyAbroadApplicationID
        ];
        return studyAbroadInterestList;
    }
}
Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi Dewakar 

Your query return no records.

[SELECT ID, Contact__c,Name
                           FROM Study_Abroad_Application__c
                          WHERE id = :studyAbroadApplicationID LIMIT 1]

The best way is to use collection while querying.

Cheers!!!
 
Raj VakatiRaj Vakati
TRy this code .. BTW your query is retuning the result and you dnt have an contact associated with the Record 
 
public with sharing class IITStudyAbroadAppTrackerController {
    
    Public id contactID {get; set;}
    Public id studyAbroadApplicationID {get; set;}
    Public Study_Abroad_Application__c studyAbroadApplication {get; set;}
    Public List<TargetX_SRMb__Essay__c> essayList {get; set;}
    Public List<Study_Abroad_Interest__c> studyAbroadInterestList {get; set;}
    Public Study_Abroad_Application__c enroll {get; set;}
    Public Study_Abroad_Application__c essay {get; set;}
    Public Study_Abroad_Application__c AppEssay{get; set;}
    Public Study_Abroad_Application__c ConEssay{get; set;}
    Public TargetX_SRMb__Application__c getapplication() {
        return null;
    }
    //Public Boolean accessError{get;set}
     
    Public IITStudyAbroadAppTrackerController(ApexPages.StandardController controller) {
        this.studyAbroadApplicationID = controller.getRecord().id;
		
	Study_Abroad_Application__c abbprd = [	SELECT ID, Contact__c,Name
                           FROM Study_Abroad_Application__c
                          WHERE id = :studyAbroadApplicationID LIMIT 1 ] ; 
						  
		If(abbprd.Contact__c!=NULL){		  
						  
			this.contactID =  abbprd.Contact__c;
		}
        this.studyAbroadApplication = this.queryStudyAbroadApplication();
        this.essayList = this.queryEssayList();
        this.studyAbroadInterestList = this.queryStudyAbroadInterestList();
    }
       
    Public Study_Abroad_Application__c queryStudyAbroadApplication(){
        // queryStudyAbroadApplication queries for a list of Study Abroad Application records that match the application ID, then takes the first record to return
        List<Study_Abroad_Application__c> appList = [
            SELECT ID,
            IIT_Study_Abroad_Application_Status__c,
            IIT_Study_Abroad_Advisor_Approval_Date__c,
            IIT_Banner_ID__c,
            Name
            FROM Study_Abroad_Application__c
            WHERE ID = :studyAbroadApplicationID    
        ];
        
        if(appList.size() > 0) {
            return appList[0];
        } else {
            // If the query fails to find a record, return null.  This shouldn't occur since the method uses an ID 
            return null;
        }
    }
    
    Public List<TargetX_SRMb__Essay__c> queryEssayList() {
        // queryEssayList queries for a list of Essay records that match the contact and study abroad application ID
        List<TargetX_SRMb__Essay__c> essayList = [
            SELECT ID,
            TargetX_SRMb__Contact__c,
            TargetX_SRMb__Application__c,
            TargetX_SRMb__Essay_File_URL__c,
            TargetX_SRMb__Essay_Key__c,
            TargetX_SRMb__Personal_Essay_Type__c,
            TargetX_SRMb__SRM_ETL_ID__c,
            TargetX_SRMb__Complete__c,
            TargetX_SRMb__IsRequired__c,
            TargetX_SRMb__RequirementID__c,
            TargetX_SRMb__Type__c,
            IIT_Insufficiency_ID__c,
            IIT_Insufficiency_ID_Desc__c
          
            FROM TargetX_SRMb__Essay__c
            WHERE TargetX_SRMb__Contact__c = :contactID AND IIT_Study_Abroad_Application__c = :studyAbroadApplicationID
        ];
        return essayList;
    }
    
    Public List<Study_Abroad_Interest__c> queryStudyAbroadInterestList() {
        // queryStudyAbroadInterestList queries for a list of Study Abroad Interest records that match the study abroad application ID
        List<Study_Abroad_Interest__c> studyAbroadInterestList = [
            SELECT ID,
            IIT_Contact__c,
            IIT_Available_Fall__c,
            IIT_Available_Spring__c,
            IIT_Available_Summer__c,
            Elevate_Study_Abroad_Opportunities__c,
            IIT_Opportunity_Type__c,
            IIT_Study_Abroad_Program_Start_Date__c,
            IIT_Study_Abroad_Program_End_Date_del__c
            FROM Study_Abroad_Interest__c
            WHERE IIT_Study_Abroad_Application__c = :studyAbroadApplicationID
        ];
        return studyAbroadInterestList;
    }
}

 
Dewakar Reddy Karra 9Dewakar Reddy Karra 9
Hi Raj
I tried putting the code which was given by you.But its give me the same error
Vinod Chokkula 3Vinod Chokkula 3
Dewakar,

Can you check if you have contact record associated to the Study_Abroad_Application__c record you are referring?
 
Dewakar Reddy Karra 9Dewakar Reddy Karra 9
Hi Vinod 

There are two contact records associated to Study_Abroad_Application__c record 
Vinod Chokkula 3Vinod Chokkula 3
What is the relationship between Contact and Study_Abroad_Application__c?
If Contact is the parent, you will have two contact records from a single Study_Abroad_Application__c 
If Study_Abroad_Application__c is the parent, you may have to change the query to [Select id from contact where Study_Abroad_Application__c=:studyAbroadApplicationID limit 1];

Also, try this query, this could work
SELECT ID, Contact__c,Name
                           FROM Study_Abroad_Application__c
                          WHERE id = :studyAbroadApplicationID and Contact__c !=null LIMIT 1
Dewakar Reddy Karra 9Dewakar Reddy Karra 9
Hi Vinod
Here contact is the master detail realtionship to StudyAbroadApplication object. So in this case the contact would be the parent and StudyAbroadAppplication would be the child.

I have tried the query given by you.But Still no luck
Vinod Chokkula 3Vinod Chokkula 3
Try executing the query in the Developer console to see if it returns the contact. If you get your result there, then there may problem with the id you are passing.
Are you passing the id to preview the visualforce page?
Dewakar Reddy Karra 9Dewakar Reddy Karra 9
When i execute the query in query editor it works fine. No iam not passing any id to preview the the visualforce page 
 
Dewakar Reddy Karra 9Dewakar Reddy Karra 9
The Query is working fine but its giving me different error on my visualforce page when iam trying to access the preview
System.TypeException: Invalid conversion from runtime type Study_Abroad_Application__c to TargetX_SRMb__Application__c 
Vinod Chokkula 3Vinod Chokkula 3
Pass the id in the URL
In the preview, your URL may something like this cs59.salesforce.com/apex/IITStudyAbroadAppTracker 
change this to cs59.salesforce.com/apex/IITStudyAbroadAppTracker?id=12344444 , replace id part with Study_Abroad_Application__c SalesforceID

 
Dewakar Reddy Karra 9Dewakar Reddy Karra 9
Even after passing the id in url it still gives the same error
vin perlvin perl
thank you for sharing me. you should look over this ( https://toqueparacelular.net (https://toqueparacelular.net/) )
https://toqueparacelular.net/iphone ).
Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi Dewakar 

Could you please share the URL once your PDF is opened.
And also share the debug statment for the value of 'studyAbroadApplicationID'.

Cheers!!!! 
Dewakar Reddy Karra 9Dewakar Reddy Karra 9
https://illinoistech--test--c.cs3.visual.force.com/apex/IITStudyAbroadAppTracker?core.apexpages.request.devconsole=1
Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi Dewakar

Share the url when you click on the 'Generate PDF' Button not the preview link from Dev Console.

And do share the debug statement for the value of 'studyAbroadApplicationID'.
Dewakar Reddy Karra 9Dewakar Reddy Karra 9
Hi Syed

This is the URL for PDF button: https://illinoistech--test--c.cs3.visual.force.com/apex/IITStudyAbroadAppTracker?scontrolCaching=1&id=a4FQ0000000MJOV

 
Syed Insha Jawaid 2Syed Insha Jawaid 2
HI Dewakar 

You tested the query using this id in URL and it works fine rght?
You have added this class in extensions attribute of vf page?
And the debug statement also displays the same value of id in debug log?

If all of these conditions satisfy then I think we need to connect to resolve this issue.

Cheers!! 
Nan cwillNan cwill
One day her curiosity won against common sense and she decided to break down her boundaries. She left home and entered a forest after the sun went down. Lost and afraid in the new world geometry dash
 
neha sharma 314neha sharma 314
This is a brilliant article I have found here lots of information here thanks for sharing this wonderful article with us!
Sex dating delight (http://www.sexdatingdelight.com/)
Acacia AdelaAcacia Adela
Thank you for sharing this useful thing. If possible, some pretty cool Mp3 files were widely shared by https://toqueparacelular.com/.
jillian montaguejillian montague
Thanks for sharing the code, I am coding for the fastest navigation directions (https://directionsmaps.io)
Jason Lee 162Jason Lee 162
Hello everyone! Have you ever heard about online writing companies?! No?! You must click on this writing agency's webpage (see statement of purpose for masters in computer science (https://www.sopservices.net/writing-sop-for-ms-in-computer-science-your-911-handbook/) wright here) to know more information and to order essays online, as they have the lowest prices for all of you, my dear visitors!