• KevinSF
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

So, I have an object called Interaction.  When the picklist value "Speaker" is stored in the Interaction object's Selected_Sub_type__c field, I want it to update Contact and Account object checkboxes.  It works correctly for the Contact object.  I want to enhance the following code so that it will also update the Account object record Guest_Speaker_s__c checkbox to TRUE.

 

The Interaction object is related to the Account and Contact object by these fields:

Field Label     API Name          Data Type

Account         Account__c        Master-Detail(Account)

Contact         Contact__c         Lookup(Contact)

 

 

This code works to update the Contact object checkbox:

======================================================================================

// Update Contact field: "Guest_Speaker__c" to TRUE when a new Interaction__c record is inserted or updated.

// This code will not set the checkbox to false if the Sub_type value is not 'Speaker'

 

trigger UpdateGuestSpeakerCheckbox on Interaction__c (after insert, after update) {

 

// Will store Contact record ID

map< id, contact > contacts = new map< id, contact >();

 

// Create trigger for new or selected Interaction__c record

for(Interaction__c record:trigger.new)       

 

if(record.Selected_Sub_type__c == 'Speaker')

 

     // Update checkbox field on the Contact record to TRUE

     contacts.put(record.contact__c, new contact(id=record.contact__c, Guest_Speaker__C = TRUE));     

 

update contacts.values(); 

 

}

======================================================================================

 

 

This was my attempt to make the checkbox on the Account record update with the same trigger:

The Contact record updated fine.  The Account record was not updated.

Can you help me dial this in?

Thanks!

 

Kevin

 

My attempt, it compiles but it does not update Account object.

=======================================================================================

// Update Contact field: "Guest_Speaker__c" to TRUE when a new Interaction__c record is inserted or updated.

// This code will not set the checkbox to false if the Sub_type value is not 'Speaker'

 

trigger UpdateGuestSpeakerCheckbox on Interaction__c (after insert, after update) {

 

// Will store Contact record ID

map< id, contact > contacts = new map< id, contact >();

 

// Create trigger for new or selected Interaction__c record

for(Interaction__c record:trigger.new)       

 

if(record.Selected_Sub_type__c == 'Speaker')

 

     // Update checkbox field on the Contact record to TRUE

     contacts.put(record.contact__c, new contact(id=record.contact__c, Guest_Speaker__C = TRUE));     

 

update contacts.values(); 

 

 

// The new section added to update the Account object, just doesn't work!

 

// Store Account record ID  

map< id, account > account = new map< id, account >();

 

     for(Interaction__c record:trigger.new)       

          if(record.Selected_Sub_type__c == 'Speaker')

 

     // Update checkbox field on the Account record to TRUE     

     Account.put(record.account__c, new account(id=record.account__c, Guest_Speaker_s__c = TRUE));

 

}

=======================================================================================

My goal: Update Contact.Major_Gift_Given_Contact checkbox to TRUE when a child "Advancement Given" record is created or updated.

 

This is what I want to do, except for the error:

"Error: Compile Error: Expression cannot be assigned at line -1 column -1"

 

trigger UpdateMajorGiftGivenContactCheckbox on Advancement_Giving__c (after insert, after update) {

Contact.Major_Gift_Given_Contact__C = TRUE;

}

 

Brand new to APEX, thanks for any help.

 

My goal: Update Contact.Major_Gift_Given_Contact checkbox to TRUE when a child "Advancement Given" record is created or updated.

 

This is what I want to do, except for the error:

"Error: Compile Error: Expression cannot be assigned at line -1 column -1"

 

trigger UpdateMajorGiftGivenContactCheckbox on Advancement_Giving__c (after insert, after update) {

Contact.Major_Gift_Given_Contact__C = TRUE;

}

 

Brand new to APEX, thanks for any help.