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
Atul Shendge 2Atul 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
Best Answer chosen by Atul Shendge 2
AnudeepAnudeep (Salesforce Developers) 
Hi Atul, 

I just completed the challenge with the following code. Can you try the same and let me know if it helps? 
public class AccountUtility {
        public static void viewAnnualRevenue(){
        List<Account> accountsList= [SELECT Name, AnnualRevenue FROM Account];
        for(Account acc : accountsList){
            String acctRev = 'account name: ' + acc.Name + ', Annual Revenue: ' + acc.AnnualRevenue;
            system.debug(acctRev);
        }
 }
}

Anudeep

All Answers

AnudeepAnudeep (Salesforce Developers) 
Hi Atul, 

I just completed the challenge with the following code. Can you try the same and let me know if it helps? 
public class AccountUtility {
        public static void viewAnnualRevenue(){
        List<Account> accountsList= [SELECT Name, AnnualRevenue FROM Account];
        for(Account acc : accountsList){
            String acctRev = 'account name: ' + acc.Name + ', Annual Revenue: ' + acc.AnnualRevenue;
            system.debug(acctRev);
        }
 }
}

Anudeep
This was selected as the best answer
Atul Shendge 2Atul Shendge 2
Hi Anudeep,

Yes, I missed to enter acctRev in String.

Thanks for your help
Regards,
Atul Shendge
Lukesh KarmoreLukesh Karmore
Atul and anudeep this code shows me error
Spencer_BerkSpencer_Berk
@Lukesh,
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);
        }
    }
}

 
Keny PatidarKeny Patidar
Using this code, but getting error.

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);
        }
    }
}