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
NikithaNikitha 

hey I'm new to salesforce I want to copy Custom object variables to other Custom object variables using bulk triggers in anonymous window please help me

My first custom object Customer_Detail__c
coping object Dup_Customer_Detail__c
 
AnudeepAnudeep (Salesforce Developers) 
You cannot write a trigger in execute anonymous window. However, you can fire a trigger by performing a DML

You cannot copy the custom object variable but you can copy the field values. Here is an example
 
trigger insertMember2 on Member__c (after insert) {
 Set<Id> Ids= new Set<Id>();
    for (Member__c member : Trigger.new)
    {
        Ids.add(member.Id);        
    }
 List<Member__c> memberList = new List<Member__c>([Select Id,FirstName__c,LastName__c  From Member__c e where Id in :Ids]);

	for(Member__c temp : memberList )
	{
		Member2__c member2 = new Member2();
		member2.FirstName__c = temp.FirstName__c;
		member2.LastName__c = temp.LastName__c;
		insert member2;

	}


 }

Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you
NikithaNikitha
Hey Anudeep,
     Thanks for clarification about anonymous window . I have tried your code but Im not able to copy can say why. my code 

trigger BulkCustomerDetailsName on Customer_Detail__c (after insert) {
    set<id> Ids = new set<id>();
}
    for(Customer_Detail__c customer : trigger.new){
        Ids.add(customer.Id);
        List<Customer_Detail__c> customerList = new List<Customer_Detail__c>([Select id,Name,Last_name__c from Customer_Detail__c
                                                                             where Id in :Ids]);
        for(Customer_Detail__c cus: customerList){
            Dup_Customer_Detail__c dup1 =new Dup_Customer_Detail__c();
            dup1.Name = cus.Name;
            dup1.Last_Name__c = cus.Last_name__c;
            insert  dup1;
        }
    
    

}