2

Trying to show the content field (blob) from contentNote in Visualforce. All that shows is "core.filemanager.ByteBlobValue@225c5e8c". I realize that I must somehow change the blob to text, but I cannot figure it out.

Here is my class:

    public list<ContentNote> getConNote() {
    String cdlId;
    List<ContentDocumentLink> cid = [Select ContentDocumentId From ContentDocumentLink Where LinkedEntityId = :RelatedTo];
    for(ContentDocumentLink c: cid){
        cdlId = c.ContentDocumentId;
    }
    return [Select Title, Content 
            From ContentNote
            Where Id = :cdlId];

        }

And here is the section of my vf page:

            <apex:dataTable value="{!ConNote}" var="cn" styleClass="slds-table slds-table--bordered slds-table--striped" >
            <apex:column width="200">
                <apex:outputText value="{!cn.Content}" styleClass="slds-cell-wrap"/>
                <apex:facet name="header"> Notes</apex:facet>
            </apex:column>
            </apex:dataTable><br /><br />

UPDATE:: Here is what I did, just in case it can help someone else. Class:

    public static String getContent() {
    String RelatedTo = ApexPages.currentPage().getParameters().get('id');
    String cid;
    Blob myBlob;
    String s;

    List<ContentDocumentLink> cdlId = [Select ContentDocumentId From ContentDocumentLink Where LinkedEntityId = :RelatedTo]; {
        for(ContentDocumentLink c: cdlId)
            cid = c.ContentDocumentId;
        List<ContentNote> cids = [Select Title, Content From ContentNote Where id = :cid]; {
            for(ContentNote cn: cids)
                myBlob = cn.Content;
                s = EncodingUtil.base64Decode(EncodingUtil.base64Encode(myBlob)).toString().replace('<br>', '\r\n'));

        } 
    }
    return s;
}

VF:

        <apex:dataTable value="{!Content}" var="s" styleClass="slds-table slds-table--bordered slds-table--striped" >
            <apex:column width="200">
                <apex:outputText value="{!s}" styleClass="slds-cell-wrap"/>
                <apex:facet name="header"> Subject</apex:facet>
            </apex:column>
            </apex:dataTable><br /><br />

1 Answer 1

3

There are two ways to convert a Blob to a string in Apex. Depending on how the Blob was created, you'll use one or the other:

blobVar.toString();
encodingUtil.base64encode(blobVar);

For content, you should use the base64encode method. This means you'll need to create additional properties or variables in your Apex class, as you wont be able to do this on the sObject itself.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .