I am trying to use the below code in my trigger to copy the Notes from my custom object to a newly created record on the Demand object:
List<Note> insertingNotes = new List<Note>();
List<Note> lstNotes = [SELECT Id, Title, ParentId, LastModifiedDate, createdbyid, body FROM Note where ParentId =:rq.Id];
for (Note eachNote : lstNotes){
Note newDemandNote= new Note();
newDemandNote.Body = eachNote.Body;
newDemandNote.Id = eachNote.Id;
newDemandNote.createdBy = string.valueOf(eachNote.CreatedById);
newDemandNote.LastModifiedDate = eachNote.LastModifiedDate;
newDemandNote.ParentId = newD.Id;
insertingNotes.add(eachNote);
}
if (insertingNotes.size() >0){
insert insertingNotes;
}
But I am getting a compile error Illegal assignment from String to User on the line
newDemandNote.createdBy = string.valueOf(eachNote.CreatedById);
I also tried:
newDemandNote.createdBy = eachNote.OwnerId;
but no luck!
so what is the correct way to do this?