You need to sign in to do that
Don't have an account?
Rakesh M
Pagereference issue
public class RecordCreations
{
public string name{set;get;}
public account acc{set;get;}
public contact con{set;get;}
public pagereference createAccount()
{
acc=new account();
acc.name=name;
insert acc;
pagereference pr = new pagereference('/'+acc.id);
return pr;
}
public pagereference createContact()
{
con=new contact();
con.lastname=name;
insert con;
pagereference p = new pagereference('/'+con.id);
return p;
}
}
<apex:page controller="RecordCreations">
<apex:sectionHeader title="Record Creations" subtitle="Accounts & Contacts creations"/>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Account" action="{!createAccount}"/>
<apex:commandButton value="Contact" action="{!createContact}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputText Label="Enter Name : " value="{!name}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
After clicking account, the code works fine and below page comes.
But when I click contact button, The error comes, request you to debug the error and let me know.
Thanks in advance.
{
public string name{set;get;}
public account acc{set;get;}
public contact con{set;get;}
public pagereference createAccount()
{
acc=new account();
acc.name=name;
insert acc;
pagereference pr = new pagereference('/'+acc.id);
return pr;
}
public pagereference createContact()
{
con=new contact();
con.lastname=name;
insert con;
pagereference p = new pagereference('/'+con.id);
return p;
}
}
<apex:page controller="RecordCreations">
<apex:sectionHeader title="Record Creations" subtitle="Accounts & Contacts creations"/>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Account" action="{!createAccount}"/>
<apex:commandButton value="Contact" action="{!createContact}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputText Label="Enter Name : " value="{!name}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
After clicking account, the code works fine and below page comes.
But when I click contact button, The error comes, request you to debug the error and let me know.
Thanks in advance.
Any Trigger for contact and in error it's showing email filed . Pass Email field in code like below .
Check Below code it will work any issue ask me .
Regards ,
Harish.R
All Answers
you got this error becasue any validation rule active on contact object
check validation rule on contact object.
setup --> contact---> validation rule
Thanks
No validation rules are activated in my contact object.
Please see below image.
Thanks in advance.
Any Trigger for contact and in error it's showing email filed . Pass Email field in code like below .
Check Below code it will work any issue ask me .
Regards ,
Harish.R
Please check below point
1) Have you created any Email Id field on contact object as required field ? IF yes then you need to pass value Email Id value on contact.
2) Please check you created any Trigger on Contact object for email id validation ?
NOTE:- you need to pass Email ID also while creating contact