0

I have 3 objects Contact, mList and mEvent. mList is a junction object which has master-detail relationships to both Contact and mEvent. The mEvent has a picklist field called Group_Level__c (values 1,2,3,4) and Contact has text field called Member_Level__c.

My problem is that whenever I save/update a new mEvent record, I need the selected mEvent.Group_Level__c picklist value to be reflected to all Contact.Member_Level__c text values that are linked to it. (Contact.Member__Level__c values are dependent on mEvent.Group_Level__c value)

What is the best approach to achieve this? (An mEvent record can be linked to thousands of Contact records at a time and vice versa.)

1 Answer 1

0

write before update trigger on mevent object. now in this trigger whenwver Group level change tthen query on mcent object including the contact field . now store this value in contact and update all contact.

Example

List<mcent__c> mcentlist =[select Contact__c,mevent__c , mEvent.Group_Level__c from mcent__c where mevent__c ID IN : meveIdSet];
List<contact> conlist = new List<contact>();
for(mcent__c me : mcentlist )
{
     contact con = new contact(id = me.contact__c);
     con.Member_Level__c = Trigger.newMap.get(me.mevent__c).Group_Level__c;
     conlist.add(con);
}
update conlist;

As i am not sure about your field api name so check them also check some null pointer validation as well. This code will give you basic understanding.

5
  • @Tushar...what if the contact is linked with thousands of mEvent and an mEvent is linked to thousands of Contact...will it reach a governor limit or not? if so, what could be done to bypass that? thx so much
    – Micz Domz
    Feb 6, 2016 at 17:14
  • what is 'meveIdSet' in the query?
    – Micz Domz
    Feb 6, 2016 at 17:59
  • meveIdset is the set of id of mevent object. and yes it can hit the governer limit for that you need to break the code. Feb 6, 2016 at 19:24
  • is it possible for you to give me the full trigger code (including the above)? I currently have small backgroup on triggers and I could use it for future references...
    – Micz Domz
    Feb 6, 2016 at 19:31
  • i realized my logic has a problem...if a contact is related to multiple events and have these corresponding selected picklist values: (mEvent ,selected value) eventA, 1; eventB, 3; eventC, 2; I decided I will get my contact value from the selected picklist value of the latest event ex. eventB based on its datecreated
    – Micz Domz
    Feb 6, 2016 at 19:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .