SF:salesforce中,文件上传的接收对象

  1. 关于<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状态。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章