Specifically, I'm trying to figure out the syntax to add the parent/master object id, to the child/detail record so the insert works without giving an error of malformed Id. I know the master name, just not the id at the time of the insert.
Apologies in advance, first day with Triggers. I don't know Java, but I do code in C#. This has a C# feeling, but I've heard Java is very similar.
Anyway, using Bulk API to add child record but failing because I don't have the Id of the Master record in the Detail record. I've heard a trigger on "before insert" will solve and I just went through the trailhead tutorial on bulk API. I think I'm missing the final aspect to being complete.
So documentation indicates a before insert operates on all records in the api call, thus single assignment is deemed bad.
I would assume at end of trigger, it will process the updates, I don't have to give it a command to continue. I would also assume I can change the values in the set of inserts to be preformed. In this case, I'm trying to replace the MasterName with the Id of the object.
If this is not the right approach - please blast away. Otherwise a couple of friendly suggestions on this code would be greatly appreciated.
trigger DetailTrigger on Detail__c (before insert) {
List<Master__c> masts = [select id, name from Master__c];
for(Detail__c dt : Trigger.new) {
ID mastId = [select Id from masts where Name = dt.Name];
if(dt.MasterName__c != null) dt.MasterName__c = parts.Name.contains(dt.MasterName__c).Id;
}
}