+ Start a Discussion
davecrusodavecruso 

Querying against Attachment -- but outer query not working?

Hi all, 

 

We're trying to generate a listing of attachments for a specific item (apprenticeship), but are having no luck with the outer query. The inner query (against Attachment) works. Any thoughts / suggestions? Thanks!  Here's our code:

 

 

   private List<Attachment> attachmentList;   

    public List<Attachment> getAttachments() {

           

      PageReference pageRef = System.currentPageReference();

        apprenticeshipID = pageRef.getParameters().get('id');

        

        for (Lesson_Plan_Attachments__c u: [select id,Apprenticeship__c from Lesson_Plan_Attachments__c where Lesson_Plan_Attachments__c.Apprenticeship__c = :apprenticeshipID limit 1]) 

        {

attachmentList = [select id from Attachment where parentid = :u.id ];

    }

    return attachmentList;

}

 

 

 

Message Edited by davecruso on 01-22-2010 12:39 PM
davecrusodavecruso

We're all getting errors like this: 

 

ApprenticeshipFileExtension : Invalid conversion from runtime type SOBJECT:Apprenticeship__c to SOBJECT:Lesson_Plan_Attachments__c

 

... any insight into what's causing this, and how to rectify? 

davecrusodavecruso

Anyone??  Even the inner query isn't working with this code: 

 

 

public class ApprenticeshipFileExtension {

 

// RELATED RESOURCES

//

// relation to an object - http://community.salesforce.com/sforce/board/message?board.id=PerlDevelopment&message.id=4168

//

   private final Lesson_Plan_Attachments__c ApprenticeshipRef; 

 

   public Attachment attachment {get;set;}

   public string apprenticeshipID;

   public string ctContactId;

   public string urlstring;

   public string url; 

   public string fileId;

 

   ApexPages.StandardController stdController;   

   public ApprenticeshipFileExtension(ApexPages.StandardController stdController)

 

  attachment = new Attachment();

  this.ApprenticeshipRef = (Lesson_Plan_Attachments__c)stdController.getRecord(); 

  this.stdController = stdController;

 

   

    private List<Attachment> attachmentList; 

    public List<Attachment> getAttachments() {

       // String  apprenticeshipID = 'a0G40000003LVz0'; 

      PageReference pageRef = System.currentPageReference();

        apprenticeshipID = pageRef.getParameters().get('id');

     for (Lesson_Plan_Attachments__c u : [select id,Apprenticeship__c from Lesson_Plan_Attachments__c where Lesson_Plan_Attachments__c.Apprenticeship__c = :apprenticeshipID limit 1])

{

      attachmentList = [select id,name,lastmodifieddate from Attachment where parentid = :u.id ];

     }

     return attachmentList;

}


} 

 -- gives the same error message. 

 

Message Edited by davecruso on 01-25-2010 10:03 AM