Hi, Below Sample Code can fulfill your requirements, Hope this will work for you.
trigger CreateCustomObjRec on Opportunity (after insert, after update) {
List <Test__c> testRec = new List <Test__c> ();
for (Opportunity o : Trigger.new) {
if (o.StageName == 'Closed Won'){
Test__c s = new Test__c ();
s.Name = o.Name;
// Map other fields if you want
testRec.add(s);
}
}
try {
INSERT testRec;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
Please mark this as best answer if this solves your problem.
Below Sample Code can fulfill your requirements, Hope this will work for you.
Please mark this as best answer if this solves your problem.
Thank you,
Ajay Dubedi