You need to sign in to do that
Don't have an account?
Get opportunity and its related list
Hi,
I m trying to get Opportunity data and all its related list in a .Net Application. I have added Salesforce web reference in .Net application and using following query to get it.
List<Opportunity> listopportinities = new List<Opportunity>();
string orsql = @"SELECT
opr.OwnerId, opr.Complete_Itinerary_Information__c
FROM Opportunity opr where opr.Id ='" + opportunityId + "'";
listopportinities = api.GetOpportunities(orsql);
E_Ticket__c is related list in opportunity, and i have around 10 such lists. I get it like this
orsql = @"select Name, Passenger_Name__c, E_Ticket__c, Airline__c
From E_Ticket__c where Opportunity__c = '" + opportunityId + "' order by Name asc ";
List<E_Ticket__c> listEt = api.GetETickets(orsql);
ViewBag.ETickets = listEt;
I don't want to execute seperate SOQL for each related list.
Is there any better way to get Opportunity data and all its related list in one SOQL query?
Thanks for any help.
Hi,
You can use the parent-to-child SOQL query for getting the E_Ticket__c.
For more detail follow the below link:
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Using following query i m able to get Opportunity and Related list in single query
List<Opportunity> listopportinities = new List<Opportunity>();
string orsql = @"SELECT
opr.OwnerId,
(select Name, Passenger_Name__c, E_Ticket__c, Airline__c
From E_Ticket_s__r)
FROM Opportunity opr
where opr.Id ='" + opportunityId + "'";
listopportinities = api.GetOpportunities(orsql);
listopportinities.FirstOrDefault().E_Ticket_s__r shows two records now,
do you know how to use E_Ticket_s__r object to get all its fileds?