+ Start a Discussion
Rick RossiRick Rossi 

Trigger account question


I am trying to come up with a trigger but no luck. The logic is on the account object which parent accounts cannot have parent accounts and child accounts cannot have child accounts.

Any help would be great!

Thank you
PriyaPriya (Salesforce Developers) 

Hi Rick,

This is very confusing. Can you please simplify your description?


Priya Ranjan

Rick RossiRick Rossi
Hi Priya,

Thanks for getting back to me. So basically if an account is a parent account, they cannot be a child in any account hierachy. A child account also cannot be a parent account if it is a child in any account already.

Hope this makes sense :) Any help would be great.
Suraj Tripathi 47Suraj Tripathi 47
Hi Rick Rossi,

Yes, you can create this type of trigger
you can understand from this trigger :

trigger triggerOnContact on Contact (after insert, after update) { 
    Map<Id,String> map1 = new Map<Id, String>(); 
    for(Contact con:trigger.new) {
        map1.put(con.AccountId, con.update_Check__c);
    List<Account> listUpdatedAccount = new List<Account>(); 
    for(Account acc:[Select id, update_Check__c From Account Where Id IN :map1.Keyset()]) {
        if(map1.containsKey(acc.id)) {
            listUpdateAccount.add(new Account(Id = acc.id, update_Check__c=map1.get(acc.id)));
    update listUpdateAccount;

You can get help from this :

If you find your Solution then mark this as the best answer.

Thank you!

Suraj Tripathi