I need to update a field value on an AccountContactRelation record in an Apex class, so I need to get a reference to the record that gets created based on the Account and Contact I just created.
So I'm trying this out first in the ExecuteAnonymous window. But this code isn't working. It works until the attempt to use the Select statement and assign the result to the variable. Help, what am I doing wrong here?
Account pa = new Account(); pa.ParentId = '001M000000zr8YvIAI'; pa.Name = 'Test Parent Account'; database.insert(pa); Contact c = new Contact(); c.AccountId = pa.Id; c.FirstName = 'John'; c.LastName = 'Tester'; c.email = 'email@example.com'; database.insert(c); AccountContactRelation acr = [Select Id, status__c from AccountContactRelation where AccountId = pa.Id and Contactid = c.Id]; acr.status__c = 'Active'; database.insert(acr);
The error I get is "Unexpected token 'acr'."
Can anyone help me, please?