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
AlecSAlecS 

Create a Note under Custom Object

I have a custom object called Invoice.

 

I want to create a new Task under this object.

 

I have this code:

Note inv_note = new Note();
	     inv_note.ID = theInvoice.id;
            inv_note.Title = theInvoice.Invoice_Name__c+' invoice emailed';
            inv_note.body = 'Invoice emailed';
        insert inv_note;
        

 This is the error message that I get:


Invalid id value for this SObject type: a07W0000000kJQMIA2

Error is in expression '{!doMyApexLogic}' in component <apex:page> in page apexbuttonpage
 
Thanks for your help!
Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

Id must be null for inserts. You meant to assign theInvoice.Id to inv_note.ParentId.

All Answers

sfdcfoxsfdcfox

Id must be null for inserts. You meant to assign theInvoice.Id to inv_note.ParentId.

This was selected as the best answer
AlecSAlecS
sfdcfox - you rock!!! Thanks!