Overriding properties from abstract class in Salesforce Apex

与世无争的帅哥 提交于 2019-12-05 17:23:08

Unfortunately, as far as I know that is a mistake in the documentation. I've only been able to apply the override and virtual modifiers to methods. You can, of course, get the desired effect by manually writing your property getter/setter methods:

public abstract class TestRow {
    public Double value;

    public virtual Double getValue() {
        return value==null ? 0 : value;
    }

    public void setValue(Double value) {
        this.value = value;
    }
}

public class SummaryTestRow extends TestRow {
    private list<TestRow> childRows;

    public override Double getValue() {
        Double totalValue = 0;
        for(TestRow childRow : childRows){
            totalValue += childRow.value;
        }

        return totalValue;  
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!