Play Games

Search This Blog

Friday, November 27, 2015

Error: Compile Error: Constructor not defined: [SObject].()

problem:
public class SobjectConstructor {
    public SobjectConstructor () {
        Sobject sobj = new Sobject();
    }
}
When we save above piece of code, We get the error.
Solution:We cannot directly create an instance of sobject.First we need to create instance of object(salesforce standard or custom object) and then type cast to sobject
Modify the piece of code like this.
public class SobjectConstructor {
    public SobjectConstructor () {
        Account acc = new Account();
        Sobject sobj = (Sobject) acc;
    }
}

No comments:

Post a Comment