You need to sign in to do that
Don't have an account?
Brandon Nelson 9
Visualforce page to show attachments
I'm having an issue trying to show ID, NAME, and URL of attachment based on who uploaded it. Problem is the code is showing results even without an attachment.... Can someone please look at my code and help me understand why?
Again, I need the page to show Attachment NAME, ID, Client NAME, ID and URL to attachment.
APEX CLASS
VISUALFORCE PAGE
Again, I need the page to show Attachment NAME, ID, Client NAME, ID and URL to attachment.
APEX CLASS
public with sharing class DisplayAttachments{ public List<Account> Records {get; set;} public DisplayAttachments(){ String userId = userinfo.getUserId(); Records = [select Id,Name,(Select Id,Name from Attachments) From Account Where CreatedById =:userId]; } }
VISUALFORCE PAGE
<apex:page controller="DisplayAttachments" > <apex:pageBlock title="{!$User.FirstName} {!$User.LastName}'s Attahments"> <apex:pageBlockTable value="{!Records}" var="Record"> <apex:column > <apex:facet name="header">Client ID</apex:facet> <apex:outputText value="{!Record.Id}"/> </apex:column> <apex:column > <apex:facet name="header">Client Name</apex:facet> <apex:outputText value="{!Record.Name}"/> </apex:column> <apex:column > <apex:facet name="header">Attachment ID</apex:facet> <apex:pageBlockTable value="{!Record.Attachments}" var="a"> <apex:column > <apex:outputField value="{!a.Id}"/> </apex:column> </apex:pageBlockTable> </apex:column> <apex:column > <apex:facet name="header">Attachment Name</apex:facet> <apex:pageBlockTable value="{!Record.Attachments}" var="a"> <apex:column > <apex:outputField value="{!a.Name}"/> </apex:column> </apex:pageBlockTable> </apex:column>--> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
Hope You Doing good. As i can see in Your code You are trying to query from account to attachments thats why its showing all the account and its related attachments but if You try from attachment to account u will be good to go. here is some piece of code which will give u some idea
Although My query will include all the objects not just account so to solve this u can add in the query
Thanks
Tarun Suri
(Salesforce Developer)
Sorry for the noob question, but where would I put the Parentid.startsWith('001')? I'm an Admin and trying to learn as much as I can, but this has me lost.....
att = [select id, Name , parentId, parent.name fromAttachment Where CreatedById=:userId and Parentid.startsWith('001')];