+ Start a Discussion
Matt HittMatt Hitt 

errors in test class

Hello,

I am getting these errors in my test class, can I please have some help fixing the issues?

Class
public class convToCst {
    public DateTime dateField{
        get;
        set;
    }
    public string dateFormat {
        get;
        set;
    }
    public string dateTimeZone {
        get;
        set;
    }
    public string output {
        get {return dateField.format(this.dateFormat,this.dateTimeZone);}
           
    }
}

Test class
@isTest
private class TestConvToCst {
    @TestSetup
    static void setupTestData()
    {
        Account acc = new Account(
            Name = 'Test Account');
        insert acc;
        
        Contact con = new Contact(
            FirstName = 'Test', LastName = 'Contact', AccountId = acc.Id  );
        insert con;
        
        eVolve_Service_Request__c ESR = new eVolve_Service_Request__c(Signing_Party_Type__c = 'Seller',
                                                                      Signing_Date_Requested_Start__c = system.today()+5, Status__c = 'New', 
                                                                      Contact_Name__c = con.Id );
        insert ESR;
    }
    @isTest
    static void validateconvToCst()
        
    {
        ConvToCst cst = new ConvToCst();
        cst.ConvToCstId = [Select Id from eVolve_Service_Request__c limit 1].Id;
        
        List<ESR_Signing_Party__c> esp = cst.getConvToCst();
        system.assertEquals('Test Party', esp[0].Name__c);
        
    }
}

Errors:
line 24: Variable does not exist: ConvToCstId
line 26: Method does not exist or incorrect signature: void getConvToCst() from the type convToCst

I tried to copy the code from this but for some reason it is producing errors on this test class: https://developer.salesforce.com/forums/ForumsMain?id=9062I000000ISkfQAG

Thanks,
Matt HittMatt Hitt
Here is the component that calls this class
 
<apex:component access="global" selfClosing="true" controller="convToCst" >
    <apex:attribute name="format" assignTo="{!dateFormat}" access="global" type="String" default="M/d/yyyy h:mm a" description="Format of the datetime field"/>
    <apex:attribute name="field" assignTo="{!dateField}" access="global" type="DateTime" required="true" description="Field to convert"/>
    <apex:attribute name="timezone" assignTo="{!dateTimezone}" access="global" type="String" default="GMT" description="Timezone to convert to"/>
     
    <apex:outputText value="{!output}"/>
</apex:component>

 
MattGoncalvesMattGoncalves
Hi Matt. What you're trying to do? What is your goal? 

About this custom class convToCst:

The class does not have a property named ConvToCstId to receive the Id. 
 
public String ConvToCstId{
        get;
        set;
 }

The class also doesn't have a method named getConvToCst(). 
In the class, you should have a method, with a returning type. Something like:
 
public [you returning type here] getConvToCst(){

... Do something here
... Return something here

}

Do you have more details on what this method is supposed to do or return? 
 
Matt HittMatt Hitt
Hi @MattGoncalves,

So what the class does is it converts the system GMT timezone to CST to display the scheduled date/time correctly on a VF email template.  It was converting correctly on the template so I didn't know it needed to return the Id (I'm new to the coding world).  I also forgot I needed a test class entirely and tried to deploy this past weekend - but I digress.  My goal is to get at least 75% code coverage so I can complete deployment.

To retreive the Id, all I need to do is add this to the end of my class, then I can use it on the Test class?  And this should resolve the line 24 error?
public String ConvToCstId{
        get;
        set;
 }

And I'm sorry, but which class would this belong in?  
public [you returning type here] getConvToCst(){

... Do something here
... Return something here

}

Could you also please walk me through this?  I'm don't really understand the question.  As mentioned this (and the linked class) are my first time using Apex.  
Do you have more details on what this method is supposed to do or return?

Thank you for the help
Matt HittMatt Hitt
Also, I'm not really sure if this last method (26) is the correct thing I need to do for this, it is just what I got for the other classes (https://developer.salesforce.com/forums/ForumsMain?id=9062I000000ISkfQAG)and thought something similar would work here.