[英]How to download all attachments of all records of a custom object in Salesforce?
[英]Salesforce custom object and attachments
好的,我的任務是創建一個自定義的 salesforce 對象來保存一些數據。 這是容易的部分。
我正在努力的地方是添加一個片段來上傳與在自定義對象中創建的記錄相關聯的文件。
自定義對象本質上是一個帶有字段的表單。 但我也需要上傳相關文件。
所以我構建了自定義對象的表單部分。 我為“上傳”部分使用了 Apex 類和 VisualForce 頁面。
不幸的是,在測試過程中,我在 VisualForce/Apex 部分不斷出現錯誤。
我得到的錯誤如下:
父級:父級 ID:類型錯誤的 id 值:00590000000yBOmAAM
我的 Apex 類看起來像這樣:
public with sharing class FileToDocument {
public Attachment attachment{
get{
if(attachment == null)
attachment = new Attachment();
return attachment;
}
set;
}
public PageReference upload(){
attachment.OwnerId = UserInfo.getUserId();
attachment.ParentId = '00590000000yBOm';
attachment.IsPrivate = false;
try{
insert attachment;
}
catch(DMLException e){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Error Uploading Attachment'));
return null;
}
finally{
attachment = new Attachment();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'Attachment Uploaded Successfully'));
return null;
}
}
我是 SalesForce 的新手。 我認為問題是 ParentID 行,但我不知道如何解決它。
我正在嘗試做的是能夠在我填寫記錄表格的同時將文檔上傳/附加到記錄中。
我的 VisualForce 看起來像這樣:
<apex:page controller="FileToDocument">
<apex:form enctype="multipart/form-data">
<apex:pageMessages />
<apex:pageblock >
<apex:pageBlockButtons >
<apex:commandButton action="{!upload}" value="Attach"/>
</apex:pageBlockButtons>
<apex:pageBlockSection showHeader="false" columns="2" id="block1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="File Name" for="fileName"/>
<apex:inputText value="{!attachment.name}" id="fileName"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="File" for="file"/>
<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
那么我可能做錯了什么? 我的另一個想法是,在創建記錄之前根本無法上傳適當的文件。 即便如此,我想我仍然需要知道如何將它與父 ID 相關聯。
一如既往,非常感謝任何幫助。
這不再相關。 該項目被重新分配給不同的組。
任何登陸這里的人檢查鏈接到教程
干杯
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.