function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anju Chacko QBAnju Chacko QB 

Get last Contract Note in a trigger (Content Note)

HI,

I am just trying to get last added / updated note (Content Note) on a contract.
I tried triger on Content Note(not supported), ContractFeed (Not supported), Content Version (Parent id is not present), Feed item (Content is not present)

What is the relataionship I can use to get
1) parent id
2) title of note
3) body of note

Code tried : This returns NULL
trigger tgrGetContractNotes on FeedItem (after insert, after update) {
    for(FeedItem f : Trigger.new){
        system.debug('#Contractid#'+f.ParentId);
        system.debug('#rel#'+f.RelatedRecordId);
        ContentVersion cV = [Select ContentDocumentId from  ContentVersion where id= :f.RelatedRecordId limit 1];
        ContentNote cN = [Select TextPreview,Title from ContentNote where id =: cv.ContentDocumentId limit 1];
        system.debug('#notetitle#'+cN.Title);
        system.debug('#notebody#'+cN.TextPreview);
        ContractFeed cF = [Select title, body from ContractFeed where parentid = : f.ParentId limit 1];
        system.debug('#notebody#'+cF.title);
        system.debug('#notebody#'+cF.body);
    }
}
Thanks
Ann
 
Andy BoettcherAndy Boettcher
Are you looking for the NOTE object?  Looking at your fields and request, I'm thinking you are.  Try [SELECT Id, Title, Body FROM Note WHERE ParentId = :yourRecordId]