You need to sign in to do that
Don't have an account?
Tiffany Shabazz 9
FormAssembly Test Class for Controller
I am working to integrate FormAssembly forms in Salesforce and need assistance with writing the test class for the code. I would think that this would be something I could easily find since this seems like a common use case, but I am not able to find anything. Has anyone written a test class associated with FormAssembly integration in Salesforce? Essentially, the code is working in the sandbox. I am just trying to display the form using a visualforce page. Here is the code. I used the instructions written by FormAssembly, but those did not include how to create the test class.
Controller:
public class SuggestionBoxController{
public HTTPResponse res {get; set;}
public String resBody {get; set;}
public String endpoint {get; set;}
public SuggestionBoxController() {
PageReference pageRef = ApexPages.currentPage();
HttpRequest req = new HttpRequest();
req.setMethod('GET');
if(pageRef.getParameters().get('tfa_next') == null){
//Replace 'FORM_ID' with your form's ID number
endpoint = 'https://app.formassembly.com/rest/forms/view/4604281';
}else{
endpoint = 'https://app.formassembly.com/rest' + pageRef.getParameters().get('tfa_next');
}
req.setEndpoint(endpoint);
Http http = new Http();
try {
//Execute web service call here
res = http.send(req);
resBody = res.getBody();
} catch(System.CalloutException e) {
//Exception handling goes here....
System.debug(e);
}
}
}
Visualforce Page:
<apex:page controller="SuggestionBoxController">
<apex:outputText value="{!resBody}" escape="false" />
</apex:page>
Controller:
public class SuggestionBoxController{
public HTTPResponse res {get; set;}
public String resBody {get; set;}
public String endpoint {get; set;}
public SuggestionBoxController() {
PageReference pageRef = ApexPages.currentPage();
HttpRequest req = new HttpRequest();
req.setMethod('GET');
if(pageRef.getParameters().get('tfa_next') == null){
//Replace 'FORM_ID' with your form's ID number
endpoint = 'https://app.formassembly.com/rest/forms/view/4604281';
}else{
endpoint = 'https://app.formassembly.com/rest' + pageRef.getParameters().get('tfa_next');
}
req.setEndpoint(endpoint);
Http http = new Http();
try {
//Execute web service call here
res = http.send(req);
resBody = res.getBody();
} catch(System.CalloutException e) {
//Exception handling goes here....
System.debug(e);
}
}
}
Visualforce Page:
<apex:page controller="SuggestionBoxController">
<apex:outputText value="{!resBody}" escape="false" />
</apex:page>
I restructured your code a bit as invoking HTTP Callouts in a constructor is not a good idea.
Please go through the code and the test class achieves 88% for now.
Sorry there was some error in my code - please use the updated version of these 2 code.
SuggestionBoxController
SuggestionBoxControllerTest
If this helped, please mark the response as best answer. thanks.