2

I have a visualforce page that will display the attachments from A custom Object based on the Current logged in Portal user AccountID and ContactID.

The custom object is Child(LookUp Rel) of Account object.

I am getting the Attachments list in a debug logs but the list is not rendered in PageBlockTable

Any one have look a into my issue.

public with sharing class ViewServiceDocs_cntrlr 
{

public User currentUser                                             {get; set;}
public Contact currentContact                                       {get; set;}        
public Account currentAccount                                       {get; set;}      
Public List<Attachment> Attach{get;set;}

Public ViewServiceDocs_cntrlr()
{


currentUser = [select id,name,IsPortalEnabled,AccountId,ContactId from user where IsPortalEnabled=true and ID=:UserInfo.getUserId()]; 



 currentContact = [select Id, LastName, Name, AccountId from Contact where Id =: currentUser.ContactId]; 
 currentAccount = [select Id, Name, RecordType.name from Account where Id =: currentContact.AccountId]; 


 if(currentAccount.RecordType.name=='Generator')
 {


 List<Attachment> Attach = new list<Attachment>();
 Attach = [SELECT Id,Name,ContentType,Description,OwnerId,ParentId FROM Attachment where parentId in 
 (select id from Manifest__c where Generator_Old__r.ID=:currentAccount.ID)];
   system.debug('-----------Attach------------'+Attach);
 }

 else If(currentAccount.RecordType.name=='Customer')
 {

  Map<ID,Account> ParentAcc = new map<ID,Account>([SELECT Id,name FROM Account where parentId =:currentAccount.id]);
  system.debug('-----ParentAcc------------------------>'+ParentAcc);
  system.debug('-----ParentAcc Key----------------->'+ParentAcc.Keyset());


List<Attachment> Attach = [SELECT Id,Name,OwnerId,ParentId FROM Attachment where parentId in 
(select id from Manifest__c where Generator_Old__r.ID in:ParentAcc.keySet())];

system.debug('------------------------Attach--'+Attach);
 }

}
} 

Page Below

<apex:page controller="ViewServiceDocs_cntrlr" showHeader="true" >

 <apex:pageblock id="account" title="Hello {!$User.FirstName}..!" tabStyle="SVMXC__Service_Order__c">
 <apex:pageBlockSection title="Documents" columns="1" collapsible="false">
            <apex:pageblockTable value="{!Attach}" var="a">
<!-- <apex:column headerValue="Download">
<apex:outputLink value="{!URLFOR($Action.Document.Download, a.Id)}" 
target="_blank"> View </apex:outputLink> 
            <apex:column /> --->
           <apex:column value="{!a.Name}" headerValue="File Name"/>
           <apex:column value="{!a.ContentType}" headerValue="ContentType"/>
           <apex:column value="{!a.Description}" headerValue="Description"/>
           <apex:column value="{!a.OwnerId}" headerValue="OwnerId"/>
            </apex:pageblockTable>
            </apex:pageBlockSection>
  </apex:pageblock>



</apex:page>

Below are Screen shot of my response Page and Dubug logs

Debug Logs

Required Attachment

Pageblock Table nill

1 Answer 1

2

You are declaring local variables called Attach that are hiding (taking precedence over) the Attach field that the Visualforce is tied to.

So instead of:

List<Attachment> Attach = new list<Attachment>();

use:

Attach = new list<Attachment>();
1
  • Wow! @Keith C Thanks for the reply Here esp. in coding smaller mistakes will result in a bigger changes
    – SFDC_Igle
    Commented Jul 3, 2015 at 18:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .