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

Hoping for help with trigger for lookup field.
This may be a stretch but I'm hoping for someone to help me write a trigger.
We have a lookup field on accounts that filters on related contacts. Based on a series of conditions being met when a record is edited, we'd like to insert into that field the Contact ID for the related contact with title = Owner.
Conditions to be met are:
Steps_to_Close__c = "Enrolled" - picklist field
Number_of_clients__c = 0 - number field
Franchise_Association__c = Null or "HCA" - picklist field
Field to update:
PM__c to be equal to the contact ID for the related contact whose title = "Owner.
Hoping someone can help a guy with not many resources....
James
We have a lookup field on accounts that filters on related contacts. Based on a series of conditions being met when a record is edited, we'd like to insert into that field the Contact ID for the related contact with title = Owner.
Conditions to be met are:
Steps_to_Close__c = "Enrolled" - picklist field
Number_of_clients__c = 0 - number field
Franchise_Association__c = Null or "HCA" - picklist field
Field to update:
PM__c to be equal to the contact ID for the related contact whose title = "Owner.
Hoping someone can help a guy with not many resources....
James
I am not explaining postive and negative case here but following code should give you 100% code coverage. Try to understand code with inline comments.
Thanks,
Himanshu
All Answers
All conditions fields are on Contact because multiple contact can have title="Owner" ?
"The Conditions to be met" are fields/values that are on the Account object right?
@Himanshu: No, they are on the account object. I realize that many contacts could have that title, and definitely thought about that. This trigger should only execute once for a specific subset of accounts where there *should* only be one contact who is an owner. If otherwise, it can fail and I'm okay with it.
following code should work. As you said I am assuming here that there will be single contact with title='Owner'
Thanks,
Himanshu
Error: Compile Error: unexpected token: '{' at line 17 column 5
Any thoughts? Thanks for all your help. Hoping this will actually work!
Error: Compile Error: expecting a semi-colon, found 'for' at line 13 column 11
and here is the code with your original text on line 13:
I was putting comment at that line. you can remove that line or replace that with
I am not explaining postive and negative case here but following code should give you 100% code coverage. Try to understand code with inline comments.
Thanks,
Himanshu