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
Nagma KhanNagma Khan 

how to count the note on the opportunities object ?

Nagma KhanNagma Khan
hi

doest not work Trigger
Balayesu ChilakalapudiBalayesu Chilakalapudi
Create a field Notes_Count__c of type number in your opportunity
Create a trigger on Note like this,
trigger NoteTrigger on Note (after insert,after delete) {
    Set<Id> oppidset=new Set<Id>();
    if(Trigger.isinsert){
    for(Note n:Trigger.new)
        oppidset.add(n.parentId);
    List<Opportunity> opplist=[Select Notes_Count__c,(Select Id FROM Notes) FROM Opportunity WHERE Id IN:oppidset];
    for(Opportunity opp:opplist){        
        opp.Notes_Count__c=opp.notes.size();
    } 
    update opplist;
    }
    if(trigger.isdelete){
        for(Note n:Trigger.old)
        oppidset.add(n.parentId);
    List<Opportunity> opplist=[Select Notes_Count__c,(Select Id FROM Notes) FROM Opportunity WHERE Id IN:oppidset];
    for(Opportunity opp:opplist){        
        opp.Notes_Count__c=opp.notes.size();
    } 
    update opplist;
    }
}
It worked for me.