You need to sign in to do that
Don't have an account?
Andrew Aldis
Retrieve a list of child records for a VF picklist
I am trying to create a VF page that will allow me to query related records and use the list as options for a VF page Picklist. I got it working but when I add a where condition to my Query I get this error "Content cannot be displayed: SObject row was retrieved via SOQL without querying the requested field: Package__c.Client_Workbook__c" I am not sure why it does not accept my where clause. Can someone let me know where I went wrong.
public class PackageSignInstanceJunctionController {
// Constructor
public PackageSignInstanceJunctionController(ApexPages.StandardController controller)
//master
{
this.proj = (Package__c)controller.getRecord();
this.clientWorkbook = proj.Client_Workbook__c;
this.junction = [ SELECT t.Package__c, t.Sign_Instance__c, t.Name, t.Id, t.Record_Type_Name__c, t.CreatedDate
FROM Package_Sign_Instance_Junction__c t
WHERE t.Package__c = :proj.Id ORDER BY t.CreatedDate Desc];
//Picklist Options
signTemp = [Select s.Name, s.Id From Sign_Instance__c s where Client_Workbook__c = :clientWorkbook];
signList = new List<SelectOption>();
for(Sign_Instance__c temp : signTemp)
{
signList.add(new SelectOption(temp.Id, temp.Name));
}
}
// Insert new Staff junction
public pagereference insertmethod()
{
Package_Sign_Instance_Junction__c cc= new Package_Sign_Instance_Junction__c();
cc.Package__c = proj.id;
insert cc;
return null;
}
public Package_Sign_Instance_Junction__c[] getjunction() {
return this.junction;
}
// Action Method called from page button
public pagereference saveChanges() {
upsert this.junction;
pageRef.setRedirect(true);
return pageRef;
}
// Action Method called from page link
public pagereference newjunction() {
Package_Sign_Instance_Junction__c d = new Package_Sign_Instance_Junction__c();
d.Package__c = this.proj.id;
junction.add( d );
getjunction();
return null;
}
public pagereference DeleteAccount()
{
// if for any reason we are missing the reference
if (SelectedAccountId == null)
{
return null;
}
// find the account record within the collection
Package_Sign_Instance_Junction__c tobeDeleted = null;
for(Package_Sign_Instance_Junction__c a : this.junction)
if (a.Id == SelectedAccountId)
{
tobeDeleted = a;
break;
}
//if account record found delete it
if (tobeDeleted != null)
{
Delete tobeDeleted;
}
pageRef.setRedirect(true);
return pageRef;
}
// class variables
PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
public List<Sign_Instance__c> signTemp = new List<Sign_Instance__c>();
Package__c proj;
Package_Sign_Instance_Junction__c[] junction;
Sign_Instance__c[] sign;
public string SelectedAccountId { get; set; }
public string clientWorkbook { get; set; }
public List<SelectOption> signList {get;set;}
}
public class PackageSignInstanceJunctionController {
// Constructor
public PackageSignInstanceJunctionController(ApexPages.StandardController controller)
//master
{
this.proj = (Package__c)controller.getRecord();
this.clientWorkbook = proj.Client_Workbook__c;
this.junction = [ SELECT t.Package__c, t.Sign_Instance__c, t.Name, t.Id, t.Record_Type_Name__c, t.CreatedDate
FROM Package_Sign_Instance_Junction__c t
WHERE t.Package__c = :proj.Id ORDER BY t.CreatedDate Desc];
//Picklist Options
signTemp = [Select s.Name, s.Id From Sign_Instance__c s where Client_Workbook__c = :clientWorkbook];
signList = new List<SelectOption>();
for(Sign_Instance__c temp : signTemp)
{
signList.add(new SelectOption(temp.Id, temp.Name));
}
}
// Insert new Staff junction
public pagereference insertmethod()
{
Package_Sign_Instance_Junction__c cc= new Package_Sign_Instance_Junction__c();
cc.Package__c = proj.id;
insert cc;
return null;
}
public Package_Sign_Instance_Junction__c[] getjunction() {
return this.junction;
}
// Action Method called from page button
public pagereference saveChanges() {
upsert this.junction;
pageRef.setRedirect(true);
return pageRef;
}
// Action Method called from page link
public pagereference newjunction() {
Package_Sign_Instance_Junction__c d = new Package_Sign_Instance_Junction__c();
d.Package__c = this.proj.id;
junction.add( d );
getjunction();
return null;
}
public pagereference DeleteAccount()
{
// if for any reason we are missing the reference
if (SelectedAccountId == null)
{
return null;
}
// find the account record within the collection
Package_Sign_Instance_Junction__c tobeDeleted = null;
for(Package_Sign_Instance_Junction__c a : this.junction)
if (a.Id == SelectedAccountId)
{
tobeDeleted = a;
break;
}
//if account record found delete it
if (tobeDeleted != null)
{
Delete tobeDeleted;
}
pageRef.setRedirect(true);
return pageRef;
}
// class variables
PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
public List<Sign_Instance__c> signTemp = new List<Sign_Instance__c>();
Package__c proj;
Package_Sign_Instance_Junction__c[] junction;
Sign_Instance__c[] sign;
public string SelectedAccountId { get; set; }
public string clientWorkbook { get; set; }
public List<SelectOption> signList {get;set;}
}
Nayana K