You need to sign in to do that
Don't have an account?
Abraham kumar 4
Compile Error: Invalid foreign key relationship: Contact.Accounts__r
Hi All,
I am using below Trigger code to send notifications to external webservice
Please help me resolve this issue.
Thanks
Abraham
I am using below Trigger code to send notifications to external webservice
if(Trigger.isUpdate){ contact old = Trigger.oldMap.get(c.Id); if (c.Email != old.Email||c.FirstName!=old.FirstName||c.LastName!=old.LastName||c.phone!=old.phone||c.Title__c!=old.Title__c||c.status__c!=old.status__c||c.AccountID!=old.AccountID||c.Accounts__r.Name!=old.Account__r.Name)but my error is only in the last part c.Accounts__r.Name!=old.Account__r.Name i want the trigger to fire when the account name is edited Like for Example when Account name "SFDC" is edited to "SFDC.COM" the related contacts of the account is also changed to SFDC.COM. i want the trigger to fire when this name change occurs in the account name field of contact object that is the reason for adding this c.Accounts__r.Name!=old.Account__r.Name but it is not working giving me Compile Error: Invalid foreign key relationship: Contact.Accounts__r
Please help me resolve this issue.
Thanks
Abraham
Try with the above code. Field should be Account__r, you have used like Accounts__r. This may be the issue. Please check the object api name.
Sorry for that.. It is Account__r But still im getting same error.
Thanks
Abraham
Now, it will allow you to save. But it returns null. So you may need to query account.
c.AccountID ==old.AccountID
instead of not equal.
This is getting saved but the when the account name is edited the trigger is not firing. Any idea y this is hapenning.
I want the trigger to fire when the account name is edited. It is working well when the account is changed ie AccountID is different but is not working when name of account is edited.ie) i want it to fire when name of account is edited the related contacts to that account get changed thats when it should fire
Many Thanks
Abraham
Firstly modify your code like this c.AccountID ==old.AccountID. And use '&&' (and) operation in 'If condition'.So it will work.If you still have problem don't hesitate to discuss.
Im not able to follow, can you please explain more briefly.
Many Thanks
Abraham
Since Account is a lookup field so in trigger it will only be identified by its Id unless you fire a SOQL on it and fetch name from Account.
So i would suggest you to please update the code as below : It will cover both of your cases as chnaging the name of Account will automatically change its ID.
Please try with above code and let me know if you have any issue.
Thanks,
Abhishek
It Fires when the the account ID is changed, But editing the account name does not change the account id it changes the account name for all related contacts but does not changes the ID so its not firing.
thanks
Abraham
Please let me know whther you are using Custom field Account Name in your Contact oblject or not ?
If yes, than please share its API name.
Thanks,
Abhishek
It is not possible to provide you a solution right here.
It would be good if you can contact me on either gmail or Skype because what you are saying is looking strange to me, so we need to have a look at ur ORG.
Gmail : abhihske.bansal@metacube.com
Skype : abhishek.bansal2790
Thanks,
Abhishek.
I have resolved this now by writing a trigger on the account object to trigger when account names are edited. As it is not able to be done from contact
many thanks
Abraham
Nice to here that.But next make sure your question should be more clear.Because there is no clarity on which object you written trigger.
Hi Hari,
Im Sorry the question was not clear to you i guess i have given the heading of this topic as "Compile Error: Invalid foreign key relationship: Contact.Accounts__r" which is clear that it is contact object.
Thanks
Abraham