I trying to move notes from one object to another and reparenting them is not allowed as parentid is not a writable field. So I'm copying them. there are only 202 of them so I do not understand why this is failing. It retrieves them fine and the map is good but when the 'insert newNotes' is executed it fails with too many DML statements? This is the only DML statement

public void copyNotes() {     
 mev_PO_Requisition__c[] lpo = [select id,name,ao_po_id__c,copiedfromaopo__c from mev_PO_Requisition__c where copiedfromaopo__c = true];
      map<id, id> poidmap = new map<id,id>();
      set<id> lpoids = new set<id>();
      note[] newNotes = new list<note>();

      if(lpo.size()>0) {
        for(mev_PO_Requisition__c po: lpo) {
        notes = [select id, parentid, title, isprivate, body, ownerid from note where parentid in :lpoids];
        if (notes.size()>0) {
          for(note n: notes) {
            id tmpid = poidmap.get(n.parentid);
            note nn = new note(parentid=tmpid,title=n.title,isprivate=n.isprivate,body=n.body,ownerid=n.ownerid);
          insert newNotes;


This is the debug log and the only log generated

09:10:40.0 (262361)|USER_INFO|[EXTERNAL]|005d0000004XFDj|[email protected]|Eastern Standard Time|GMT-05:00
09:10:40.0 (292848)|EXECUTION_STARTED
09:10:40.0 (296165)|CODE_UNIT_STARTED|[EXTERNAL]|0661h0000008TIe|VF: /apex/rdTest4
09:10:40.0 (789553)|VF_DESERIALIZE_VIEWSTATE_BEGIN|0661h0000008TIe
09:10:40.0 (40486796)|VF_DESERIALIZE_VIEWSTATE_END
09:10:40.0 (41990929)|SYSTEM_MODE_ENTER|true
09:10:40.0 (42133288)|SYSTEM_MODE_ENTER|false
09:10:40.0 (42143400)|SYSTEM_MODE_EXIT|false
09:10:40.0 (65525331)|SYSTEM_MODE_ENTER|true
09:10:40.0 (112082521)|SYSTEM_MODE_ENTER|false
09:10:40.0 (114161295)|SOQL_EXECUTE_BEGIN|[147]|Aggregations:0|SELECT id, name, ao_po_id__c, copiedfromaopo__c FROM mev_PO_Requisition__c WHERE copiedfromaopo__c = TRUE
09:10:40.0 (150955955)|SOQL_EXECUTE_END|[147]|Rows:1940
09:10:40.0 (184442969)|SOQL_EXECUTE_BEGIN|[157]|Aggregations:0|SELECT id, parentid, title, isprivate, body, ownerid FROM note WHERE parentid = :tmpVar1 LIMIT 100
09:10:40.0 (211262211)|SOQL_EXECUTE_END|[157]|Rows:100
09:10:40.0 (215766074)|DML_BEGIN|[163]|Op:Insert|Type:Note|Rows:100
09:10:40.0 (215849728)|EXCEPTION_THROWN|[163]|System.LimitException: Too many DML statements: 1
09:10:40.0 (216062054)|SYSTEM_MODE_EXIT|false
09:10:40.0 (216155777)|FATAL_ERROR|System.LimitException: Too many DML statements: 1

  • 3
    Is the Visualforce page in read-only mode?
    – David Reed
    Jan 22, 2018 at 14:55
  • Including the fact you're working with a Visualforce Page would have been useful context from the get go.
    – Adrian Larson
    Jan 22, 2018 at 14:59
  • Yes I it would've. Sorry about that. And that was the problem David. The page was showing multiple list some of them large so I made it read-only. Problem solved. Thanks to you both for your time and help
    – Ohmicron
    Jan 22, 2018 at 15:01
  • 1
    @ohmicron, please select David’s answer so that others will find it useful Jan 22, 2018 at 16:09

1 Answer 1


(Comment to Answer for posterity).

The error log is showing

Too many DML statements: 1

because the Visualforce page is in read-only mode. (The normal DML statement limit is 150, so this is an indicator of the type of problem). Changing the Visualforce page out of read-only mode resolves this issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .