+ Start a Discussion
Jon FoyJon Foy 

Need Help Creating an Apex Class to Create a New Record on Custom Object

I'd like to create an Apex Class that finds any 'Case_Resource__c' (Custom Object) where the following critera are met ont his object:
UOM__c = 'mo.'
Active__c = 'true'
For all Case_Resource__c records that are found matching those criteria, I'd like to create a new 'TimeSlip__c' (Custom Object) record.

The new TimeSlip__c record should map some data points from the Case_Resource__c record:
(Case Resource) Case__c should be mapped to the new (TimeSlip) Case__c
Case_Resource_ID should be mapped to the new (TimeSlip) Case_Resource_ID__c

The new TimeSlip__c record should also be created with this static value:
(TimeSlip) Total_Time__c = '1'

The result should be all Case_Resource__c records that are active and uom = mo. would then have a corresponding TimeSlip containing the matching Case, Case Resource ID, and a value of 1 in the Total Time field.

Liist<TimeSlip__c> recsToBeInserted = new Liist<TimeSlip__c>();
for(Case_Resource__c c:[Select id, Case__c from Case_Resource__c]){

TimeSlip__c ts= new TimeSlip__c();
ts.Total_Time__c = 1;

//do error handling

Hope this helps! 
Jon FoyJon Foy
Thank you so much for taking the time to respond.

However, I only want to create a new timeslip for case resources where UOM__c = 'mo.' and Status__c = true.  
You need to edit the query in the for loop.

for(Case_Resource__c c:[Select id, Case__c from Case_Resource__c where UOM__c = 'mo.' and Status__c = true ])