function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VinslikeuVinslikeu 

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.

PremanathPremanath

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

souvik9086souvik9086

Modify your class like the following

 

public with sharing class Student {
private final Student__c std;
public String Name{ get; set; }
public Double Height{ 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;
}
}

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

VinslikeuVinslikeu

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

 

souvik9086souvik9086

Did you changed it?

 

private final Student__c std;

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

VinslikeuVinslikeu

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

}

VinslikeuVinslikeu

Hey Thanks!

 

Code is working! 

you are great! :-)

souvik9086souvik9086

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

llisallisa
Hi all,

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;
    }
}
anna smithanna smith
Thanks for the wonderful tips, we often face problems while working at our workplace, I shall suggest my friends also read this article DumpsExpert HPE2-E74 (https://www.dumpsexpert.com/HPE2-E74-Exam-Dumps.html) Exam Study Guide. I am sure they will also be able to draw some positive aspects from this post.
Arfa Rfa3Arfa Rfa3
The realm of Fertilizerland is not limited to conventional agriculture alone. It also extends its reach to other branches of horticulture, floriculture, and even home gardening. Whether you are a farmer, a gardener, or simply someone passionate about sustainable food production, Fertilizerland offers a wealth of knowledge and resources to help you achieve your goals. try this web-site (https://fertilizerland.com/best-fertilizer-for-centipede-grass/)