+ Start a Discussion
MikeCloudMikeCloud 

APEX Error help

Not sure what to do  - Client_Status__s is a custom filed on c case, standard contact and account names 

 

 

Error: Compile Error: Didn't understand relationship 'Contacts_r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 123 column 19

 

 

//if (Aid<>){
Account[] AL=[Select a.name,(select name, age__c,CLIENT_STATUS__C from Contacts__r where CLIENT_STATUS__c <>'inactive' and CLIENT_STATUS__c <> 'deceased' Order by Age__c desc) from Account a where id=:request.Account];
if (AL.size()>0){
ANAME=AL[0].name;
if (AL[0].Contacts__r.size()>0{
Alist=AL[0].Contacts__r;
}

}

Andrew WilkinsonAndrew Wilkinson

Try FROM Account.Contacts instead of Contacts__r

MikeCloudMikeCloud

This is the one area in a much larger section that is not working?, it is in Classes that refers to a PDF in the PDF this area won't show up  -  Account name, contacts related to the Account and their Age.  This is for a non-profit, the person who wrote this left.

 

Error: Compile Error: Didn't understand relationship 'Account.Contact' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 123 column 19

 

 

//if (Aid<>){
Account[] AL=[Select a.name,(select name, age__c,Client_Status__c from Account.Contact where Client_Status__c <>'inactive' and Client_Status__c<>'deceased' Order by Age__c desc) from Account a where id=:request.Account];
if (AL.size()>0){
ANAME=AL[0].name;
if (AL[0].Contacts__r.size()>0){
Alist=AL[0].Contacts__r;
}

}

Andrew WilkinsonAndrew Wilkinson

Account.Contacts...missing the s

MikeCloudMikeCloud

Got it now I am here, this saved before?

 

Error: Compile Error: Invalid field Contacts__r for SObject Account at line 127 column 22

 

//if (Aid<>){
Account[] AL=[Select a.name,(select name, age__c,Client_Status__c from Account.Contacts where Client_Status__c <>'inactive' and Client_Status__c<>'deceased' Order by Age__c desc) from Account a where id=:request.Account.Name];
if (AL.size()>0){
ANAME=AL[0].name;
if (AL[0].Contacts__r.size()>0){
Alist=AL[0].Contacts__r;
}

}

 

 

 

 

 

//**************************
// GETTER AND SETTER METHODS
//**************************

//VERSION 1: GET CONTACT INFO
//public Contact getContact(){return a;} //LG
public Case getRequest(){return request;}
public List<wGrocery> getpdfGRItemList() {
List<wGrocery> pdfGRItemList = new List<wGrocery>();
for (Integer i = 0; i<pdfGSortMap.size(); i++) {
if (pdfGSortMap.get(i).quantity > 0) pdfGRItemList.add(pdfGSortMap.get(i));

}

Andrew WilkinsonAndrew Wilkinson

Use the new relationship name instead of Contacts__r it will be Account.Contacts. 

 

Alist = AL[0].Contacts

 

if AL[0].Contacts.size()>0

 

This trigger looks like it needs to be bulkified. It will only work on the first account run through the trigger.

MikeCloudMikeCloud

Thanks for your help I am doing admin work for a non profit this previously written apex code to fill a grocery list for Food for the needy is what I an trying to fix, the Account name, Contacts and ages in the house hold do no appear on Pdf so they do not no how siz of food to give (family size for family, small can for single person...this is a big help thanks!

 

 

Error: Compile Error: Illegal assignment from LIST<Contact> to LIST<Name> at line 127 column 10

 

 

 

//if (Aid<>){
Account[] AL=[Select a.name,(select name, age__c,Client_Status__c from Account.Contacts where Client_Status__c <>'inactive' and Client_Status__c<>'deceased' Order by Age__c desc) from Account a where id=:request.Account.Name];
if (AL.size()>0){
ANAME=AL[0].name;
if (AL[0].Contacts.size()>0){
Alist=AL[0].Contacts;
}

}

Andrew WilkinsonAndrew Wilkinson

When the Alist is declared it is of type Name...

 

Something like... List<Name> Alist = new List<Name>();

The above code is declared somewhere earlier in the class.

 

But the contact list is a list of type contact. If you were just trying to grab the names of the contacts then you could do another for loop and each contact name individually. If you want a list of contacts with all the fields queried then you will need to change Alist to this...

 

List<Contact> Alist = new List<Contact>();

 

MikeCloudMikeCloud

This the whole thing I highlighted the error

 

Error: Compile Error: Illegal assignment from LIST<Contact> to LIST<Name> at line 127 column 10

 

 

public class GroceryUpdate{
//VERSION 1: SORT GROCERY LIST BY CATEGORY
// PDF: INCLUDE THE Contact/Account Name
// Account Members Ages
//VERSION 2: CHANGE QUANTITY TO INTEGER TO REMOVE DECIMAL POINT
//VERSION 3: GET TYPE OF FOOD ORDER and SHOPPING NOTES FROM REQUEST (CASE)

Case request;
//Name crequest;
List <Grocery_Request__c> GRList;
List <Name> AList;
//List <Account> atmplist;
Account aMembers;
Set<Id> GItemIdSet = new Set<Id>();
Set<Id> gIdSet = new Set<Id>();
Map<Id,wGrocery> gMap = new Map<Id,wGrocery>();
Map<Integer,Id> gSortMap = new Map<Integer,Id>();
Map<Integer,wGrocery> pdfGSortMap = new Map<Integer,wGrocery>();
Map<Id,Integer> pdfIdxMap = new Map<Id,Integer>();
List<wGrocery> gList = new List<wGrocery>();
List<Grocery_Item__c> gItemList;
List<Grocery_Item__c> pdfGItemList;
String Aid;
String AName;
// Contact c; //LG

//****************
// CONSTRUCTOR
//****************

public GroceryUpdate() {
Integer idx = 0;

//VERSION 1: SORT BY CATEGORY AFTER WAREHOUSE ORDER
pdfGItemList = [Select g.Warehouse_Order__c, g.Name, g.Id,
g.Grocery_Category__c, g.Available__c
From Grocery_Item__c g
order by Warehouse_Order__c, Grocery_Category__c, Name ASC nulls last
limit 1000];

for (Grocery_Item__c gi : pdfGItemList) {
pdfGSortMap.put(idx,new wGrocery(gi));
pdfIdxMap.put(gi.id,idx);
idx++;
}
system.debug('@@@pdfGSortMap=' + pdfGSortMap);
system.debug('@@@pdfIdxMap=' + pdfIdxMap);

//VERSION 1: SORT BY CATEGORY AFTER AVAILABLE
gItemList = [Select g.Warehouse_Order__c, g.Name, g.Id,
g.Grocery_Category__c, g.Available__c
From Grocery_Item__c g
order by Available__c, Grocery_Category__c, Name ASC nulls last
limit 1000];

idx = 0;
String s = null;
String oldHighlight = '#BDBDBD';

for (Grocery_Item__c gi : gItemList) {
gMap.put(gi.id,new wGrocery(gi));

if (gi.Grocery_Category__c != s ) {
s=gi.Grocery_Category__c;
if (oldHighlight == null) oldHighlight = '#BDBDBD';
else oldHighlight = null;
}

gMap.get(gi.id).highlight = oldHighlight;

if (gi.Available__c == true) {
gSortMap.put(idx,gi.id);
idx++;
}
}

for (Grocery_Item__c gi : gItemList) {
if (gi.Available__c == false) {
gSortMap.put(idx,gi.id);
idx++;
}
}

//VERSION 3: GET Type_of_Food_Order__c and Shopping_List_Notes__c

//request = [Select c.Id, c.Subject, c.Contact.Name, c.ContactId, c.CaseNumber,
// c.Type_of_Food_Order__c, c.Shopping_List_Notes__c,
// (Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantify__c
// From Grocery_Requests__r)
// From Case c
// where id = :ApexPages.currentPage().getParameters().get('id')];

//GRList = request.Grocery_Requests__r;
//system.debug('@@@GRList=' + GRList);

//for (Grocery_Request__c GR : GRList) {
// gMap.get(GR.Grocery_Item__c).quantity = GR.Quantify__c.intValue();
// gIdSet.add(GR.Grocery_Item__c);

// pdfGSortMap.get(pdfIdxMap.get(GR.Grocery_Item__c)).quantity = GR.Quantify__c.intValue();
//}

request = [Select c.Id,c.Account.Name, c.Subject, c.Contact.Name, c.ContactId, c.CaseNumber,
c.Type_of_Food_Order__c, c.Shopping_List_Notes__c,
(Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantity__c
From Grocery_Requests__r)
From Case c
where id = :ApexPages.currentPage().getParameters().get('id')];
Aid=request.Account.Name;
GRList = request.Grocery_Requests__r;

system.debug('@@@GRList=' + GRList);

for (Grocery_Request__c GR : GRList) {
gMap.get(GR.Grocery_Item__c).quantity = GR.Quantity__c.intValue();
gIdSet.add(GR.Grocery_Item__c);

pdfGSortMap.get(pdfIdxMap.get(GR.Grocery_Item__c)).quantity = GR.Quantity__c.intValue();
}


//if (Aid<>){
Account[] AL=[Select a.name,(select name, age__c,Client_Status__c from Account.Contacts where Client_Status__c <>'inactive' and Client_Status__c<>'deceased' Order by Age__c desc) from Account a where id=:request.Account.Name];
if (AL.size()>0){
ANAME=AL[0].name;
if (AL[0].Contacts.size()>0){
Alist=AL[0].Contacts;
}

}







//ctmplist=[Select name,(select name,age__c from Accounts.Contacts__r) from Account where id=:request.Account];
//if (ctmplist[0].Contacts__r.size() > 0){


//}

//AList=ctmplist[0].Contacts__r;
//}


//AList=[Select name, age__c from Contact where Account like '%001E000000RoF4sIAQ%'];




//VERSION 1: GET Contact INFO
// a = [Select a.Social_Security_Number__c, a.SC_Photo_ID__c, a.Name, a.Id, LG
// From Contact a
// where id = :request.ContactId
// limit 1];

}


//**************************
// GETTER AND SETTER METHODS
//**************************

//VERSION 1: GET CONTACT INFO
//public Contact getContact(){return a;} //LG
public Case getRequest(){return request;}
public List<wGrocery> getpdfGRItemList() {
List<wGrocery> pdfGRItemList = new List<wGrocery>();
for (Integer i = 0; i<pdfGSortMap.size(); i++) {
if (pdfGSortMap.get(i).quantity > 0) pdfGRItemList.add(pdfGSortMap.get(i));

}
return pdfGRItemList;
}

public List<Name> getAList() {
return AList;
}

public string getAName(){
return AName;
}

public List<wGrocery> getGList(){
List<wGrocery> displayGList = new List<wGrocery>();
for (Integer idx = 0; idx<gSortMap.size(); idx++) {
displayGList.add(gMap.get(gSortMap.get(idx)));
}
return displayGList;
}

public void setGList(List<wGrocery> GList){
for (wGrocery gr : GList) gMap.put(gr.GI.id,gr);
}

public pageReference save() {
List<Grocery_Request__c> insertGList = new List<Grocery_Request__c>();

for (Grocery_Request__c gr : GRList) gr.Quantity__c = GMap.get(gr.Grocery_Item__c).quantity;
if (GRList.size()>0) update GRList;

for (wGrocery wGr : GMap.values()) {
if (wGr.quantity > 0 && gIdSet.contains(wGr.GI.Id)== false) {
Grocery_Request__c gr = new Grocery_Request__c(Request__c=request.id,
Grocery_Item__c=wGr.GI.Id, Quantity__c=wGr.quantity);

insertGList.add(gr);
}
}

if (insertGList.size()>0) insert insertGList;


PageReference pRef = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
pRef.setRedirect(true);
return pRef;

}
//************
//PAGE METHODS
//************

public pageReference cancel() {

PageReference pRef = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
pRef.setRedirect(true);
return pRef;

}

public pageReference pdfPage() {

PageReference pRef = page.GroceryUpdatePDFPage;
pRef.getParameters().put('id',ApexPages.currentPage().getParameters().get('id'));
pRef.setRedirect(true);
return pRef;

}

//WRAPPER CLASS FOR GROCERY
public class wGrocery{
public Integer quantity {get; set;}
public Grocery_Item__c GI {get; set;}
public String highlight {get;set;}

public wGrocery(Grocery_Item__c GI){
quantity = 0;
this.GI = GI;
highlight=null;
}
}

//TEST METHOD
static testMethod void T1() {
//
Grocery_Request__c qGR = [Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantity__c
From Grocery_Request__c
where IsDeleted = false
and Grocery_Item__c != null
limit 1];

Case qRequest = [Select c.Id,
(Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantity__c
From Grocery_Requests__r)
From Case c
where id = :qGR.Request__c
limit 1];

//INITIALIZE PAGE AND STANDARD CONTROLLER
PageReference pageRef = Page.GroceryUpdatePage;
Test.setCurrentPageReference(pageRef);
ApexPages.currentPage().getParameters().put('id', qRequest.Id);

GroceryUpdate stdCon = new GroceryUpdate();

Case tgetRequest = stdCon.getRequest();
List<wGrocery> tgetGList = stdCon.getGList();
stdCon.setGList(tgetGList);
List<wGrocery> tgetpdfGItemList = stdCon.getpdfGRItemList();
pageReference tpref = stdCon.save();
tpref = stdCon.cancel();
tpref = stdCon.pdfPage();
// Account tA = stdCon.getAccount();
}
}

Andrew WilkinsonAndrew Wilkinson

Made some changes...try this...

public class GroceryUpdate{
//VERSION 1: SORT GROCERY LIST BY CATEGORY
// PDF: INCLUDE THE Contact/Account Name
// Account Members Ages
//VERSION 2: CHANGE QUANTITY TO INTEGER TO REMOVE DECIMAL POINT
//VERSION 3: GET TYPE OF FOOD ORDER and SHOPPING NOTES FROM REQUEST (CASE)

Case request;
//Name crequest;
List <Grocery_Request__c> GRList;
List <Contact> AList;
//List <Account> atmplist;
Account aMembers;
Set<Id> GItemIdSet = new Set<Id>();
Set<Id> gIdSet = new Set<Id>();
Map<Id,wGrocery> gMap = new Map<Id,wGrocery>();
Map<Integer,Id> gSortMap = new Map<Integer,Id>();
Map<Integer,wGrocery> pdfGSortMap = new Map<Integer,wGrocery>();
Map<Id,Integer> pdfIdxMap = new Map<Id,Integer>();
List<wGrocery> gList = new List<wGrocery>();
List<Grocery_Item__c> gItemList;
List<Grocery_Item__c> pdfGItemList;
String Aid;
String AName;
// Contact c; //LG

//****************
// CONSTRUCTOR
//****************

public GroceryUpdate() {
Integer idx = 0;
Alist = new List<Contact>();
//VERSION 1: SORT BY CATEGORY AFTER WAREHOUSE ORDER
pdfGItemList = [Select g.Warehouse_Order__c, g.Name, g.Id,
g.Grocery_Category__c, g.Available__c
From Grocery_Item__c g
order by Warehouse_Order__c, Grocery_Category__c, Name ASC nulls last
limit 1000];
for (Grocery_Item__c gi : pdfGItemList) {
pdfGSortMap.put(idx,new wGrocery(gi));
pdfIdxMap.put(gi.id,idx);
idx++;
}
system.debug('@@@pdfGSortMap=' + pdfGSortMap);
system.debug('@@@pdfIdxMap=' + pdfIdxMap);

//VERSION 1: SORT BY CATEGORY AFTER AVAILABLE
gItemList = [Select g.Warehouse_Order__c, g.Name, g.Id,
g.Grocery_Category__c, g.Available__c
From Grocery_Item__c g
order by Available__c, Grocery_Category__c, Name ASC nulls last
limit 1000];

idx = 0;
String s = null;
String oldHighlight = '#BDBDBD';

for (Grocery_Item__c gi : gItemList) {
gMap.put(gi.id,new wGrocery(gi));

if (gi.Grocery_Category__c != s ) {
s=gi.Grocery_Category__c;
if (oldHighlight == null) oldHighlight = '#BDBDBD';
else oldHighlight = null;
}

gMap.get(gi.id).highlight = oldHighlight;

if (gi.Available__c == true) {
gSortMap.put(idx,gi.id);
idx++;
}
}

for (Grocery_Item__c gi : gItemList) {
if (gi.Available__c == false) {
gSortMap.put(idx,gi.id);
idx++;
}
}

//VERSION 3: GET Type_of_Food_Order__c and Shopping_List_Notes__c

//request = [Select c.Id, c.Subject, c.Contact.Name, c.ContactId, c.CaseNumber,
// c.Type_of_Food_Order__c, c.Shopping_List_Notes__c,
// (Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantify__c
// From Grocery_Requests__r)
// From Case c
// where id = :ApexPages.currentPage().getParameters().get('id')];

//GRList = request.Grocery_Requests__r;
//system.debug('@@@GRList=' + GRList);
//for (Grocery_Request__c GR : GRList) {
// gMap.get(GR.Grocery_Item__c).quantity = GR.Quantify__c.intValue();
// gIdSet.add(GR.Grocery_Item__c);

// pdfGSortMap.get(pdfIdxMap.get(GR.Grocery_Item__c)).quantity = GR.Quantify__c.intValue();
//}

request = [Select c.Id,c.Account.Name, c.Subject, c.Contact.Name, c.ContactId, c.CaseNumber,
c.Type_of_Food_Order__c, c.Shopping_List_Notes__c,
(Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantity__c
From Grocery_Requests__r)
From Case c
where id = :ApexPages.currentPage().getParameters().get('id')];
Aid=request.Account.Name;
GRList = request.Grocery_Requests__r;

system.debug('@@@GRList=' + GRList);
for (Grocery_Request__c GR : GRList) {
gMap.get(GR.Grocery_Item__c).quantity = GR.Quantity__c.intValue();
gIdSet.add(GR.Grocery_Item__c);

pdfGSortMap.get(pdfIdxMap.get(GR.Grocery_Item__c)).quantity = GR.Quantity__c.intValue();
}


//if (Aid<>){
Account[] AL=[Select a.name,(select name, age__c,Client_Status__c from Account.Contacts where Client_Status__c <>'inactive' and Client_Status__c<>'deceased' Order by Age__c desc) from Account a where id=:request.Account.Name];
if (AL.size()>0){
ANAME=AL[0].name;
if (AL[0].Contacts.size()>0){
Alist=AL[0].Contacts;
}

}






//ctmplist=[Select name,(select name,age__c from Accounts.Contacts__r) from Account where id=:request.Account];
//if (ctmplist[0].Contacts__r.size() > 0){


//}

//AList=ctmplist[0].Contacts__r;
//}


//AList=[Select name, age__c from Contact where Account like '%001E000000RoF4sIAQ%'];




//VERSION 1: GET Contact INFO
// a = [Select a.Social_Security_Number__c, a.SC_Photo_ID__c, a.Name, a.Id, LG
// From Contact a
// where id = :request.ContactId
// limit 1];

}

//**************************
// GETTER AND SETTER METHODS
//**************************

//VERSION 1: GET CONTACT INFO
//public Contact getContact(){return a;} //LG
public Case getRequest(){return request;}
public List<wGrocery> getpdfGRItemList() {
List<wGrocery> pdfGRItemList = new List<wGrocery>();
for (Integer i = 0; i<pdfGSortMap.size(); i++) {
if (pdfGSortMap.get(i).quantity > 0) pdfGRItemList.add(pdfGSortMap.get(i));

}
return pdfGRItemList;
}

public List<Name> getAList() {
return AList;
}

public string getAName(){
return AName;
}

public List<wGrocery> getGList(){
List<wGrocery> displayGList = new List<wGrocery>();
for (Integer idx = 0; idx<gSortMap.size(); idx++) {
displayGList.add(gMap.get(gSortMap.get(idx)));
}
return displayGList;
}

public void setGList(List<wGrocery> GList){
for (wGrocery gr : GList) gMap.put(gr.GI.id,gr);
}

public pageReference save() {
List<Grocery_Request__c> insertGList = new List<Grocery_Request__c>();

for (Grocery_Request__c gr : GRList) gr.Quantity__c = GMap.get(gr.Grocery_Item__c).quantity;
if (GRList.size()>0) update GRList;

for (wGrocery wGr : GMap.values()) {
if (wGr.quantity > 0 && gIdSet.contains(wGr.GI.Id)== false) {
Grocery_Request__c gr = new Grocery_Request__c(Request__c=request.id,
Grocery_Item__c=wGr.GI.Id, Quantity__c=wGr.quantity);

insertGList.add(gr);
}
}

if (insertGList.size()>0) insert insertGList;


PageReference pRef = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
pRef.setRedirect(true);
return pRef;

}
//************
//PAGE METHODS
//************
public pageReference cancel() {

PageReference pRef = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
pRef.setRedirect(true);
return pRef;

}
public pageReference pdfPage() {

PageReference pRef = page.GroceryUpdatePDFPage;
pRef.getParameters().put('id',ApexPages.currentPage().getParameters().get('id'));
pRef.setRedirect(true);
return pRef;

}

//WRAPPER CLASS FOR GROCERY
public class wGrocery{
public Integer quantity {get; set;}
public Grocery_Item__c GI {get; set;}
public String highlight {get;set;}

public wGrocery(Grocery_Item__c GI){
quantity = 0;
this.GI = GI;
highlight=null;
}
}

//TEST METHOD
static testMethod void T1() {
//
Grocery_Request__c qGR = [Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantity__c
From Grocery_Request__c
where IsDeleted = false
and Grocery_Item__c != null
limit 1];

Case qRequest = [Select c.Id,
(Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantity__c
From Grocery_Requests__r)
From Case c
where id = :qGR.Request__c
limit 1];

//INITIALIZE PAGE AND STANDARD CONTROLLER
PageReference pageRef = Page.GroceryUpdatePage;
Test.setCurrentPageReference(pageRef);
ApexPages.currentPage().getParameters().put('id', qRequest.Id);

GroceryUpdate stdCon = new GroceryUpdate();

Case tgetRequest = stdCon.getRequest();
List<wGrocery> tgetGList = stdCon.getGList();
stdCon.setGList(tgetGList);
List<wGrocery> tgetpdfGItemList = stdCon.getpdfGRItemList();
pageReference tpref = stdCon.save();
tpref = stdCon.cancel();
tpref = stdCon.pdfPage();
// Account tA = stdCon.getAccount();
}
}

 

MikeCloudMikeCloud

Looks like that took, 

 

 

Error: Compile Error: Return value must be of type: LIST<Name> at line 174 column 1

 

 

//VERSION 1: GET CONTACT INFO
//public Contact getContact(){return a;} //LG
public Case getRequest(){return request;}
public List<wGrocery> getpdfGRItemList() {
List<wGrocery> pdfGRItemList = new List<wGrocery>();
for (Integer i = 0; i<pdfGSortMap.size(); i++) {
if (pdfGSortMap.get(i).quantity > 0) pdfGRItemList.add(pdfGSortMap.get(i));

}
return pdfGRItemList;
}

public List<Name> getAList() {
return AList;
}

Andrew WilkinsonAndrew Wilkinson

Try this

 

 

//VERSION 1: GET CONTACT INFO
//public Contact getContact(){return a;} //LG
public Case getRequest(){return request;}
public List<wGrocery> getpdfGRItemList() {
List<wGrocery> pdfGRItemList = new List<wGrocery>();
for (Integer i = 0; i<pdfGSortMap.size(); i++) {
if (pdfGSortMap.get(i).quantity > 0) pdfGRItemList.add(pdfGSortMap.get(i));

}
return pdfGRItemList;
}

public List<Contact> getAList() {
return AList;
}

MikeCloudMikeCloud

It saved, but PDF did not work, its the same?

 

 

<apex:page controller="GroceryUpdate" renderAs="pdf">
<style>
</style>

   <apex:outputText value="Grocery List for Household: {!AName}" style="font-weight:bold;"/>
   <br/>
   <br/>
   <apex:outputText value="Request Number: {!request.CaseNumber}" style="font-weight:bold;"/>
   <br/>
   <apex:outputText value="Type of Food Order: {!request.Type_of_Food_Order__c}" style="font-weight:bold;"/>
   <br/>
   <br/>
    <apex:pageBlock >
    <apex:pageBlockSection >
    <apex:pageBlockTable value="{!AList}" var="A" border="1">
        <apex:column value="{!A.Name}" headerValue="Client Name" style="width:300px;white-space:nowrap;"/>
        <apex:column value="{!A.Age__c}" headerValue="Age" style="width:50px;white-space:nowrap;"/>
            </apex:pageBlockTable>
    </apex:pageBlockSection>
    </apex:pageBlock>
   <br/>
   <apex:outputText value="Shopping List Notes: {!request.Shopping_List_Notes__c}" style="font-weight:bold;"/>
   <br/>
   <br/>

    <apex:pageBlock >
        <apex:pageBlockTable value="{!pdfGRItemList}" var="gl" id="pb" border="1">      

            <apex:column value="{!gl.GI.Name}" headerValue="Name" style="width:100px;white-space:nowrap;"/>

            <apex:column value="{!gl.quantity}" headerValue="Quantity" style="width:100px;"/>

            <apex:column value="{!gl.GI.Available__c}" headerValue="Available" style="width:100px;white-space:nowrap;"/>
                    
            <apex:column value="{!gl.GI.Warehouse_Order__c}" headerValue="Warehouse Order" style="width:100px;"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
Andrew WilkinsonAndrew Wilkinson

By pdf did not work are you saying there is no data?

 

If so, it could be many reasons...the queries aren't working correctly...or the account does not have any records associated to it...or other things.

MikeCloudMikeCloud

The list populates the groceries request number show up, shopping list notes will show up, but Household (Account) Name will not showup, the Clients (Contacts) related to that "Household" & their Ages fro Age__c on contact will not show up, it used to?

Andrew WilkinsonAndrew Wilkinson

All of that is populated from the query that was the initial issue. Is there a custom Contact lookup for an Account? Go to the Contact Fields look for a lookup to Account that isn't a standard field. If there is one, click on it and the relationship name will be on that page.

MikeCloudMikeCloud

No, the standard Account lookup filed on contact and standard lookup contact field on account (renamed Households).  The object is case (renamed request).  Standard lookups for both used on Case object no other custom lookups, the age__c is on the Contact object (renamed Clients).  The Class refers to Pages to create a grocery list that works great, once that saved you hit the pring grocery list button, the PDF comes up with the proper Grocery Lists, has the auto Case (Request) Number, The Shopping_List_Notes__c will show up, but The "Household" (Account) name is blank,  Clients (Contacts) related to Account is blank & their Age__c  (Ages) is blank, so the back warehouse who gets the PDF print out has no name, how many in house hold and their ages? 

MikeCloudMikeCloud

When I run test I get query error line 254 - everthing works except Account Name, Contact Names & their ages will not show up on pdf.  

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
public class GroceryUpdate{
//VERSION 1: SORT GROCERY LIST BY CATEGORY
// PDF: INCLUDE THE Contact/Account Name,Client SC Photo ID,Client SSN
//Household Memebers Age 0 to 17 (calculated field from contact object)
//Household Members Age 18 to 59
//Household Members Age 60 Plus
//VERSION 2: CHANGE QUANTITY TO INTEGER TO REMOVE DECIMAL POINT
//VERSION 3: GET TYPE OF FOOD ORDER and SHOPPING NOTES FROM REQUEST (CASE)

 Case request;
 //Account crequest;
 List <Grocery_Request__c> GRList;
 List <Contact> AList;
 //List <Account> ctmplist;
 Contact AMembers;
 Set<Id> GItemIdSet = new Set<Id>();
 Set<Id> gIdSet = new Set<Id>();
 Map<Id,wGrocery> gMap = new Map<Id,wGrocery>();
 Map<Integer,Id> gSortMap = new Map<Integer,Id>();
 Map<Integer,wGrocery> pdfGSortMap = new Map<Integer,wGrocery>();
 Map<Id,Integer> pdfIdxMap = new Map<Id,Integer>();
 List<wGrocery> gList = new List<wGrocery>();
 List<Grocery_Item__c> gItemList;
 List<Grocery_Item__c> pdfGItemList;
 String Aid;
 String AName;
 // Contact cn; //LG

//****************
// CONSTRUCTOR
//****************

 public GroceryUpdate() {
  Integer idx = 0;

  //VERSION 1: SORT BY CATEGORY AFTER WAREHOUSE ORDER
  pdfGItemList = [Select g.Warehouse_Order__c, g.Name, g.Id,
  g.Grocery_Category__c, g.Available__c
  From Grocery_Item__c g
  order by Warehouse_Order__c, Grocery_Category__c, Name ASC nulls last
  limit 1000];

 for (Grocery_Item__c gi : pdfGItemList) {
  pdfGSortMap.put(idx,new wGrocery(gi));
  pdfIdxMap.put(gi.id,idx);
  idx++;
 }
 system.debug('@@@pdfGSortMap=' + pdfGSortMap);
 system.debug('@@@pdfIdxMap=' + pdfIdxMap);

 //VERSION 1: SORT BY CATEGORY AFTER AVAILABLE
 gItemList = [Select g.Warehouse_Order__c, g.Name, g.Id,
  g.Grocery_Category__c, g.Available__c
  From Grocery_Item__c g
  order by Available__c, Grocery_Category__c, Name ASC nulls last
  limit 1000];

 idx = 0;
 String s = null;
 String oldHighlight = '#BDBDBD';

 for (Grocery_Item__c gi : gItemList) {
  gMap.put(gi.id,new wGrocery(gi));

 if (gi.Grocery_Category__c != s ) {
  s=gi.Grocery_Category__c;
  if (oldHighlight == null) oldHighlight = '#BDBDBD';
  else oldHighlight = null;
 }

 gMap.get(gi.id).highlight = oldHighlight;

 if (gi.Available__c == true) {
  gSortMap.put(idx,gi.id);
  idx++;
 }
}

for (Grocery_Item__c gi : gItemList) {
 if (gi.Available__c == false) {
  gSortMap.put(idx,gi.id);
  idx++;
 }
}

 //VERSION 3: GET Type_of_Food_Order__c and Shopping_List_Notes__c

 //request = [Select c.Id, c.Subject, c.Contact.Name, c.ContactId, c.CaseNumber,
 // c.Type_of_Food_Order__c, c.Shopping_List_Notes__c,
 // (Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantify__c
 // From Grocery_Requests__r)
 // From Case c
 // where id = :ApexPages.currentPage().getParameters().get('id')];

 //GRList = request.Grocery_Requests__r;
 //system.debug('@@@GRList=' + GRList);

 //for (Grocery_Request__c GR : GRList) {
 // gMap.get(GR.Grocery_Item__c).quantity = GR.Quantify__c.intValue();
 // gIdSet.add(GR.Grocery_Item__c);

 // pdfGSortMap.get(pdfIdxMap.get(GR.Grocery_Item__c)).quantity = GR.Quantify__c.intValue();
 //}

 request = [Select c.Id,c.Account.Name, c.Subject, c.Contact.Name, c.ContactId, c.CaseNumber,
  c.Type_of_Food_Order__c, c.Shopping_List_Notes__c,
  (Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantity__c
   From Grocery_Requests__r)
 From Case c
 where id = :ApexPages.currentPage().getParameters().get('id')];
 Aid=request.Account.Name;
 GRList = request.Grocery_Requests__r;

 system.debug('@@@GRList=' + GRList);

 for (Grocery_Request__c GR : GRList) {
  gMap.get(GR.Grocery_Item__c).quantity = GR.Quantity__c.intValue();
  gIdSet.add(GR.Grocery_Item__c);

 pdfGSortMap.get(pdfIdxMap.get(GR.Grocery_Item__c)).quantity = GR.Quantity__c.intValue();
}


//if (Aid<>){
 Account[] AL=[Select a.name,(select name, age__c,Client_Status__c from Account.Contacts where Client_Status__c <>'inactive' and Client_Status__c<>'deceased' Order by Age__c desc) from Account a where id=:request.Account.Name];
 if (AL.size()>0){
  ANAME=AL[0].name;
  if (AL[0].Contacts.size()>0){
   Alist=AL[0].Contacts;
 }

}


  //ctmplist=[Select name,(select name,age__c from Accounts.Contacts__r) from Account where id=:request.Account];
  //if (ctmplist[0].Contacts__r.size() > 0){


  //}

  //AList=ctmplist[0].Contacts__r;
 //}


 //AList=[Select name, age__c from Contact where Account like '%001E000000QduYPIAQ%'];




 //VERSION 1: GET Contact INFO
 // cn = [Select cn.Social_Security_Number__c, cn.SC_Photo_ID__c, cn.Name, cn.Id, LG
 // From Contact cn
 // where id = :request.ContactId
 // limit 1];

 }

//**************************
// GETTER AND SETTER METHODS
//**************************

 //VERSION 1: GET CONTACT INFO
 //public Contact getContact(){return cn;} //LG
 public Case getRequest(){return request;}
 public List<wGrocery> getpdfGRItemList() {
  List<wGrocery> pdfGRItemList = new List<wGrocery>();
  for (Integer i = 0; i<pdfGSortMap.size(); i++) {
   if (pdfGSortMap.get(i).quantity > 0) pdfGRItemList.add(pdfGSortMap.get(i));

 }
 return pdfGRItemList;
}

 public List<Contact> getAList() {
  return AList;
}

 public string getAName(){
  return AName;
}

 public List<wGrocery> getGList(){
  List<wGrocery> displayGList = new List<wGrocery>();
  for (Integer idx = 0; idx<gSortMap.size(); idx++) {
   displayGList.add(gMap.get(gSortMap.get(idx)));
  }
  return displayGList;
 }

 public void setGList(List<wGrocery> GList){
  for (wGrocery gr : GList) gMap.put(gr.GI.id,gr);
 }

 public pageReference save() {
  List<Grocery_Request__c> insertGList = new List<Grocery_Request__c>();

 for (Grocery_Request__c gr : GRList) gr.Quantity__c = GMap.get(gr.Grocery_Item__c).quantity;
 if (GRList.size()>0) update GRList;

 for (wGrocery wGr : GMap.values()) {
  if (wGr.quantity > 0 && gIdSet.contains(wGr.GI.Id)== false) {
   Grocery_Request__c gr = new Grocery_Request__c(Request__c=request.id,
    Grocery_Item__c=wGr.GI.Id, Quantity__c=wGr.quantity);

   insertGList.add(gr);
  }
 }

 if (insertGList.size()>0) insert insertGList;


 PageReference pRef = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
 pRef.setRedirect(true);
 return pRef;

 }
//************
//PAGE METHODS
//************

  public pageReference cancel() {

   PageReference pRef = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
   pRef.setRedirect(true);
   return pRef;

 }
 
 public pageReference pdfPage() {

  PageReference pRef = page.GroceryUpdatePDFPage;
  pRef.getParameters().put('id',ApexPages.currentPage().getParameters().get('id'));
  pRef.setRedirect(true);
  return pRef;

 }

 //WRAPPER CLASS FOR GROCERY
 public class wGrocery{
  public Integer quantity {get; set;}
  public Grocery_Item__c GI {get; set;}
  public String highlight {get;set;}

  public wGrocery(Grocery_Item__c GI){
   quantity = 0;
   this.GI = GI;
   highlight=null;
  }
 }

 //TEST METHOD
 static testMethod void T1() {
  //
  Grocery_Request__c qGR = [Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantity__c
   From Grocery_Request__c
   where IsDeleted = false
   and Grocery_Item__c != null
   limit 1];

 Case qRequest = [Select c.Id,
  (Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantity__c
  From Grocery_Requests__r)
 From Case c
 where id = :qGR.Request__c
 limit 1];

 //INITIALIZE PAGE AND STANDARD CONTROLLER
 PageReference pageRef = Page.GroceryUpdatePage;
 Test.setCurrentPageReference(pageRef);
 ApexPages.currentPage().getParameters().put('id', qRequest.Id);

 GroceryUpdate stdCon = new GroceryUpdate();

 Case tgetRequest = stdCon.getRequest();
 List<wGrocery> tgetGList = stdCon.getGList();
 stdCon.setGList(tgetGList);
 List<wGrocery> tgetpdfGItemList = stdCon.getpdfGRItemList();
 pageReference tpref = stdCon.save();
 tpref = stdCon.cancel();
 tpref = stdCon.pdfPage();
 // Contact tCN = stdCon.getContact();
 }
}