You need to sign in to do that
Don't have an account?
Didn't understand relationship 'Opportunities' error
Hello,
I am writting a trigger to rollup a field (Type) from the Opportunity object on Account. I get the error "Didn't understand relationship 'Opportunities' error". I am out of ideas. Any clue?
trigger UpdateMembershipType on Opportunity (after delete, after insert, after update) { set<ID> orgIDs = new Set<ID>(); if(Trigger.isInsert) { for(Opportunity o : System.Trigger.new){ orgIDs.add(o.AccountId); } Organization[] orgs = new List<Organization>(); orgs = [select Id, (select Type, RecordType.Name from Opportunities where IsWon = TRUE order by CloseDate Desc limit 1 ) from Organization where ID in :orgIDs ]; Opportunity[] os = new List<Opportunity>(); Map<Id, Opportunity[]> orgopp = new Map<Id, Opportunity[]>(); for (Organization eachOrg: orgs){ orgopp.put(eachOrg.Id, eachOrg.Opportunities); } Organization[] updatedOrganizations = new List<Organization>(); Opportunity[] opps = new List<Opportunity>(); for (Organization o : orgs ){ opps=orgopp.get(o.Id); for(Opportunity opty : opps) { o.Type__c=opty.Type; } updatedOrganizations.add(o); } if(updatedOrganizations.size()>0) {update updatedOrganizations;}}
Thanks!
Pierre
Hey
This line assumes Opportunity and Organization objects are related.
[select Id, (select Type, RecordType.Name from Opportunities where IsWon = TRUE order by CloseDate Desc limit 1 ) from Organization where ID in :orgIDs ];
Have you created this relationship? Because it doesn't seem to be standard.
You could however do something like this:
select id, (select id from opportunities) From account
Perhaps I've misunderstood your question, if so please could you give a bit more info.
Cheers,
Wes
All Answers
Hey
This line assumes Opportunity and Organization objects are related.
[select Id, (select Type, RecordType.Name from Opportunities where IsWon = TRUE order by CloseDate Desc limit 1 ) from Organization where ID in :orgIDs ];
Have you created this relationship? Because it doesn't seem to be standard.
You could however do something like this:
select id, (select id from opportunities) From account
Perhaps I've misunderstood your question, if so please could you give a bit more info.
Cheers,
Wes
Very good point. Account was renamed Organization and I did pay attention. Plus Eclipse did throw an error on the object name so I completly missed that. Thanks, it works now!
Pierre