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
DesaiDesai 

Error while using Address object

Hi,

we have a requirement to display the address in a lightning page. To acheive this , when we query on apex controller we are gettign this error.
CODE:
public class AddressController 
{
    @AuraEnabled
    public static List<Address> getAddData{
       List<Address> getAddData = [SELECT Id FROM Address ];
        return getAddData;
    }

}

ERROR:
1) AuraEnabled methods do not support return type of List<System.Address>
2) Illegal assignment from List<Address> to List<System.Address>


Regards,
Desai
Best Answer chosen by Desai
Khan AnasKhan Anas (Salesforce Developers) 
Hi Desai,

Greetings to you!

“Address” in Salesforce can also refer to the Address compound field found on many standard objects. When referencing the Address object in your Apex code, always use Schema.Address instead of Address to prevent confusion with the standard Address compound field. If referencing both the address object and the Address field in the same snippet, you can differentiate between the two by using System.Address for the field and Schema.Address for the object.
 
@AuraEnabled
    public static List<Schema.Address> getAddData(){
        List<Schema.Address> getAddData = [SELECT Id FROM Address ];
        return getAddData;
    }

Please refer to the below links which might help you further with the above requirement.

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_address.htm

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/compound_fields_address.htm

I hope it helps 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. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Desai,

Greetings to you!

“Address” in Salesforce can also refer to the Address compound field found on many standard objects. When referencing the Address object in your Apex code, always use Schema.Address instead of Address to prevent confusion with the standard Address compound field. If referencing both the address object and the Address field in the same snippet, you can differentiate between the two by using System.Address for the field and Schema.Address for the object.
 
@AuraEnabled
    public static List<Schema.Address> getAddData(){
        List<Schema.Address> getAddData = [SELECT Id FROM Address ];
        return getAddData;
    }

Please refer to the below links which might help you further with the above requirement.

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_address.htm

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/compound_fields_address.htm

I hope it helps 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. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
DesaiDesai
Thanks Khan.

Regards,
Desai