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
KevinsanKevinsan 

Can I import data into child object without parent recordID by dataloader?

Hi, I have two objects Parent__c and Child__c in Master-Detail relationship.
There is need that create a trigger on Child__c which can automatically create parent record when child records are insert or update.
Is that possible?
My understanding is a child record cannot be inserted without parent record ID.
Best Answer chosen by Kevinsan
Raj VakatiRaj Vakati
Its possiable with the trigger .. .Like this   sample code is here and its not bulkified 
 
trigger demo on Chaild__c(before insert){
	
	for(Chaild__c c :Trigger.new){
		Parent__c p = new Parent__c();
		p.Name =c.Name ; 
		insert p ; 
		c.ParentiD__c =p.Id ; 
	}
	
	
}

 

All Answers

Raj VakatiRaj Vakati
Its possiable with the trigger .. .Like this   sample code is here and its not bulkified 
 
trigger demo on Chaild__c(before insert){
	
	for(Chaild__c c :Trigger.new){
		Parent__c p = new Parent__c();
		p.Name =c.Name ; 
		insert p ; 
		c.ParentiD__c =p.Id ; 
	}
	
	
}

 
This was selected as the best answer
SANKET KUMAR 28SANKET KUMAR 28
Hi @kevinsan,
If you want to achieve this, use dataloader.io whe you can lookup via name if you have parent record already in your org. If you dont have parent record then go for trigger.