You need to sign in to do that
Don't have an account?
IMU Admin
Test Method for Custom Controller (Apex Class and Visual Force Component)
Hi All,
I need some help writing a test class for the below (I am fairly new to apex so still learning)
Apex Class:
public class InteractionsForCustomer {
private List<Interactions__c> allInteractions;
private Interactions__c currentInteractions;
public InteractionsForCustomer() {
}
public List<Interactions__c> getAllInteractions() {
allInteractions = [Select Id, Name from Interactions__c where Stage__c = 'Open' AND Cutomer__c = :currentInteractions.Customer__c];
return allInteractions;
}
public Interactions__c getcurrentInteractions() {
return currentInteractions;
}
public void setcurrentInteractions(Interactions__c val) {
this.currentInteractions = val;
}
}
VisualForce Component
<apex:component controller="InteractionsForCustomer" access="global">
<apex:dataTable value="{!allInteractions}" var="inv">
<apex:column >
<apex:facet name="header">Invoice Name</apex:facet>
{!inv.Customer__c}
</apex:column>
</apex:dataTable>
</apex:component>
Thanks
Josh
I need some help writing a test class for the below (I am fairly new to apex so still learning)
Apex Class:
public class InteractionsForCustomer {
private List<Interactions__c> allInteractions;
private Interactions__c currentInteractions;
public InteractionsForCustomer() {
}
public List<Interactions__c> getAllInteractions() {
allInteractions = [Select Id, Name from Interactions__c where Stage__c = 'Open' AND Cutomer__c = :currentInteractions.Customer__c];
return allInteractions;
}
public Interactions__c getcurrentInteractions() {
return currentInteractions;
}
public void setcurrentInteractions(Interactions__c val) {
this.currentInteractions = val;
}
}
VisualForce Component
<apex:component controller="InteractionsForCustomer" access="global">
<apex:dataTable value="{!allInteractions}" var="inv">
<apex:column >
<apex:facet name="header">Invoice Name</apex:facet>
{!inv.Customer__c}
</apex:column>
</apex:dataTable>
</apex:component>
Thanks
Josh
Please try following class. Also, Please go through the link for learning how to write test class -
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_best_practices.htm
All Answers
Check this Trailhead module to learn about writing apex test class in Salesforce https://developer.salesforce.com/trailhead/module/apex_testing
Please try following class. Also, Please go through the link for learning how to write test class -
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_best_practices.htm
I seem to get an error with this code - Line 7 Invalid Type: Customer__c
Customer is the parent object and Interaction is the child object if that makes any difference I am not too sure?
Hi @Tarun_Khandelwal
I don't get any errors for this but when I check my Apex Class it is still showing as 0% test coverage?
Sorry if this is simple but haven't written test class before
Thanks in advance
Tell a lie - that has worked
Thank you very much