+ 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