I defined a virtual class and two classes that extend it with additional properties.

After creating the class instance and trying to initialize it's properties i get a "Variable does not exist" error on the properties of the extending class.

Code examples

The class definition:

public virtual class BpmPayment {
public Payment__c payment { get; set; }
public String sum { get; set; }

public class TransferPayment extends BpmPayment {
    public Date transferDate { get; set; }

public class CheckPayment extends BpmPayment {
    public String bank { get; set; }
    public String branch { get; set; }
    public String serial { get; set; }
    public Date repaymentDate { get; set; }


newCheckPayment.sum = String.valueOf(newPayment.Paid_Amount__c);
newCheckPayment.payment = newPayment;                    
newCheckPayment.repaymentDate = date.valueOf(checkDate);

The "sum" and "payment" properties are resolved just fine (i'm guessing because they belong to the outer class) But i get the error for the "repaymentDate" property.

2 Answers 2


It depends what instance is the newCheckPayment.

I think you should make something like:

BpmPayment.CheckPayment newCheckPayment = new BpmPayment.CheckPayment();

I tried to reproduce this with a minimal example and found that property resolution on the inner subclass works fine:

public virtual class Superclass {
    public String superProperty { get; set; }

    public class Subclass extends Superclass {
        public String subProperty { get; set; }


Superclass s = new Superclass();

s.superProperty = 'Test';
System.assertEquals('Test', s.superProperty);

Superclass.Subclass sc = new Superclass.Subclass();

sc.superProperty = 'Test';
sc.subProperty = 'Test-Sub';

System.assertEquals('Test', sc.superProperty);
System.assertEquals('Test-Sub', sc.subProperty);

All of the assertions pass.

I suspect that the issue you have here is outside the code that you shared, and it's one of two things. Either:

  • You declared your variable as an instance of BpmPayment, rather than BpmPayment.CheckPayment. The superclass doesn't have the property (which is checked at compile time), even if you're actually assigning an instance of a subclass that does.
  • There's a separate, unrelated syntax error nearby in your code, which can sometimes manifest as "no such variable" type errors.
  • Thank you for the answer! It was very informative, had to mark Enrik since he answered first though, i tried to upvote but i don't have enough reputation.
    – RealGigex
    Jul 4, 2018 at 14:09

You must log in to answer this question.

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