You need to sign in to do that
Don't have an account?
Sv Krishna Reddy
Constructor not defined: [PageReference].<Constructor>(String)
public class Duplicate {
public Account acc {set;get;}
public Duplicate(){
acc=new Account();
}
public PageReference create(){
PageReference p;
try{
integer count=[select count() from Account where name=:acc.name];
if(count>0){
Apexpages.Message msg=new Apexpages.Message(Apexpages.Severity.ERROR,'Duplicate Record found');
Apexpages.addMessage(msg);
}
else{
insert acc;
p=new PageReference('/'+acc.Id);
}
}
catch(Exception e){
Apexpages.Message msg=new ApexPages.Message(ApexPages.Severity.ERROR,e.getMessage());
ApexPages.addMessage(msg);
}
return p;
}
}
public Account acc {set;get;}
public Duplicate(){
acc=new Account();
}
public PageReference create(){
PageReference p;
try{
integer count=[select count() from Account where name=:acc.name];
if(count>0){
Apexpages.Message msg=new Apexpages.Message(Apexpages.Severity.ERROR,'Duplicate Record found');
Apexpages.addMessage(msg);
}
else{
insert acc;
p=new PageReference('/'+acc.Id);
}
}
catch(Exception e){
Apexpages.Message msg=new ApexPages.Message(ApexPages.Severity.ERROR,e.getMessage());
ApexPages.addMessage(msg);
}
return p;
}
}
Instead of PageReference try to use the system.PageReferenc
The error reason you can find it from below links;
https://salesforce.stackexchange.com/questions/221919/constructor-not-defined-pagereference-constructorstring
https://salesforce.stackexchange.com/questions/96148/getting-error-as-compile-error-constructor-not-defined-pagereference-constr
Thanks,
Maharajan.C
All Answers
Hi Krishna,
Please change your class name and method name it might be possible some standard things are there in the apex like Duplicate
Please mark it as the Best Answer if your queries are solved.
Thank You
Instead of PageReference try to use the system.PageReferenc
The error reason you can find it from below links;
https://salesforce.stackexchange.com/questions/221919/constructor-not-defined-pagereference-constructorstring
https://salesforce.stackexchange.com/questions/96148/getting-error-as-compile-error-constructor-not-defined-pagereference-constr
Thanks,
Maharajan.C
I am not getting any errors.
Can you please try like this
System.PageReference p = new System.PageReference('/'+acc.Id);
or You can also change the API version.
Thank You
its fine,there is no errors but in vf page if i am enter duplicate value it does't show any popup msg
<apex:sectionHeader title="Account"/>
<apex:form >
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!create}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection>
<apex:inputField value="{!acc.name}"/>
<apex:inputField value="{!acc.rating}"/>
<apex:inputField value="{!acc.phone}"/>
<apex:inputField value="{!acc.industry}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>