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
Lukesh KarmoreLukesh Karmore 

Trailhead challenge "create SOQL query with apex code"

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 write a code that shows me error
public class AccountUtility{
Public static void viewannualRevenue() {
List<Account>  accountlist = [ SELECT Name , annual Revenue From Account];
for(Account acc : accountlist){
string  accRev='<account name>: ' +acc.name+ , '<annual revenue>: ' +acc.annualrevenue;
System.debug(accRev);
}
}
}
thxx for help..
ANUTEJANUTEJ (Salesforce Developers) 
Hi Lukesh,

Greetings!

There is a separate Trailhead team who can help you with these issues. So, can you please use the below link to reach out to them so that one of the agents will get in touch with you.

Support:https://trailhead.salesforce.com/help

Thank you!

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Warm Regards,
Anutej
Lukesh KarmoreLukesh Karmore
Anutez ,
Not helpful i want to complete challanges ,so anyone clear error ...here.
ANUTEJANUTEJ (Salesforce Developers) 
Try checking this line string  accRev='<account name>: ' +acc.name+ , '<annual revenue>: ' +acc.annualrevenue; as mentioned in the instructions 
 <account name> : <annual revenue> instead of writing it in braces you will have to have the name so it would be acc.name followed by a colon ':' then the revenue acc.revenue 

Going Forward please be advised that this community is focused on Salesforce technical discussions where the forums and participants are geared toward programming troubleshooting and support. 

I would request you to try them and check the instructions once.

Regards,
Salesforce Support
Lukesh KarmoreLukesh Karmore
It shows error , anutej
ANUTEJANUTEJ (Salesforce Developers) 
So you will have to make a change to the above line and run the method from the anonymous window so you will have to call the static method as classname.meethod_name();

if the name of the class id accdebug and name of the method is deb then in the anonymous window it would be accdebug.deb() 

And change the line to make sure it displays like below:

if the account name is test and the revenue is 200 then in the debug log it should be test:200 but as per your implementation it would be printing 
<account name>: test,  '<annual revenue>: 200

to concatenate two strings use the words in quotes with +.

you are getting the above error because you are writing , in the string you are concatinating you will have to put them in quotes to print them ',' but you are simply putting a ,
Shailaja GeelaShailaja Geela
Passed with this:

public class PropertyUtility 
{
    public static void newListedProperties()
    {
        List<Property__c> newPropList=[SELECT Name,Broker__r.Email__c,Days_On_Market__c FROM Property__c where Days_On_Market__c<=30];
        string propEmail='';
        for(Property__c proplist:newPropList)
        {
            propEmail=propEmail+proplist.Name+' : '+proplist.Broker__r.Email__c;
        }
        system.debug(propEmail);
            
    }
}
sravani proddatur 10sravani proddatur 10
Hi Lukesh,
public class AccountUtility {
    public static void viewAnnualRevenue(){
        
        
        List<Account> accountsList = [SELECT Name,AnnualRevenue FROM Account];
        String acctRev;
        
        for(Account acc : accountsList){
            acctRev = acc.name + ':' +acc.annualrevenue;
            system.debug(acctRev);
            
        }
        
        
    }

}

Thank you
I hope this code helps to you..If u Likes the answer  please select as a best answer..