好的,我的任务是创建一个自定义的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相关联。
一如既往,非常感谢任何帮助。