You need to sign in to do that
Don't have an account?

Insert trigger to create child on parent creation (ID field issue)
Dear all,
I have been playing around and looking for a solution to my problem on these forums for quite a bit now without success (it is worth mentioning I am new to the developer side of SF). Here is what I am trying to accomplish:
Users in our system create a record project__c (master object). The trigger then is meant to create a record for Selling_Team__c (child), using the project owner (or the running user's ID if the first does not work) to populate "User__c" (look-up field). My problem is that I cannot get the ID into the child record without error - "INVALID_FIELD_FOR_INSERT_UPDATE". I have tried several ways with map(), list(), etc. but have not yet managed to get this done. Without the ID insert for User__c, the trigger works fine (child record gets created with information for role__c).
Any help on this would be highly appreciated! (please see below for details of trigger)
Many thanks,
Daniel
-------
trigger CreateSellingTeam on ts2__Project_Job__c (after insert)
{
//Creates set for Project records
list<Selling_Team__c> STList = new list<Selling_Team__c>{};
//Loop for new record
for (ts2__Project_Job__c Pro :trigger.new)
{STList.add(new Selling_Team__c (
Role__c = 'Lead CSP',
User__c = UserInfo.getUserID()
));
} {
insert STList;
try { insert STList; } catch (Exception Ex) { system.debug(Ex);
}
}
}
Please see if this helps.
http://help.salesforce.com/apex/HTViewSolution?id=000073334&language=en_US
Regards,
Satish Kumar
Thank you for your prompt response, but I am afraid the link does not fully describe my situation. In your link, the problem comes from a erroneous attempt to update a field on the parent record, whereas my problem is to get the ID value from the parent record into the newly created child record.
....
for (ts2__Project_Job__c Pro :trigger.new)
{STList.add(new Selling_Team__c (
Role__c = 'Lead CSP',
User__c = UserInfo.getUserID()
...
Regards,
Daniel