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;
}
}
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