Assume that the splitContactIds field has 3 contact ids separated with commas.

What do I need to add to this code in order to create 3 new records in the Training__c object where the records has a contact lookup field that is required and a Name field that is required? The cane can be any short text for our purposes.


Here is what I have

 Training__c trn = New Training__c();
        // CSV to list
        if (currentContacts_CSV != null && currentContacts_CSV != ''){
            splitContactIds = currentContacts_CSV.split(',');
            for (String cId:splitContactIds){


1 Answer 1


Something of this nature should work:

Training__c[] ts = new Training__c[] {};
for (String cId : splitContactIds){
    ts.add(new Training__c(Name = 'Training for ' + cId, Contact__c = cId));
insert ts;

You must log in to answer this question.

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