You need to sign in to do that
Don't have an account?
Issue updating contact's parent account via mutually related custom object
I'm stumped!
The scenario:
- Object "ZenDesk Ticket" record is created, with a lookup field to an account, and another lookup field to a contact.
- The contact record didn't exist until the ZenDesk connector created the ticket record in SF, at which point it also creates the contact
- ZenDesk should create the contact with the ticket's related Account also being the contact's related account. Instead, the contact is created as an orphan.
- Not sure if this is relevant, bu the ZenDesk objects/fields/etc are part of a managed package on our org.
Trigger goal:
- Upon creation of ticket and contact, to identify the account related to the ticket, and update the related contact to also relate to this account.
Method from my test class:
static testmethod void contact_with_no_account(){ Account testAccount1 = new Account(Name = 'test account', Type = 'Customer', Country__c = 'Albania'); insert testAccount1; Contact testContact1 = new Contact(FirstName = 'Test', LastName = 'Contact', City__c = 'Test city'); insert testContact1; test.startTest(); Zendesk__Zendesk_Ticket__c testTicket1 = new Zendesk__Zendesk_Ticket__c(Zendesk__Organization__c = testAccount1.ID, Zendesk__Requester__c = testContact1.ID); insert testTicket1; test.stopTest(); System.assertEquals(testContact1.AccountId, testAccount1.ID); }
Pretty basic - I make an account, an orphaned contact, and a ticket that relates to both of them, and insert them all. That should set off this trigger:
(partial) Trigger code:
trigger Zendesk_Ticket_Trigger on Zendesk__Zendesk_Ticket__c (after insert) { for (Zendesk__Zendesk_Ticket__c ticket1: [SELECT Id, Zendesk__Organization__c, Zendesk__Requester__r.AccountID FROM Zendesk__Zendesk_Ticket__c WHERE Id IN :Trigger.new AND Zendesk__Requester__r.AccountID = NULL]){ ticket1.Zendesk__Requester__r.AccountID = ticket1.Zendesk__Organization__c; update ticket1.Zendesk__Requester__r; }
I wonder if my SOQL query is causing the problem by selecting only the tickets whose related Contact's account ID is NULL - can I fairly assume that to be true when a contact is inserted without an account specified?
The problem:
My system.assertEquals statement is returning the error, because the "requester" contact's account ID is null. Clearly it isn't updating after being assigned ticket1.Organization__c's ID.
This *shouldn't* matter, but have you tried aligning the spelling of the field names (for case sensitivity)? You mention AccountId vs. AccountID.
Again, this *shouldn't* matter, but it's good to check anyway.