I'm trying to write a test class for this class but not sure how to provide code coverage for what I'm doing here. In my class I'm just running a query, looping through the query and creating a list with some other info in the list. In my VF page, I then loop through this list to display the data. I'm not sure how to cover this in the test class. Below is my attempt to do it, but I'm running into a couple of errors:

1st error: Line 16: Static method cannot be referenced from a non static context: List AccountLocation.getAccount()

2nd error: Line 17: Variable does not exist: Location

This is my class (which is a controller for a VF page)

public class AccountLocation {
    public static List<Location> getAccount() {
        List< Account> accs =  [Select Id, Name,Type, Industry, BillingAddress,BillingStreet,
                                BillingCity, BillingCountry, BillingPostalCode,
                                BillingState,Phone from Account ] ;

        List<Location> loc = new List<Location>();
        for(Account acc :accs){
            Location locDetail = new Location();
            locDetail.icon = 'action:map'; 
            locDetail.title = acc.Name;
            locDetail.description = '<strong>Location Name: ' + acc.Name + '</strong>' +
                                    '<br/><br/>Last Inspection Date: ' + acc.Industry + 
                                    '<br/><br/>Next Inspection Date: ' + acc.BillingCity +
                                    '<br/><br/><a target=_blank href=https://' + System.URL.getSalesforceBaseURL().getHost() + '/' + acc.Id + '>View Account</a>';

        return loc ;
    public class Location{
        public String icon{get;set;} 
        public String title{get;set;} 
        public String description{get;set;} 

This is my test class

public class AccountLocation_UT {

    public static testmethod void AccountLocation_UT(){
        List<Account> acc=new List<Account>();
        for(Integer i=0;i<200;i++){
            Account l=new Account();
        insert acc;

            AccountLocation accloc = new AccountLocation();
            accloc.Location.latitude = 96.23040;

        List<Account> accList = [SELECT id, Name, Description FROM Account];
        system.assertEquals(accList[0].Name, 'Name0');
        system.assertEquals(accList[0].Description, 'Description0');


Thank you for the assistance.


Try to instantiate the class directly:

AccountLocation accloc = new AccountLocation();


You should be able to access the wrapper Location class with

Location loc = new Location(); 
loc.latitud = 96.23040;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.