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
IntroAmmyIntroAmmy 

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  
AnkaiahAnkaiah (Salesforce Developers) 
Hi,

What are all the fields you need to copy from parent record and provide the self lookup relationship field name.

Thanks!!