function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Everton CP7Everton CP7 

How I add the buttons on a related list

Hi there,

 

I put the related list in my VF page.

The related list appears to me, but the button to attach the files don't.

 

<apex:relatedlist list="Attachments"/>

 

How I add the button?

 

I tried add the button, without the related list:

<apex:commandbutton value="Anexar arquivo" onclick="window.open('/p/attach/ActivityAttach?relatedListId={!task.Id}_RelatedActivityAttachmentList&retURL=%2F{!task.Id}%2Fe%3Fclose%3D1%26retURL%3D%252F500U0000001q9ik&pid={!task.Id}&type=00T')" /> 

With this code I open a window to attach the file.
But when I finished the process to attach the file. The file don't get attached into the task.

Best Answer chosen by Admin (Salesforce Developers) 
Everton CP7Everton CP7

I read some topics and finally I get it.

 

Code:

 

<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}"/>

 

 

Code:

 

private final Task tsk; 
   
   public Attachment attachment {get;set;}
   
   public PageReference save() {
     attachment.parentid = tsk.id;
     insert attachment;
     return stdController.save();
   }
 
 public Anexos(ApexPages.StandardController stdController)
 { 
  attachment = new Attachment();
  this.tsk = (Task)stdController.getRecord(); 
  this.stdController = stdController;
 } 
 
 ApexPages.StandardController stdController;
}

 You have to save the record.

And you open the record again, the file you be in the related list "Attachments".

All Answers

Rahul_sgRahul_sg
Go to the STD page layout for the object and add the new button for that related list.. eg. if you are creating detail VF page for Contact and want to add this related list then go and Edit contact layout and add the New button (select checkbox) for Attachment
Everton CP7Everton CP7

I'll get you a better explanation.

 

I'm not creating a detail VF page.
I'm creating a VF page on tasks. I'll never use anymore the standard layout.

 

Even if I go to the layout page in tasks. I can't add buttons to "Related List Attachments".
"This list can't be customized."

 

When I enter in a task with standard layout.
I still can't see the button. The button just appears when I click in "Edit".

Rahul_sgRahul_sg

How about using apex:inputFile

 

<!-- Upload a file and put it in your personal documents folder-->
                        

<!-- Page: -->
<apex:page standardController="Document" extensions="documentExt"> <apex:messages /> <apex:form id="theForm"> <apex:pageBlock> <apex:pageBlockSection> <apex:inputFile value="{!document.body}" filename="{!document.name}"/> <apex:commandButton value="Save" action="{!save}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page> /*** Controller ***/
public class documentExt { public documentExt(ApexPages.StandardController controller) { Document d = (Document) controller.getRecord(); d.folderid = UserInfo.getUserId(); //this puts it in My Personal Documents } }
Everton CP7Everton CP7

Thanks Rahul, I don't know how appreciate your help.

 

I have already tried this one.

The problem here is the file will be attached in "Documents" and I need the file in my task, or in the case (the tasks will always be related to a case).

Everton CP7Everton CP7

I don't know how I adapt this code to a task.

You know how?

 

 

I tried this :

 

<apex:page standardController="case">
        <apex:relatedList list="Attachments" />
</apex:page>

 

And in my VF, I used :

 

<apex:include pageName="AnexoCaso"/>

 

Obviously didn't work, cause the first one is related to "case" and my VF is related to "task".

Everton CP7Everton CP7

I read some topics and finally I get it.

 

Code:

 

<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}"/>

 

 

Code:

 

private final Task tsk; 
   
   public Attachment attachment {get;set;}
   
   public PageReference save() {
     attachment.parentid = tsk.id;
     insert attachment;
     return stdController.save();
   }
 
 public Anexos(ApexPages.StandardController stdController)
 { 
  attachment = new Attachment();
  this.tsk = (Task)stdController.getRecord(); 
  this.stdController = stdController;
 } 
 
 ApexPages.StandardController stdController;
}

 You have to save the record.

And you open the record again, the file you be in the related list "Attachments".

This was selected as the best answer