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
angela mullen-smith 18angela mullen-smith 18 

build conference app - test code for the Controller

I am getting myself confused here - I have built the App and my hotels are displaying on the Google map which is fab, but I now want to transfer it into Production and I appreciate that I need to test the Controller.

Am I testing that I can create a new record in my custom object?

OR

Am I testing that a new visualforce page is created
Best Answer chosen by angela mullen-smith 18
Amit Chaudhary 8Amit Chaudhary 8
Please try below code
@isTest 
public class FacilityRemoterTest 
{
    static testMethod void testMethod1() 
	{
		Facility__c obj = new Facility__c();
		// add all required field;
		insert obj;
		
		List<Facility__c> lstFac =FacilityRemoter.FindAll();
		//System.assert(lstFac!= null);
    }
}
Let us know if this will help you
 

All Answers

angela mullen-smith 18angela mullen-smith 18
This is my Controller
User-added image

The example in the Visualforce Developer Guide is confusing.

Am I testing that I bring back a list of records or am I testing that I bring back my visualforce page

<apex:page sidebar="false" showheader="false" controller="FacilityRemoter">
 
 
<head>
 
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0; padding: 0 }
  #map-canvas { height: 100% }
</style>
<script src="https://maps.googleapis.com/maps/api/js?key= AIzaSyC3GwkxsiGHfc0y5sheupDf7QzKtbFI4jg&region=AU">
 
</script>
<script>
var map;
function initialize() {
    var mapOptions = {
        center: new google.maps.LatLng(-16.45789579, 145.3789838),
        zoom: 15
    };
    map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
    loadFacilities();
}
function loadFacilities() {
    Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.FacilityRemoter.findAll}',
        function(result, event){
            if (event.status) {
                for (var i=0; i<result.length; i++) {
                    var id = result[i].Id;
                    var name = result[i].Name;
                    var lat = result[i].Location__Latitude__s;
                    var lng = result[i].Location__Longitude__s;
                    addMarker(id, name, lat, lng);
                }
            } else {
                alert(event.message);
            }
        },
        {escape: true}
    );
}
function addMarker(id, name, lat, lng) {
    var marker = new google.maps.Marker({
            position: new google.maps.LatLng(lat, lng),
            map: map,
            title: name
    });
    google.maps.event.addListener(marker, 'click', function(event) {
        window.top.location = '/' + id;
    });
}
 
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
  <div id="map-canvas"/>
</body>
</apex:page>
 
Amit Chaudhary 8Amit Chaudhary 8
Please try below code
@isTest 
public class FacilityRemoterTest 
{
    static testMethod void testMethod1() 
	{
		Facility__c obj = new Facility__c();
		// add all required field;
		insert obj;
		
		List<Facility__c> lstFac =FacilityRemoter.FindAll();
		//System.assert(lstFac!= null);
    }
}
Let us know if this will help you
 
This was selected as the best answer
angela mullen-smith 18angela mullen-smith 18
@Amit Chaudhary

Thank you - that makes it easier to understand. I am in effect testing the Controller Extension rather than the ability to create the Visual force page.
One more question if you don't mind.
When I test it in the Developer Console - I have 100%
User-added image

It says that I have no Code coverage %