How to get a subquery field value using Apex?

List<Account> acct = new List<Account>();

String sql = 'SELECT Name,Phone,External_ID__c,Type,Industry,AccountNumber,Description,FAX,SLA__c,Rating,(SELECT Name,StageName,CloseDate,Probability FROM Opportunities) FROM Account WHERE ID=:localId';

acct = Database.Query(sql);
       
        for(Account ac:acct)
        {
            List<Opportunity> opptys = new List<Opportunity>();
            opptys = ac.getSObjects('Opportunities');
            for(Opportunity opt:opptys)
            {
            }
        }


Cheers!!!

No comments:

Post a Comment