I'm trying to have a button in my VFP that'll add a Note (AttachedContentNote) to my custom object.

I want my button to do the same as the New Note button from the Note's relatedList in my custom object Salesforce default page. (I'm not talking about notes and attachment) This New Note button

This button is using this code onclick:


I've included these js files (Don't even know if I do it right??? Is there a best practise on this?):

<script src="/EXT/ext-3.0.0/ext-core.js"/>
<script src="/jslibrary/1487809120000/sfdc/Chatter.js"/>
<script defer="true" src="/jslibrary/1487809120000/sfdc/ChatterDefer.js"/>

When I click on my button that calls the Sfdc...createNote(). I get a popup that says: "The action you performed was invalid for your session. Please refresh your page and try again." Alert message


Ok I got it! Instead of trying to do it client-side in javascript. I do it server-side in Apex like that:

ContentNote cn = new ContentNote();
cn.title = 'Untitled Note';

ContentDocumentLink link = new ContentDocumentLink();
link.ContentDocumentId = cn.Id;
link.LinkedEntityId = ***myCustomObjectId***;
link.ShareType = 'I'; 

Et voilà!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.