2

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:

Sfdc.ChatterNotes.createNote(); 

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

1 Answer 1

1

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'; insert(cn); ContentDocumentLink link = new ContentDocumentLink(); link.ContentDocumentId = cn.Id; link.LinkedEntityId = ***myCustomObjectId***; link.ShareType = 'I'; insert(link); 

Et voilà!

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.