1

How do I access the method getDateTime in the following class. I tried ZuoraObject zo = new ZuoraObject(); but get the error constructor not defined

public class ZuoraObject  {
    private Zuora.zObject xObj;
    private string xObjectType;
    private string xNamespace;
    private Map<String, object> xAttributes;


    public ZuoraObject(string objectType)
    {
        if (Test.isRunningTest()) {
            xObjectType = objectType;
            xNamespace = 'http://object.api.zuora.com/';
            xAttributes = new Map<String, object>(); 
        }
        else{
            xObj = new Zuora.zObject(objectType);
        }
    }
 public DateTime getDateTime(String fieldName){
        if(String.isBlank(fieldName)){
            return null;
        }
    }
}
2
  • Does this even compile? getDateTime() falls off the end with no explicit return value.
    – David Reed
    Feb 4, 2020 at 16:51
  • I assumed this was cut-down code so have ignored various issues such as this :D
    – Phil W
    Feb 4, 2020 at 16:51

1 Answer 1

2

This class has an explicit constructor that takes an object type, so you need to construct the instance passing in an object type:

String someObjectType = ...; // Set it somehow. In this case null might be
                             // appropriate but it rather depends on the code
                             // you omitted
ZuoraObject zo = new ZuoraObject(someObjectType);

You can then access the getDateTime method, passing in some field name:

String someFieldName = ...; // Set to whatever you need
Datetime dt = zo.getDateTime(someFieldName);

Note that the getDateTime is an instance method, not a static one, so you do need an instance to call it on.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .