You need to sign in to do that
Don't have an account?
Albert Raul
Help me with the error.
public class FindOpp {
public static void function(){
Date sDate = Date.today().addMonths(-1);
Date eDate = Date.today();
List<Account> accList = [SELECT Id, Name, (SELECT Id FROM Opportunity WHERE IsClosed = true AND StageName = 'Closed Won' AND CloseDate >= :sDate AND CloseDate <= :eDate) FROM Account];
List<Account> AccountData = new List<Account>();
for (Account acc : accList) {
if (acc.Opportunities.size() >= 10) {
AccountData.add(acc);
}
}
for (Account acc : AccountData) {
system.debug(acc.Name);
}
}
}
ERROR at Row:1:Column:34 Didn't understand relationship 'Opportunitiy' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
public static void function(){
Date sDate = Date.today().addMonths(-1);
Date eDate = Date.today();
List<Account> accList = [SELECT Id, Name, (SELECT Id FROM Opportunity WHERE IsClosed = true AND StageName = 'Closed Won' AND CloseDate >= :sDate AND CloseDate <= :eDate) FROM Account];
List<Account> AccountData = new List<Account>();
for (Account acc : accList) {
if (acc.Opportunities.size() >= 10) {
AccountData.add(acc);
}
}
for (Account acc : AccountData) {
system.debug(acc.Name);
}
}
}
ERROR at Row:1:Column:34 Didn't understand relationship 'Opportunitiy' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
You should use Opportunities in sub query instead of Opportunity in sub query if you want to avoid this problem.
use this code
Please mark it as best answer if it helps you
Thanks
To fix the error, update the relationship name in the query from "Opportunitiy" to "Opportunities" as follows: By making this adjustment, the query should recognize the correct relationship and allow you to retrieve the desired information.
If this helps , please mark this as Best Answer.
Thank you.
The error you're encountering is due to a typo in your SOQL query. The object name should be 'Opportunities', not 'Opportunitiy'.
Here is the corrected code:
public class FindOpp {
public static void function(){
Date sDate = Date.today().addMonths(-1);
Date eDate = Date.today();
List<Account> accList = [SELECT Id, Name, (SELECT Id FROM Opportunities WHERE IsClosed = true AND StageName = 'Closed Won' AND CloseDate >= :sDate AND CloseDate <= :eDate) FROM Account];
List<Account> AccountData = new List<Account>();
for (Account acc : accList) {
if (acc.Opportunities.size() >= 10) {
AccountData.add(acc);
}
}
for (Account acc : AccountData) {
system.debug(http://acc.Name);
}
}
}
This code is doing the following:
Remember to always double-check the object and field names in your SOQL queries to avoid such errors.