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
DannyK89DannyK89 

Adding Notes

I would like to add a Note to a custom object everytime a user does a certian action on my visual force page such as click a button. At the Moment I am having trouble with that. A code sample or redirect would be appreciated. 

Best Answer chosen by Admin (Salesforce Developers) 
DannyK89DannyK89

 

notes.OwnerId = UserInfo.getUserId();
                    notes.ParentId = RFGroup.Id;
                    notes.Title = 'Log In';
                    notes.Body = '{!RFGroup.Name} Logged In';
                    try {
                       insert notes;
                    } catch (DMLException e) {
                       ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error: Log Not Updated'));
                    } finally {
                       notes = new Note(); 
                    }

 

I did this and it seemed to work. 

 

All Answers

NPNP

for most of the tag's ( for eg - pageBlock ) you have onclick="" , you can use this .

 

 

DannyK89DannyK89

 

notes.OwnerId = UserInfo.getUserId();
                    notes.ParentId = RFGroup.Id;
                    notes.Title = 'Log In';
                    notes.Body = '{!RFGroup.Name} Logged In';
                    try {
                       insert notes;
                    } catch (DMLException e) {
                       ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error: Log Not Updated'));
                    } finally {
                       notes = new Note(); 
                    }

 

I did this and it seemed to work. 

 

This was selected as the best answer