• DDay
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 14
    Replies

Hello,

 

I have the following method which gets some XML from a web service call, parses through the data and passes it on for display in a VF page. I have everything working as I need it to but don't know how write a test case for it. I've tried writing a test case that uses bogus data and compares that to this method but it still complains that every line is not being covered. Any help?

 

 

public class UserConference {
public String usr_conference_id { get; set; }
public String conference_name { get; set; }
}

public List<Conference.UserConference> getConferenceData(HttpResponse res) {
XMLDom responseXML = new XMLDom(res.getBody());

UserConference[] conference_list = new UserConference[0];
all_conferences = responseXML.getElementsByTagName(xml_search_tag);

for (Integer i=0; i < all_conferences.size(); i++) {
UserConference conference = new UserConference();

child_nodes = all_conferences.get(i).childNodes;
for (Integer c=0; c < child_nodes.size(); c++) {
conf_element = child_nodes.get(c);
if (conf_element.nodeName == 'usr_conference_id') conference.usr_conference_id = conf_element.textContent();
if (conf_element.nodeName == 'conference_name') conference.conference_name = conf_element.textContent();
conference_list.add(conference);
}
return conference_list;
}

 

Thanks,

Dan

 

 

  • July 01, 2009
  • Like
  • 0
Hello,
 
I have a method that returns a List<SelectOption> containing a list of months to be used in a menu on a VF page. I'm still new to writing Apex code and I can't figure out what the correct way to write the test method for this is. If I run tests on the following code I get this error:
 
 

System.Exception: Assertion Failed: Expected: (System.SelectOption[value="01", label="Jan", disabled="false"], System.SelectOption[value="02", label="Feb", disabled="false"], System.SelectOption[value="03", label="Mar", disabled="false"], System.SelectOption[value="04", label="Apr", disabled="false"], System.SelectOption[value="05", label="May", disabled="false"], System.SelectOption[value="06", label="Jun", disabled="false"], System.SelectOption[value="07", label="Jul", disabled="false"], System.SelectOption[value="08", label="Aug", disabled="false"], System.SelectOption[value="09", label="Sep", disabled="false"], System.SelectOption[value="10", label="Oct", disabled="false"], ...), Actual: (System.SelectOption[value="01", label="Jan", disabled="false"], System.SelectOption[value="02", label="Feb", disabled="false"], System.SelectOption[value="03", label="Mar", disabled="false"], System.SelectOption[value="04", label="Apr", disabled="false"], System.SelectOption[value="05", label="May", disabled="false"], System.SelectOption[value="06", label="Jun", disabled="false"], System.SelectOption[value="07", label="Jul", disabled="false"], System.SelectOption[value="08", label="Aug", disabled="false"], System.SelectOption[value="09", label="Sep", disabled="false"], System.SelectOption[value="10", label="Oct", disabled="false"], ...)

 

 

public class Months {

public List<SelectOption> getMonthList() {

List<SelectOption> options = new List<SelectOption>();

options.add(new SelectOption('01', 'Jan'));

options.add(new SelectOption('02', 'Feb'));

options.add(new SelectOption('03', 'Mar'));

options.add(new SelectOption('04', 'Apr'));

options.add(new SelectOption('05', 'May'));

options.add(new SelectOption('06', 'Jun'));

options.add(new SelectOption('07', 'Jul'));

options.add(new SelectOption('08', 'Aug'));

options.add(new SelectOption('09', 'Sep'));

options.add(new SelectOption('10', 'Oct'));

options.add(new SelectOption('11', 'Nov'));

options.add(new SelectOption('12', 'Dec'));

return options;

}

 

static testMethod void testMonthList() {

List<SelectOption> test_options = new List<SelectOption>();

test_options.add(new SelectOption('01', 'Jan'));

test_options.add(new SelectOption('02', 'Feb'));

test_options.add(new SelectOption('03', 'Mar'));

test_options.add(new SelectOption('04', 'Apr'));

test_options.add(new SelectOption('05', 'May'));

test_options.add(new SelectOption('06', 'Jun'));

test_options.add(new SelectOption('07', 'Jul'));

test_options.add(new SelectOption('08', 'Aug'));

test_options.add(new SelectOption('09', 'Sep'));

test_options.add(new SelectOption('10', 'Oct'));

test_options.add(new SelectOption('11', 'Nov'));

test_options.add(new SelectOption('12', 'Dec'));

 

Months my_months = new Months();

List<SelectOption> method_options = my_months.getMonthList();

 

system.assertEquals(method_options, test_options);

}

}

 

I copied/pasted the 'expected' and 'actual' responses to a text editor and they look identical to me. Is there another way I should be writing this test?
 
Thanks,
Dan 
 
 
 
 
  • June 30, 2009
  • Like
  • 0

Hello,

 

I'm creating a select menu that is a list of months Jan-Dec. When my VF page is loaded I'd like the menu to default to the current month (set that option as 'selected'). I know how to get the current month in my apex code but don't know how to combine that in my VF page to set the selected option.

 

Thanks,

Dan 

  • June 25, 2009
  • Like
  • 0

Hello,

 

I'm using the XMLDom class to parse some XML. I'm trying to set a variable to a list of tag names that I can loop through later. What is the correct return type I should set 'names' in the following code to?

 

 

names = responseXML.getElementsByTagName('names');

 

I've tried setting it to List<String> but I get the following error:

 

  Error: Compile Error: Illegal assignment from LIST:XMLDom.Element to LIST:String

 

Thanks,

Dan

  • June 10, 2009
  • Like
  • 0

Hello,

 

Just started using apex and VisualForce last week and I'm trying to get some XML data into a dataTable. I'm able to get the XML and parse it using the XmlStreamReader but I keep getting errors when trying to pass it to the dataTable. Here is my code. For now I'm just trying to get text from the usr_conference_id node but eventually I'd like to get the data from the other nodes.

 

The XML (I'm getting a valid XML doc but removed the header for this post):

 

<meeting>

<usr_conference_id>382718</usr_conference_id>

<conference_name>Test Conf.</conference_name>

<conference_user>Test User1</conference_user>

</meeting>

<meeting>

<usr_conference_id>381084</usr_conference_id>

<conference_name>Test Conf. 2</conference_name>

<conference_user>Test User2</conference_user>

</meeting> 

 

 

<apex:page controller="Conferences">

<apex:dataTable value="{!conferencelist}" var="conf">

<apex:column>

<apex:facet name="header">ID</apex:facet>

<apex:outputText value="{!conf.usr_conference_id}"/>

</apex:column>

</apex:dataTable>

</apex:page> 

 

public class Conferences {

 

public class UserConferences {

String usr_conference_id;

String conference_name;

} // End UserConferences

 

UserConferences[] parseXML(XmlStreamReader reader) {

UserConferences[] conferences = new UserConferences[0];

while(reader.hasNext()) {

if (reader.getEventType() == XmlTag.START_ELEMENT) {

if ('usr_conference_id' == reader.getLocalName()) {

reader.next();

UserConferences conference = new UserConferences();

conference.usr_conference_id = reader.getText();

conferences.add(conference);

}

}

}

return conferences;

} // End parseXML()

 

public List<Conferences.UserConferences> getConferenceList() {

Http http = new Http();

HttpRequest req = new HttpRequest();

req.setEndpoint('https:ADDRESS REMOVED');

req.setMethod('GET');

HttpResponse res = http.send(req);

 

// Generate the HTTP response as an XML stream

XmlStreamReader reader = res.getXmlStreamReader();

List<Conferences.UserConferences> conf_return = parseXML(reader);

return conf_return;

}} // End Conferences

 

When I try to save this in the page editor I get the following error:

 

System.Exception: Too many script statements: 200001

 

Class.Conferences.parseXML: line 21, column 13 Class.Conferences.getConferenceList: line 35, column 60 External entry point 

 

 

Any help would be greatly appreciated!

 

Thanks,

Dan 

 

Message Edited by DDay on 06-07-2009 07:22 PM
  • June 08, 2009
  • Like
  • 0

Hello,

 

I've inherited a project that uses some custom S-Controls. When I log into my dev account and click S-Controls the following message is displayed:

 

"S-controls have been superseded by Visualforce pages. Salesforce will, sometime after January 2010, remove the ability to create and distribute new s-controls. Existing s-controls will be unaffected."

 

Can anyone tell me when this announcement was originally made? The project I'm working on isn't that old so I'm curious to know why the previous dev used S-Controls if they were being deprecated.

 

Thanks,

Dan 

  • June 05, 2009
  • Like
  • 0

Hello,

 

Just started using Apex today and I'm having trouble using List<sObject>. Here is my class:

 

 

public class Settings {

private List<sObject> info;

 

public Settings() {

info = [Select Id, API_Key__c, Password__c, Phone_No__c, Recording_Phone_Number__c, Time_Zone__c from Settings__c];

}

 

public String getKey() {

//String key = [SELECT API_Key__c FROM Settings__C].api_key__c;

String key = info.api_key__c;

return key;

}

}

 

The line commented out in the getKey method works fine. However, trying to use info.api_key__c gives me the following error:

 

   Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST:SObject at line 10 column 22

 

How can I access individual values in the info List object?

 

Thanks,

Dan 

 

 

Message Edited by DDay on 06-04-2009 01:12 PM
  • June 04, 2009
  • Like
  • 0

Hello,

 

I have the following method which gets some XML from a web service call, parses through the data and passes it on for display in a VF page. I have everything working as I need it to but don't know how write a test case for it. I've tried writing a test case that uses bogus data and compares that to this method but it still complains that every line is not being covered. Any help?

 

 

public class UserConference {
public String usr_conference_id { get; set; }
public String conference_name { get; set; }
}

public List<Conference.UserConference> getConferenceData(HttpResponse res) {
XMLDom responseXML = new XMLDom(res.getBody());

UserConference[] conference_list = new UserConference[0];
all_conferences = responseXML.getElementsByTagName(xml_search_tag);

for (Integer i=0; i < all_conferences.size(); i++) {
UserConference conference = new UserConference();

child_nodes = all_conferences.get(i).childNodes;
for (Integer c=0; c < child_nodes.size(); c++) {
conf_element = child_nodes.get(c);
if (conf_element.nodeName == 'usr_conference_id') conference.usr_conference_id = conf_element.textContent();
if (conf_element.nodeName == 'conference_name') conference.conference_name = conf_element.textContent();
conference_list.add(conference);
}
return conference_list;
}

 

Thanks,

Dan

 

 

  • July 01, 2009
  • Like
  • 0
Hello,
 
I have a method that returns a List<SelectOption> containing a list of months to be used in a menu on a VF page. I'm still new to writing Apex code and I can't figure out what the correct way to write the test method for this is. If I run tests on the following code I get this error:
 
 

System.Exception: Assertion Failed: Expected: (System.SelectOption[value="01", label="Jan", disabled="false"], System.SelectOption[value="02", label="Feb", disabled="false"], System.SelectOption[value="03", label="Mar", disabled="false"], System.SelectOption[value="04", label="Apr", disabled="false"], System.SelectOption[value="05", label="May", disabled="false"], System.SelectOption[value="06", label="Jun", disabled="false"], System.SelectOption[value="07", label="Jul", disabled="false"], System.SelectOption[value="08", label="Aug", disabled="false"], System.SelectOption[value="09", label="Sep", disabled="false"], System.SelectOption[value="10", label="Oct", disabled="false"], ...), Actual: (System.SelectOption[value="01", label="Jan", disabled="false"], System.SelectOption[value="02", label="Feb", disabled="false"], System.SelectOption[value="03", label="Mar", disabled="false"], System.SelectOption[value="04", label="Apr", disabled="false"], System.SelectOption[value="05", label="May", disabled="false"], System.SelectOption[value="06", label="Jun", disabled="false"], System.SelectOption[value="07", label="Jul", disabled="false"], System.SelectOption[value="08", label="Aug", disabled="false"], System.SelectOption[value="09", label="Sep", disabled="false"], System.SelectOption[value="10", label="Oct", disabled="false"], ...)

 

 

public class Months {

public List<SelectOption> getMonthList() {

List<SelectOption> options = new List<SelectOption>();

options.add(new SelectOption('01', 'Jan'));

options.add(new SelectOption('02', 'Feb'));

options.add(new SelectOption('03', 'Mar'));

options.add(new SelectOption('04', 'Apr'));

options.add(new SelectOption('05', 'May'));

options.add(new SelectOption('06', 'Jun'));

options.add(new SelectOption('07', 'Jul'));

options.add(new SelectOption('08', 'Aug'));

options.add(new SelectOption('09', 'Sep'));

options.add(new SelectOption('10', 'Oct'));

options.add(new SelectOption('11', 'Nov'));

options.add(new SelectOption('12', 'Dec'));

return options;

}

 

static testMethod void testMonthList() {

List<SelectOption> test_options = new List<SelectOption>();

test_options.add(new SelectOption('01', 'Jan'));

test_options.add(new SelectOption('02', 'Feb'));

test_options.add(new SelectOption('03', 'Mar'));

test_options.add(new SelectOption('04', 'Apr'));

test_options.add(new SelectOption('05', 'May'));

test_options.add(new SelectOption('06', 'Jun'));

test_options.add(new SelectOption('07', 'Jul'));

test_options.add(new SelectOption('08', 'Aug'));

test_options.add(new SelectOption('09', 'Sep'));

test_options.add(new SelectOption('10', 'Oct'));

test_options.add(new SelectOption('11', 'Nov'));

test_options.add(new SelectOption('12', 'Dec'));

 

Months my_months = new Months();

List<SelectOption> method_options = my_months.getMonthList();

 

system.assertEquals(method_options, test_options);

}

}

 

I copied/pasted the 'expected' and 'actual' responses to a text editor and they look identical to me. Is there another way I should be writing this test?
 
Thanks,
Dan 
 
 
 
 
  • June 30, 2009
  • Like
  • 0

Hello,

 

I'm creating a select menu that is a list of months Jan-Dec. When my VF page is loaded I'd like the menu to default to the current month (set that option as 'selected'). I know how to get the current month in my apex code but don't know how to combine that in my VF page to set the selected option.

 

Thanks,

Dan 

  • June 25, 2009
  • Like
  • 0

Hello,

 

I'm using the XMLDom class to parse some XML. I'm trying to set a variable to a list of tag names that I can loop through later. What is the correct return type I should set 'names' in the following code to?

 

 

names = responseXML.getElementsByTagName('names');

 

I've tried setting it to List<String> but I get the following error:

 

  Error: Compile Error: Illegal assignment from LIST:XMLDom.Element to LIST:String

 

Thanks,

Dan

  • June 10, 2009
  • Like
  • 0

Hello,

 

Just started using apex and VisualForce last week and I'm trying to get some XML data into a dataTable. I'm able to get the XML and parse it using the XmlStreamReader but I keep getting errors when trying to pass it to the dataTable. Here is my code. For now I'm just trying to get text from the usr_conference_id node but eventually I'd like to get the data from the other nodes.

 

The XML (I'm getting a valid XML doc but removed the header for this post):

 

<meeting>

<usr_conference_id>382718</usr_conference_id>

<conference_name>Test Conf.</conference_name>

<conference_user>Test User1</conference_user>

</meeting>

<meeting>

<usr_conference_id>381084</usr_conference_id>

<conference_name>Test Conf. 2</conference_name>

<conference_user>Test User2</conference_user>

</meeting> 

 

 

<apex:page controller="Conferences">

<apex:dataTable value="{!conferencelist}" var="conf">

<apex:column>

<apex:facet name="header">ID</apex:facet>

<apex:outputText value="{!conf.usr_conference_id}"/>

</apex:column>

</apex:dataTable>

</apex:page> 

 

public class Conferences {

 

public class UserConferences {

String usr_conference_id;

String conference_name;

} // End UserConferences

 

UserConferences[] parseXML(XmlStreamReader reader) {

UserConferences[] conferences = new UserConferences[0];

while(reader.hasNext()) {

if (reader.getEventType() == XmlTag.START_ELEMENT) {

if ('usr_conference_id' == reader.getLocalName()) {

reader.next();

UserConferences conference = new UserConferences();

conference.usr_conference_id = reader.getText();

conferences.add(conference);

}

}

}

return conferences;

} // End parseXML()

 

public List<Conferences.UserConferences> getConferenceList() {

Http http = new Http();

HttpRequest req = new HttpRequest();

req.setEndpoint('https:ADDRESS REMOVED');

req.setMethod('GET');

HttpResponse res = http.send(req);

 

// Generate the HTTP response as an XML stream

XmlStreamReader reader = res.getXmlStreamReader();

List<Conferences.UserConferences> conf_return = parseXML(reader);

return conf_return;

}} // End Conferences

 

When I try to save this in the page editor I get the following error:

 

System.Exception: Too many script statements: 200001

 

Class.Conferences.parseXML: line 21, column 13 Class.Conferences.getConferenceList: line 35, column 60 External entry point 

 

 

Any help would be greatly appreciated!

 

Thanks,

Dan 

 

Message Edited by DDay on 06-07-2009 07:22 PM
  • June 08, 2009
  • Like
  • 0

Hello,

 

I've inherited a project that uses some custom S-Controls. When I log into my dev account and click S-Controls the following message is displayed:

 

"S-controls have been superseded by Visualforce pages. Salesforce will, sometime after January 2010, remove the ability to create and distribute new s-controls. Existing s-controls will be unaffected."

 

Can anyone tell me when this announcement was originally made? The project I'm working on isn't that old so I'm curious to know why the previous dev used S-Controls if they were being deprecated.

 

Thanks,

Dan 

  • June 05, 2009
  • Like
  • 0

Hello,

 

Just started using Apex today and I'm having trouble using List<sObject>. Here is my class:

 

 

public class Settings {

private List<sObject> info;

 

public Settings() {

info = [Select Id, API_Key__c, Password__c, Phone_No__c, Recording_Phone_Number__c, Time_Zone__c from Settings__c];

}

 

public String getKey() {

//String key = [SELECT API_Key__c FROM Settings__C].api_key__c;

String key = info.api_key__c;

return key;

}

}

 

The line commented out in the getKey method works fine. However, trying to use info.api_key__c gives me the following error:

 

   Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST:SObject at line 10 column 22

 

How can I access individual values in the info List object?

 

Thanks,

Dan 

 

 

Message Edited by DDay on 06-04-2009 01:12 PM
  • June 04, 2009
  • Like
  • 0

Hi,

 

While Running a testmethod, I am getting the exception "System.TypeException: Testmethods do not support webservice callouts". This testmethod is for testing a trigger, which is calling the Google API service for Latitude and Lonitude Conversion. I am using Salesforce API version 15.0

 

What can be the alternative way? Please help..

 

Thanks in advance,

Suvra

  • April 17, 2009
  • Like
  • 0