You need to sign in to do that
Don't have an account?
Brittanie
Trigger to autopop custom lookup on account from custom lookup on opportunity
I'm learning as I go with this but have successfully manipulated a good 5 triggers. Can't seem to figure this one out and besides necessary it is also the solution to why a workflow that works fine in sadbox wont let me save without this field on the account filled in on my live sf. I apologize after about 80 rounds and trying to manipulate off other posts the syntax my be destroyed!
Account
Contact_Declining__c
needs to be updated from the Primary_Contact__C on the Opportunity.
Trigger UpdateContactDeclining on Account(before insert, before update) { Set<id> OpportunityIds = new Set<id>(); for (Account a : Trigger.new) { OpportunityIds.add(a.Contact_Declining__c ); } Map<Id, Opportunity> OpportunityContactMap = new Map<id, Opportunity>( [SELECT Id,Primary_Contact__c FROM Opportunity WHERE Id IN :OpportunityIds]); for (Account a: Trigger.new) { if (a.Contact_Declining__c == null && OpportunityContactMap .containsKey(a.Opportunity )) { a.Contact_Declining__c = OpportunityContactMap.get (Opportunity.Primary_Contact__c); } } }
You never made an update to Account that was queried
All Answers
Firstly an account can be the parent of many opportunities. How do u want to choose the one child opportunity which will be used to populate the custom look up on parent Account ?
Our company only has one opportunity at a time for an account. also the field updates allow you to pull from opp to act but not on lookups.
And both these lookups are to Contact so the following code should help u :
One more thing this functionality is not relevant to account insert , because you will not have any opportunities which are already related to the accounts to be inserted.
hmmm. i looks good and no errors... however the end result is the field still not updating... I'm honestly at a loss as it looks to cover everything and the fields are correct.
Try looking at the Debug logs. There might be some other process interfering.
As per My Understanding you want to bring "Primary_Contact__c" from Opp to Account "Contact_Declining__c"
how about moving the triggers to Opportunity ?
Whenever you will be doing an update the changes will be on Opportunity object and not in the Account.
So it makes sense to have a trigger on Opportunity rather than account.
So I've put together a trigger for the opportunity that I thought was great and saved with no problem... but when I try and add a primary contact to the opportunity I get the following very scarry error and it won't let me save.
Since this seems like such a simple task this is becoming increasingly irratating that I can't seem to get it to work! (probably due to the fact I am very new at this.)
Fixed the code to be able to save the Primary_Contact_c in the opportunity but it still doesn't update the Contact_Declining__c on the Account...
I should also add that some how on the account trigger under field dependencies it checks the right field under account to be updated but the object itself isn't checked to be updated... I know that it should be, I'm just not sure how to make that happen
Now I have codes both ways that say they are supposed to do what I want but without the final result enacted.
You never made an update to Account that was queried
back to getting the error
This one you have to solve.
the "Contact_Declining__c" field has a lookup filter added and the record value you are setting is not satisfying the filter condition
yup, I'm a big dork! works like a charm.
Thanks for the help!
question on the test as it is a lookup... what would I put for Primary_Contact__c= (??)
Currently getting the following error
Error Message System.StringException: Invalid id: Contact Stack Trace
Class.UpdateAcctContactDecliningTestClass.myUnitTest: line 14, column 1