關於<apex:inputfile>組件上傳文件:
a.用Document對象來接:
*需要爲document指定一個folderId
Page:
<apex:page controller="PersonalUploadFileController">
<apex:apexMessages />
<apex:form >
<apex:pageBlock >
<apex:inputFile value="{!document.body}" fileName="{!document.name}" />
<apex:commandButton value="Upload" action="{!upload}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class PersonalUploadFileController{
private Document document = new Document();
public Document getDocument(){
return document;
}
public void setDocument(Document document){
this.document = document;
}
public PersonalUploadFileController(){
//Document document = new Document();
}
public void upload(){
System.debug('name:' + document.name);
document.folderId = UserInfo.getUserId();
try{
insert document;
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.INFO, 'Upload Success!'));
}catch(Exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.INFO, 'Upload Fail!'));
System.debug(e);
}
}
}
b.用Attachment對象來接:
*需要爲attach指定一個parentId
Page:
<apex:page controller="PersonalAttachmentController">
<apex:form >
<apex:pageBlock >
<apex:inputFile value="{!attach.Body}" fileName="{!attach.Name}" />
<apex:commandButton value="attach" action="{!attach}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class PersonalAttachmentController{
private Attachment attach = new Attachment();
public Attachment getAttach(){
return attach;
}
public void setAttach(Attachment attach){
this.attach = attach;
}
public PersonalAttachmentController(){
}
public void attach(){
System.debug(attach.Name);
try{
insert attach;
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.INFO, 'Upload Success!'));
}catch(Exception e){
System.debug(e);
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.INFO, 'Upload Fail!'));
}
}
}
c.用content對象來接:
<apex:page>
<apex:pageBlock>
<apex:inputFile fileName="{!content.PathOnClient}" value="{!content.VersionDat a}"/> <apex:commandButton value="upload" action="{!upload}"/>
</apex:pageBlock>
</apex:page>
*content<===>ContentVersion
此對象可以手動創建,VersionData字段,必須指定。PathOnClient字段跟另外一字段二選一指定。
ContentWorkspace 與 ContentWorkspaceDoc
father son
子類中查父類:
Select Id, IsOwner, CreatedDate, ContentWorkspace.Id, ContentWorkspace.Name From ContentWorkspaceDoc
父類中查子類:
不支持。
ContentDocument 與 ContentWorkspaceDoc
father son
子類中查父類:
Select Id, IsOwner, CreatedDate, ContentDocumentId, ContentDocument.Title From ContentWorkspaceDoc
父類中查子類:
不支持
ContentDocument 與 ContentVersion
father son
子類中查父類:
Select Id, VersionNumber, Title, Description, FileType, ContentSize, IsLatest From ContentVersion
父類中查子類:
Select Id, Title, (Select VersionNumber, Title, Description From ContentVersions) From ContentDocument c
Opportunity 與 ContentVersion
father son
子類中查父類
Select VersionNumber, Title, Description, ReasonForChange, OwnerId, TagCsv, FileType, ContentSize, Opportunity__r.Name From ContentVersion
父類中查子類
Select o.Name, (Select VersionNumber, Title, Description, ReasonForChange, OwnerId, TagCsv, FileType, ContentSize From Content__r) From Opportunity o
ContentWorkspace:
Select c.TagModel, c.SystemModstamp, c.Name, c.LastModifiedDate, c.LastModifiedById, c.IsRestrictLinkedContentTypes, c.IsRestrictContentTypes, c.Id, c.Description, c.DefaultRecordTypeId, c.CreatedDate, c.CreatedById From ContentWorkspace c
創建ContentWorkspaceDoc對象時(爲當前content指定存放library.),需要ContentDocumentId, ContentDocumentId兩個Required Fields.
ContentWorkspaceDoc contentDoc = new ContentWorkspaceDoc();
contentDoc.ContentDocumentId = '06990000000nwlKAAQ';
contentDoc.ContentDocumentId = '05890000000ctNxAAI';
insert contentDoc;
在一個新的環境中,用content等對象:Set up ==> Build ==> Customize ==> Salesforce CRM Content ==> Settings,先設置。再在User對象中的Receive Salesforce CRM Content Email Alerts, Receive Salesforce CRM Content Alerts as Daily Diges三個複選框,設置爲true狀態。