You need to sign in to do that
Don't have an account?
Mario C
Help with simple trigger on contact
I can't get the following trigger to update the acount!
Can you pleas help me?
Can you pleas help me?
trigger UpdateMembershipLevelOnAccount on Contact (after update) { for(Contact con : Trigger.New) { List<Contact> conList; List<Contact> gm; List<Contact> sm; List<Contact> bm; String contactMembLevel; String accountMembLevel; conList = [Select ID, Member_Level__c, Account.Membership_Level_Text__c FROM Contact WHERE Account.Id = :con.Account.Id]; if(conList.Size() <2 ){ accountMembLevel = contactMembLevel; } else if(conList.Size() >1 ){ for(Contact c: conList){ contactMembLevel = con.Member_Level__c; accountMembLevel = con.Account.Membership_Level_Text__c; if(c.Member_Level__c == 'Gold'){ gm.add(c); accountMembLevel = 'Gold'; } else if(c.Member_Level__c == 'Silver'){ sm.add(c); if(gm.size() <1 && sm.size() >0){ accountMembLevel = 'Silver'; } else { bm.add(c); accountMembLevel= 'Black'; } } } } } }
Hope this works.
Thanks
All Answers
Thanks
if on any of the contacts of an account there is not any with member level gold, but there is a silver then the related account membership level field has to be populated with Silver
if on any of the contacts of an account there is not any with member level gold or silver, the related account membership level has to be populated with Black (black is the default contact member level value)
Thanks
UpdateMembershipLevelOnAccount: execution of AfterUpdate caused by: System.ListException: DML statement found null SObject at position 0 Trigger.UpdateMembershipLevelOnAccount: line 24, column 1
Thanks for your help so far.
The account membership level should be Gold if at least 1 contact of the same account has member_level__c = gold. Similarly, the account membership level should be Silver if at least 1 contact of the same account has member_level__c = Silver and none of the contacts of the same account are Member Level = Gold. If none of the contact of same account have member level = gold or silver, the account membership level should be set to black.
As you can see, in my original code, I've divided the account contacts in 3 lists based on contact member level; the size of each list will indicate the contacts of the account are gold, silver and/or black.
Hope this works.
Thanks
Thanks,
Ashish
I am getting the following when I create a new contact:
UpdateMembershipLevelOnAccount: execution of AfterInsert caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Contact.AccountId Trigger.UpdateMembershipLevelOnAccount: line 14, column 1
List<Contacts> contactLst=[Select id,Member_Level__c,AccountId from contact where AccountId in:lstAccountIds];