You need to sign in to do that
Don't have an account?
Compile Error: Incompatible types since an instance of SObject is never an instance of Student
///////Visualforce////////
<apex:page standardController="Student__c" extensions="Student">
<apex:pageblock title="New Account">
<apex:pageBlockSection title="Register">
<apex:form >
<b>Username:</b> <br/>
<apex:inputText required="true" id="username" value="{!Student__c.Name}" /> <br/>
<b>Password:</b> <br/>
<apex:inputSecret required="true" id="password" value="{!Student__c.Mobile__c}"/> <br/>
<b>Email:</b> <br/>
<apex:inputText required="true" id="emailid" value="{!Student__c.Email__c}" /> <br/>
<b>Phone Number:</b> <br/>
<apex:inputText required="true" id="phno" value="{!Student__c.Height__c}" /> <br/> <br/>
<apex:commandButton value="Register" action="{!register}"/> <t/> <t/>
<apex:commandButton value="Existing User" action="{!pbck}"/> <br/> <br/>
</apex:form>
</apex:pageBlockSection>
</apex:pageblock>
</apex:page>
/////Controller////////
public with sharing class Student {
private final Student std;
public String Name{ get; set; }
public Double Height__c{ get; set; }
public String Email__c{ get; set; }
public String Mobile__c { get; set; }
list<student__c> stdlist=[select id, Name, Height__c, Email__c, Mobile__c from student__c where id=:ApexPages.currentPage().getParameters().get('id')];
public Student(ApexPages.StandardController controller) {
this.std= (Student)Controller.getRecord();
}
public PageReference pbck() {
return page.mylogin;
}
public PageReference register() {
insert stdlist;
return page.mylogin;
}
}
Im facing following errors:
1: Error: Student Compile Error: Invalid identifier: Height__c at line 5 column 13
2: Error: Student Compile Error: Incompatible types since an instance of SObject is never an instance of Student at line 12 column 19
for 1st error, i tried all the premitive data types, still that error is there.
The Problem is here
public Student(ApexPages.StandardController controller) {
this.std= (Student)Controller.getRecord();
}
instead of that you should use
public Student(ApexPages.StandardController controller) {
this.std= (Student__c)Controller.getRecord();
}
try this
prem
Modify your class like the following
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Thanks all of you for your reply.
I tried this solution but its showing
Compile Error: Illegal assignment from SOBJECT:Student__c to Student at line 12 column 9
Did you changed it?
Then how come this error came?
Can you post your current code?
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Kindly verify my code:
public with sharing class Student {
private final Student std;
public String Name{ get; set; }
public Double Height__c{ get; set; }
public String Email__c{ get; set; }
public String Mobile__c { get; set; }
list<student__c> stdlist=[select id, Name, Height__c, Email__c, Mobile__c from student__c where id=:ApexPages.currentPage().getParameters().get('id')];
public Student(ApexPages.StandardController controller) {
this.std= (Student__c)Controller.getRecord();
}
public PageReference pbck() {
return page.mylogin;
}
public PageReference register() {
insert stdlist;
return page.mylogin;
}
}
Hey Thanks!
Code is working!
you are great! :-)
Great then. If it works then please throw KUDOS by clicking the star icon in the lef to the helpful posts and mark it as solution which answers your question. This will help other developers in searching for answers.
Thanks
I face the same issue here : Error: Compile Error: Incompatible types since an instance of SObject is never an instance of String at line 11 column 28
i cant feagure it out what will be the problem.Please help me on this.
public class StatusController
{
public static Boolean StatusUpdate(Map<Id,SObject> OldObject, Map<Id,SObject> NewObject, String StatusAPI)
{
Schema.sObjectType ObjectType = OldObject.getSObjectType();
String ObjectType2 = String.ValueOf(ObjectType);
String OldStatus = (String) OldObject.get(StatusAPI);
String NewStatus = (String) NewObject.get(StatusAPI);
List<Status__c> OldStatusFromTo = [Select From__c, To__c from Status__c where Status_Name__c =: OldStatus and Object__c =: ObjectType2];
List<Status__c> NewStatusID = [Select StatusID__c from Status__c where Status_Name__c =: NewStatus and Object__c =: ObjectType2];
Decimal FromVar = OldStatusFromTo.From__c;
Decimal ToVar = OldStatusFromTo.To__c;
Decimal StatusID = NewStatusID.StatusID__c;
if (!(FromVar <= StatusID && StatusID <= ToVar))
{
return false;
}
return true;
}
}