function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Girish Reddy 52Girish Reddy 52 

Hello Can someone help me with this code, I'm getting error since 2hrs unable to solve this. I tried it on developer console Anonymous window the error say that Line: 1, Column: 5 Unexpected token '<'.

List<Account> Aop = [Select Name (Select Name, StageName From Opportunites) From Account];
    
for(Account acc : Aop){
    system.debug('Parent '+ acc.name);
    
    for(Opportunity opp: acc.opportunity){
        system.debug('Child '+ opp.Stagename);
    }
}
Best Answer chosen by Girish Reddy 52
Shatrughna SalunkeShatrughna Salunke

Please change your code as per the highlighted line.

List <Account> listOfAccount = [SELECT Name, (SELECT Name, StageName FROM Opportunities) FROM Account];
for(Account acc : listOfAccount){
    system.debug('Parent '+ acc.name);
    for(Opportunity opp: acc.Opportunities){
        system.debug('Child '+ opp.Stagename);
    }
}

Regards,
Shatrughna Salunke

All Answers

VinayVinay (Salesforce Developers) 
Try below snippet.
 
List <Account> Aop = [Select Name, (Select Name, StageName From Opportunities) From Account];
    
for(Account acc : Aop){
    system.debug('Parent '+ acc.name);
    
    for(Opportunity opp: acc.opportunity){
        system.debug('Child '+ opp.Stagename);
    }
}

Please mark as Best Answer if above information was helpful so that it can help others in the future.

Thanks,
Shatrughna SalunkeShatrughna Salunke

Please change your code as per the highlighted line.

List <Account> listOfAccount = [SELECT Name, (SELECT Name, StageName FROM Opportunities) FROM Account];
for(Account acc : listOfAccount){
    system.debug('Parent '+ acc.name);
    for(Opportunity opp: acc.Opportunities){
        system.debug('Child '+ opp.Stagename);
    }
}

Regards,
Shatrughna Salunke

This was selected as the best answer