You need to sign in to do that
Don't have an account?
IntroAmmy
how to populate values from parent record to child record if object is same
I need to popluate values from parent record to child record using trigger if the object is same ,
Suppose in Account object(choose Record Type A) i have created and now i am going to create another record(let say child account record) in Account object but this time i have choose the Record Type B
So while i am creating child record some fields need to copy from first account record to child account record [i have created self relationship here]
below is the code
Trigger PopulatevaluesonChildAccount on Account(Before Insert)
{
Set<Id> ParentIds = New Set<Id>();
For(Account A : Trigger.New)
{
ParentIds.Add(A.AccountType__c);
}
List<Account> ParentList = [Select Id,AccountType__c,name from Account where Id =: ParentIds];
System.debug(ParentList);
For(Account ChildAccount : Trigger.New)
{
For(Account ParentAccount : ParentList)
{
IF(ChildAccount.AccountType__c == ParentAccount.ID)
System.debug(Co);
{
IF(ParentAccount.Name != NULL)
{
ChildAccount.Name = ParentAccount.Name ;
ChildAccount.AccountType__c=ParentAccount.Id;
}
}
}
}
Can someone please help on that
Suppose in Account object(choose Record Type A) i have created and now i am going to create another record(let say child account record) in Account object but this time i have choose the Record Type B
So while i am creating child record some fields need to copy from first account record to child account record [i have created self relationship here]
below is the code
Trigger PopulatevaluesonChildAccount on Account(Before Insert)
{
Set<Id> ParentIds = New Set<Id>();
For(Account A : Trigger.New)
{
ParentIds.Add(A.AccountType__c);
}
List<Account> ParentList = [Select Id,AccountType__c,name from Account where Id =: ParentIds];
System.debug(ParentList);
For(Account ChildAccount : Trigger.New)
{
For(Account ParentAccount : ParentList)
{
IF(ChildAccount.AccountType__c == ParentAccount.ID)
System.debug(Co);
{
IF(ParentAccount.Name != NULL)
{
ChildAccount.Name = ParentAccount.Name ;
ChildAccount.AccountType__c=ParentAccount.Id;
}
}
}
}
Can someone please help on that
What are all the fields you need to copy from parent record and provide the self lookup relationship field name.
Thanks!!