You need to sign in to do that
Don't have an account?
Account Contact Role
I have a trigger that I need to find a specific role name if the account contact role name is "Primary Service Contact" the trigger will inserted or update the field named ( Account_Case_Contact__c with the account contact role name. I tried added this code to my Where statement, but it obvioysly didn't work. Can anyone help me? ) trigger Trigger_CasePrimaryContact on Account (before insert, before update) { for (Account a : Trigger.new) { // a.NextStep = 'DEBUG: Running function...'; AccountContactRole[] contactRoleArray = [select ContactID, Role from AccountContactRole where AccountId = :a.id && Role='Primary Service Contact' ORDER BY Role DESC, createdDate]; if (contactRoleArray.size() > 0) { a.Account_Case_Contact__c = contactRoleArray[0].ContactID; }else{ // IF NO CONTACT ROLES EXIST RETURN NULL... a.Account_Case_Contact__c = null; // a.NextStep = 'DEBUG; CONTACT = null '; } } }
select ContactID, Role from AccountContactRole where AccountId = :a.id AND Role='Primary Service Contact' ORDER BY createdDate
Thx
All Answers
I need to find a specific role name if the account contact role name is "Primary Service Contact" - what does this mean? specific role name?
select ContactID, Role from AccountContactRole where AccountId = :a.id &&Role='Primary Service Contact' ORDER BY Role DESC, createdDate
What are you trying to do? Does the role 'Primary Service Contact' exist? You probably don't need ORDER BY Role DESC since only 1 role is returned.
Thx
Primary Service Contact
The error I get is below while trying to save the change.
Error: Compile Error: Variable does not exist: Role at line 18 column 83
I will remove the Order By DESC.
select ContactID, Role from AccountContactRole where AccountId = :a.id AND Role='Primary Service Contact' ORDER BY createdDate
Thx