You need to sign in to do that
Don't have an account?

Creating an Apex class that return Account objects challenge?
I am having issues with Creating an Apex class that returns Account objects for the Mapping.net concepts challenge. I am a VB and Javascript programmer and I can't seem to get the syntax right.
public class AccountUtils {
public static void accountsByState(String st){
List<String> accts = [SELECT Id, Name FROM Account WHERE billingState = :st];
}
}
I believe the first part is correct, but I cannot seem to get a return value. I am confused by the constructors. I have tried the documentation but I can't get a return value. Please help. I need to get this challenge complete.
public class AccountUtils {
public static void accountsByState(String st){
List<String> accts = [SELECT Id, Name FROM Account WHERE billingState = :st];
}
}
I believe the first part is correct, but I cannot seem to get a return value. I am confused by the constructors. I have tried the documentation but I can't get a return value. Please help. I need to get this challenge complete.
You can try this:
Please look into the below useful links:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining_methods.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_static.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining.htm
http://www.tutorialspoint.com/apex/apex_methods.htm
Please do let me know if it helps you.
Regards,
Mahesh
All Answers
You can try this:
Please look into the below useful links:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining_methods.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_static.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining.htm
http://www.tutorialspoint.com/apex/apex_methods.htm
Please do let me know if it helps you.
Regards,
Mahesh
Regards,
Mahesh
Regards,
Mahesh
I'm pretty new to the development arena myself and I was having issues on how to proceed on this module. I thank you Mahesh for providing some guidance and Susan for posting the question. I'm in the learning and knowing phase here lol.
Try this code, it works for me.
Hope this helps!!
When I looked into the page layout of the Account object its seen that oly 'Account Name' is a required field and also i dont have any validation rule that is active which could be possibly causing this error.
Kindly Help ?
Regards,
Kavya.N
Unable to view your Error Message.Can you check for Tiggers on Account object which are in active mode?
If it is in active mode then de activate it and try to verify the challenge.
Thanks,
Kishan
Try Bellow Code
it may helps you:
public class AccountUtils {
public static List<Account>accountsByState(String st){ List<Account> acctList =[SELECT Id, Name FROM Account WHEREbillingState = :st];
return acctList;
}
}
public static List<Account> accountsByState (String accountState){
List<Account> searchedResults = [SELECT Name FROM Account WHERE BillingState= :accountState];
return searchedResults;
}
}
This works fine for me
public static list<Account> accountsByState (String state){
list<Account> act=[select ID, Name from account where BillingState=:state];
return act;
}
}
Executing the 'accountsByState' method on 'AccountUtils' failed. Make sure there are no required fields other than Name for the Account object, the method exists with the name 'accountsByState', is public and static, accepts a String and returns a List of Account objects.
I was having a similar issue. It solved after I saved my class in the Dev Console. (Go to File -> Save)
Hi Everyone I just use the same code as above but when I check following errors popped out:
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, A country/territory must be specified before specifying a state value for field: [BillingState]
My class is as follows:
public class AccountUtils {
public static List<Account> accountsByState(String stateAbr) {
List<Account> listOfAccounts = [Select Id, name from Account where BillingState = :stateAbr];
return listOfAccounts;
}
}
Is there any problem with my environment or something? Thanks!
Thank you!!
Hello again, I have managed to solve the KO, in the end I had to create another (Trailhead Playground).
Best regards.
1. I couldn't find the Billing state field in accounts object why?
2. How to test this is working as expected(can anyone provide the debug code) in dev console.
Illegal assignment from List<Account> to List<Account>