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

What is the ID of the new record I just added?
Here is a small sample of my code. In the line that is commented out for the AddError (used for debugging) I am asking for the ID of the newFulfillment record I just added. How do I get the ID?
List<productProcesses__c> processes = [SELECT Name, predecessorStep__c, processStep__c, successorStep__c, workStepName__c FROM productProcesses__c];
//for each one add to fulfillment and fulfillmentDependencies
for (productProcesses__c pp: processes) {
List<fulfillment__c> newFulfillment = new List<fulfillment__c>();
List<fulfillmentDependencies__c> newDependencies = new List<fulfillmentDependencies__c>();
if (pp.predecessorStep__c == 0) {
newStatus = 'current';
} else {
newStatus = 'waiting';
}
newFulfillment.add( new fulfillment__c (Opportunity__c = o.Id , Status__c = newStatus, workStepName__c = pp.workStepName__c));
try {
insert newfulfillment;
//o.AddError('ID: ' + newfulfillment.Id);
}
catch (DmlException de) {
for (Integer I = 0; I < de.getNumDml(); i++) {
o.addError(de.getDmlMessage(i));
}
}
All Answers
It looks like you are trying to insert record in "fulfillment__c" and then explicity adding error in trigger with the newly created record ID.
However the transaction is explicity aborted using "AddError" which causes the trigger to rollback the transaction including the insert operation.
The insert operation is not completed successfully, hence record ID is not available.