+ Start a Discussion
Chait_SFDCChait_SFDC 

Can we create records in Site object using Apex Test class?

I have an Apex class that has "Site site = [select Id from Site limit 1];". I wrote a test class but my test class is failing because there are no sites defined in my sandbox organization. The question is, can we create a dummy site using a test class so it gets deleted automaitcally? If yes, can someone give me sample code on how to do that? Thanks in advance for all your help.

Regards
Chait
Best Answer chosen by Chait_SFDC
Sonam_SFDCSonam_SFDC
Hi Chait, this would not be possible as Site object is a read only object to query or retrieve information on your Force.com site.

reference: https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_site.htm

All Answers

Sonam_SFDCSonam_SFDC
Hi Chait, this would not be possible as Site object is a read only object to query or retrieve information on your Force.com site.

reference: https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_site.htm
This was selected as the best answer
Chait_SFDCChait_SFDC
Thanks Sonam, that's what I thought too.