I'm having problems with my apex code inserting. I don't know whats going on

here is my code:

// object instance with memory allocation.

Work_Order__c wo = new Work_Order__c();
wo.Est_Hours__c = 89;
wo.Instructions__c = 'this is a test';
insert wo;

and I have looked at the system.debug log and this is what I'm getting in the log:

23:54:38.198 (198681448)|USER_DEBUG|[14]|DEBUG|===> insert ===> Work_Order__c:{Instructions__c=this is a test, Est_Hours__c=89, Id=a0j1a000000cbuFAAQ}

but how come its not inserting a new row in the Work_Order__C object?

  • Why are you saying it's not inserted? it has an Id, which you get only after inserting the record. It seems inserted. – navD87 May 25 '15 at 4:13
  • That code won't run. The second and third lines don't terminate with a semi colon. Are you sure this is the right code? What error messages are you receiving? – Nick Cook May 25 '15 at 4:13
  • yes its look like but i do not see the record in work_oder__c object thats the confusing part – Nick Kahn May 25 '15 at 4:14
  • 1
    What happens if you pop that Id in the URL? – Nick Cook May 25 '15 at 4:15
  • 1
    What filter is on the list view? – Nick Cook May 25 '15 at 4:20

As per your discussion with Nick, the view from where you are seeing the records has a filter enabled on it. It may be showing recently opened records
You can see all records by creating a new view ( if not already present ) which will not have any filter and shows all records.

Regarding your question about inserting Picklist values, here is a sample code
Project__c prj = new Project__c();
prj.Project_Name__c='Proj 003';
prj.Project_Status__c = 'Active';
insert prj;

Here Status field is a picklist value. It is ultimately a string field and a string value is saved.

Hope it is clear, you can try and get back in case of any issues.


Use schema as a prefix, sometimes we need to use that. Try this let me know if you're having any more problems.

Schema.Work_Order__c wo = new Schema.Work_Order__c();
wo.Est_Hours__c = 89;
wo.Instructions__c = 'this is a test';
insert wo;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.