You need to sign in to do that
Don't have an account?
Atul Shendge 2
We can’t find the correct results format. Make sure that your concatenation puts each list item in this format: 'Account Name' : 'Account Revenue'.
Hi,
I was doing the trailhead challenge on "Create SOQL Queries in Apex Classes"
Create a class
Name: AccountUtility
Create a method
Name: viewAnnualRevenue
Keywords: public, static, and void
Create a list
Name: accountsList
Create a query and assign the results to a list
Fields: Name and annual revenue (Hint: Use API names, not field names or labels)
Object: Account
Create a for loop that iterates through the query results
Object: Account
List name: accountsList
For each item, concatenate the account name, followed by a colon, followed by the account’s annual revenue: <account name> : <annual revenue>
Store the concatenated string in a variable named acctRev
Print the acctRev variable to the debug log:
I have written a code below:
public class AccountUtility {
public static void viewAnnualRevenue (){
List<Account> accountsList = [SELECT Name, AnnualRevenue FROM Account];
for(Account acc: accountsList){
//Looping the class through the query
String name = '<Account Name>: ' + acc.Name +', <Annual Revenue> : ' + acc.AnnualRevenue;
system.debug(name);
}
}
}
I am getting an error while passing the challenge "We can’t find the correct results format. Make sure that your concatenation puts each list item in this format: 'Account Name' : 'Account Revenue'."
Help would be appreciated.
Regards,
Atul Shendge
I was doing the trailhead challenge on "Create SOQL Queries in Apex Classes"
Create a class
Name: AccountUtility
Create a method
Name: viewAnnualRevenue
Keywords: public, static, and void
Create a list
Name: accountsList
Create a query and assign the results to a list
Fields: Name and annual revenue (Hint: Use API names, not field names or labels)
Object: Account
Create a for loop that iterates through the query results
Object: Account
List name: accountsList
For each item, concatenate the account name, followed by a colon, followed by the account’s annual revenue: <account name> : <annual revenue>
Store the concatenated string in a variable named acctRev
Print the acctRev variable to the debug log:
I have written a code below:
public class AccountUtility {
public static void viewAnnualRevenue (){
List<Account> accountsList = [SELECT Name, AnnualRevenue FROM Account];
for(Account acc: accountsList){
//Looping the class through the query
String name = '<Account Name>: ' + acc.Name +', <Annual Revenue> : ' + acc.AnnualRevenue;
system.debug(name);
}
}
}
I am getting an error while passing the challenge "We can’t find the correct results format. Make sure that your concatenation puts each list item in this format: 'Account Name' : 'Account Revenue'."
Help would be appreciated.
Regards,
Atul Shendge
I just completed the challenge with the following code. Can you try the same and let me know if it helps?
Anudeep
All Answers
I just completed the challenge with the following code. Can you try the same and let me know if it helps?
Anudeep
Yes, I missed to enter acctRev in String.
Thanks for your help
Regards,
Atul Shendge
Try this code:
public class AccountUtility {
public static void viewAnnualRevenue(){
List<Account> accountsList = [SELECT Name, AnnualRevenue FROM Account];
for (Account acc : accountsList){
String acctRev = acc.Name + ' : ' + acc.AnnualRevenue;
system.debug(acctRev);
}
}
}