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

Query to get opportunities from custom object?
Hi,
I have 3 objects:
Opportunity
Pro__c
Unc__c
(Pro__c and Unc__c has lookup to opportunities)
To get unc__c values from Opportunities i am using this query,
select name from opportunity where unc__r.id='idvalue'
can I query from Unc__c to get opportunities??
If so, How?
I have 3 objects:
Opportunity
Pro__c
Unc__c
(Pro__c and Unc__c has lookup to opportunities)
To get unc__c values from Opportunities i am using this query,
select name from opportunity where unc__r.id='idvalue'
can I query from Unc__c to get opportunities??
If so, How?
Try it...
hope this works....
All Answers
Yes you can query Unc__c to get Opportunity.
Here is an example of the query:-
select Id, Opportunity__r.name from unc__c
Thanks,
Meenu Mathew
Use this query,
Querying from child record:
select id,name,opportunity__r.name,opportunity__r.id from unc__c
Querying from master record:
select id,name,(select id,name,opportunity__c from uncs__r) from opportunity
Hope this helps..
for both the answers I am getting this error
Didn't understand relationship 'opportunities__r' in field path.
Use your relationship field's API name, replace '__c' with ' __r' ,that will be your relationship name. For eg : If lookup field name is 'opportunity__c', then use 'opportunity__r' in query.
'opportunities__r' is used for retrieving field values from the unc__c's related Opportunity object when these objects have relationship via Lookup field.
If Opprtunity is your related object, then for retriving Opportunity's fields we use 'opportunities__r' in query,
Thanks
I tried all of the above options but the Error didn't go.
while I was checking how they gave relations, I found this:
If I am trying to create a new Opp record.
> Pro__c has lookUp
AND
Unc__c is a depends on Pro__c.
by any chance this is creating error?
Try this,
select id,name,(select id,name,unc__c from Opportunities__r) from unc__c
Let me know if its works!
This is giving required result when I do query from Developer console,
but when I add this query to class it just giving pro__c Name.
any idea where I may be going wrong?
Can you share your apex code, so that I can help.Also please specify your context...
Please have a look at the following code. Hope this will help you.
public class UncCls {
public static void getOpportunities()
{
List<Unc__c> uncList = new List<Unc__c>();
List<Opportunity> oppList = new List<Opportunity>();
set<Id> oppIdSet = new set<Id>();
uncList = [SELECT id,Name,Opportunity__c FROM Unc__c LIMIT 1000];
for(Unc__c uncObj : uncList)
{
oppIdSet.add(uncObj.Opportunity__c);
}
if(oppIdSet != null)
{
oppList = [SELECT Id, Name FROM Opportunity WHERE id IN:oppIdSet];
if(oppList.size() > 0)
{
for(Opportunity oppObj : oppList)
system.debug('Opp Name :' + oppObj.Name);
}
}
}
}
Thank You
Ajay Dubedi
It's works as required
But I want to add Opportunities as column.
Try it...
hope this works....
Thankyou So much!!
you saved 100 hairs on my head!!
There was little bit of Css work needed but am able to achieve the requirement.
Thanks a ton!!