function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pranathi AnukuriPranathi Anukuri 

write a trigger when opportunity stage is closed won the record must be create in any custom object with the opportunity name

Raj VakatiRaj Vakati
Try this code
 
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update)
{
    
    List<CustomObject__c> coInsert = new List<CustomObject__c>();
    
    for(Opportunity o: Trigger.new)
    {
        if(o.StageName=='Closed Won')
        {
            CustomObject__c t= new CustomObject__c();
            t.Name=o.Name;
            t.Amount__c=o.Amount;
// Add other fields 
            coInsert.add(t);
        }
        
    }
    
    if(coInsert.size() > 0){
        insert coInsert ;
    }
    
}

 
Ajay K DubediAjay K Dubedi
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.

Thank you,
Ajay Dubedi