You need to sign in to do that
Don't have an account?

How to update the parent object using trigger while gettting the data from child and other parent object
Hi,
I have created a Trigger on the Child Object having 2 parent objects. Below is the Relationship
So, I want to do is to create a trigger after the attendee Record is created. The tirgger will look for some fields on the Special Events and Contacts and if the criteria is met then update some fields on the Contact Object.
I have created the trigger but it looks like not working. It is not giving me any error also.
Below is the code of the Trigger.
trigger AttendeeITK on evt__Attendee__c (after insert)
{
List<Contact> contactsToUpdate = new List<Contact>();
Set<Id> ContactIds = new Set<Id>();
Set<Id> SEIds = new Set<Id>();
for(evt__Attendee__c attendee :trigger.new)
{
ContactIds.add(attendee.evt__Contact__c);
SEIds.add(attendee.evt__Event__c);
}
Map<Id, Contact> ContactMap = new Map<Id, Contact>([SELECT Id,Assignment_Queue__c,Law_Student__c,Stage__c,Contact_Type__c FROM Contact WHERE Id IN :ContactIds]);
Map<Id, evt__Special_Event__c> SEMap = new Map<Id, evt__Special_Event__c>([SELECT Id,Non_Recruitment_Event__c FROM evt__Special_Event__c WHERE Id IN :SEIds]);
for(evt__Attendee__c attendee : System.Trigger.New)
{
Contact tempContact = ContactMap.get(attendee.evt__Contact__c);
evt__Special_Event__c tempSE = SEMap.get(attendee.evt__Event__c);
if (tempSE.Non_Recruitment_Event__c == False &&
tempContact.Assignment_Queue__c == null &&
tempContact.Law_Student__c == False &&
tempContact.Stage__c == null &&
tempContact.Ownerid == '005G0000002wYvi' &&
(tempContact.Contact_Type__c != 'Faculty' || tempContact.Contact_Type__c == null))
{
tempContact.Assignment_Queue__c = 'Inside Track Graduate';
tempContact.Stage__c = 'New';
tempContact.Lead_Status__c = 'Not Attempted';
tempContact.Contact_Type__c = 'Prospect';
tempContact.Most_Recent_Inquiry_Date__c = date.today();
tempContact.Non_Law_Student__c = True;
contactsToUpdate.add(tempContact);
}
}
update contactsToUpdate;
}
I will really appreciate if somebody can help me in developing the right code.
Thanks
I have created a Trigger on the Child Object having 2 parent objects. Below is the Relationship
- evt__Attendee__c - Child Object
- evt__Special_Event__c - Parent Object
- Contacts - Parent Object
So, I want to do is to create a trigger after the attendee Record is created. The tirgger will look for some fields on the Special Events and Contacts and if the criteria is met then update some fields on the Contact Object.
I have created the trigger but it looks like not working. It is not giving me any error also.
Below is the code of the Trigger.
trigger AttendeeITK on evt__Attendee__c (after insert)
{
List<Contact> contactsToUpdate = new List<Contact>();
Set<Id> ContactIds = new Set<Id>();
Set<Id> SEIds = new Set<Id>();
for(evt__Attendee__c attendee :trigger.new)
{
ContactIds.add(attendee.evt__Contact__c);
SEIds.add(attendee.evt__Event__c);
}
Map<Id, Contact> ContactMap = new Map<Id, Contact>([SELECT Id,Assignment_Queue__c,Law_Student__c,Stage__c,Contact_Type__c FROM Contact WHERE Id IN :ContactIds]);
Map<Id, evt__Special_Event__c> SEMap = new Map<Id, evt__Special_Event__c>([SELECT Id,Non_Recruitment_Event__c FROM evt__Special_Event__c WHERE Id IN :SEIds]);
for(evt__Attendee__c attendee : System.Trigger.New)
{
Contact tempContact = ContactMap.get(attendee.evt__Contact__c);
evt__Special_Event__c tempSE = SEMap.get(attendee.evt__Event__c);
if (tempSE.Non_Recruitment_Event__c == False &&
tempContact.Assignment_Queue__c == null &&
tempContact.Law_Student__c == False &&
tempContact.Stage__c == null &&
tempContact.Ownerid == '005G0000002wYvi' &&
(tempContact.Contact_Type__c != 'Faculty' || tempContact.Contact_Type__c == null))
{
tempContact.Assignment_Queue__c = 'Inside Track Graduate';
tempContact.Stage__c = 'New';
tempContact.Lead_Status__c = 'Not Attempted';
tempContact.Contact_Type__c = 'Prospect';
tempContact.Most_Recent_Inquiry_Date__c = date.today();
tempContact.Non_Law_Student__c = True;
contactsToUpdate.add(tempContact);
}
}
update contactsToUpdate;
}
I will really appreciate if somebody can help me in developing the right code.
Thanks
I think you should check this link
https://developer.salesforce.com/forums/?id=906F00000008ztOIAQ
you are trying to update a read only record
Can you please add the debug statement inside the if condition and try to update the attendee record. If it comes inside the if condition then it should definitely work for you.
Thanks,