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
laxman rajlaxman raj 

how to insert a new record in same object by using a trigger

trigger insertrecord on x__c (before insert) {
list<x__c> cu=trigger.new;
for(x__c xg:trigger.new)
{
xg.name='hjh';
insert xg;
}
}
Vatsal KothariVatsal Kothari
Hi,

You can refer below code:
trigger insertrecord on x__c (before insert) {
	List<X__c> cu = new List<X__c>;
	
	for(x__c xg:trigger.new)
	{
		X__c xg = new X__c();
		xg.name='hjh';
		cu.add(xg);		
	}
	
	if(cu.size() > 0){
		insert cu;
	}	
}
If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal
laxman rajlaxman raj
hi vatsal thanks for your reply am using your code but record is not inserted thanks, laxman