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
yarramyarram 

Fields get cleared Issue..Urgent !

Hi All,

 

I have two custom objects Employee and Department, I have created and displaying one VF page with these objects Field Values and two command buttons like Update and Cancel buttons. Also created validation rules for those objects.While Updating the employee information I am entering wrong data on some fields. It displays the validation rule error message and at the same time those fields are get cleared

How to keep the wrong data on the fields.

How to resolve this "Fields get cleared" problem... Please suggest me.

 

Thanks,

yarram.

Best Answer chosen by Admin (Salesforce Developers) 
tukmoltukmol

that's what i was telling. you may somehow reinitializing your sobject. Everytime your VFpage refers to LabAdmin (via getLabAdmin()), it is being reinitialized. effect is, cleared fields because your code keep discarding it:

 

public LabAdmin__c getLabAdmin()
{

// call method from LabadminUtil
labadmin= LabAdminUtil.getLabAdminDetails(LabadminId); // this line resets/clears your fields

return labadmin;
}

 

since you already initialized "labadmin" in your class constructor, your getLabAdmin should be just like this:

public LabAdmin__c getLabAdmin()
{

    return this.labadmin;

}

 

All Answers

bob_buzzardbob_buzzard

Its a bit tricky to say without seeing your code - can you post up the relevant sections of the page and controller?

yarramyarram

Hi,

 

Thanks for replying,  bellow code is my actual code. 

 

//////// page code //////////

<apex:page sidebar="false" showHeader="false" controller="LabAdminCtrl">
<apex:form >
<apex:pageBlock title="My Profile">

<apex:outputpanel>
<apex:pageMessages ></apex:pageMessages>


 <apex:pageBlockSection Title="LabAdmin Details">
<apex:inputField value="{!LabAdmin.FName__c}" styleClass="blockno"/>
<apex:inputField value="{!LabAdmin.LName__c}" styleClass="blockno"/>
<apex:inputField value="{!LabAdmin.PPhone__c}" styleClass="blockno"/>
<apex:inputField value="{!LabAdmin.PEmail__c}" styleClass="blockno"/>
<apex:inputField value="{!LabAdmin.PFax__c}" styleClass="blockno"/>
</apex:pageBlockSection>

 

<apex:pageblockSection title="Demographic Details">
<apex:inputField value="{!demographic.AddLine1__c}" style="resize:none;" styleClass="blockno"/>
<apex:inputField value="{!demographic.Landmark__c}" style="resize:none;" styleClass="blockno"/>
<apex:inputField value="{!demographic.City__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.State__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.Country__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.Pincode__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.Email__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.Phone__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.Fax__c}" styleClass="blockno"/>
</apex:pageblockSection>


<center>
<apex:commandButton value="Update" action="{!updateProfile}" />
<apex:commandButton value="Cancel" action="{!cancelChanges}"/>
</center>


</apex:outputpanel>
</apex:pageBlock>
</apex:form >
</apex:page>


//////////////// Controller code ///////////////


//Called When click on Update Btton in Profile Edit form
public void updateProfile()
{
Savepoint labTechProfilesp = Database.setSavepoint();
if(labadmin.FName__c!=null && labadmin.LName__c!=null && labadmin.PEmail__c!=null && demographic.AddType__c!=null && demographic.AddLine1__c!=null)
{
LabAdminUpdateInformationError=false;

try
{
update labadmin;
update demographic;
profileMainForm = true; //After click on UpdateButton it will render to Profle form
profileEditForm = false;
}
catch(Exception e)
{
ApexPages.addMessages(e);
profileMainForm = false; //After click on UpdateButton it will render to Profle form
profileEditForm = true;
Database.rollback(labTechProfilesp);

}

}
else
{
LabAdminUpdateInformationError=true;
}
}

 

please tell me where I did mistake in this code.

 

Thanks,

Yarram.

 

bob_buzzardbob_buzzard

I can't see anything obviously wrong.  Which fields are being cleared?

tukmoltukmol

you are using a custom controller instead of an extension.

 

your controller code isn't complete.

 

it doesn't show where and how you instantiated your sobjects (employee and department). _could_ be that these sobjects are reinstantiated in each page refresh, clearing the default values.

yarramyarram

Hi,

 

What i am saying, i have two objects(LabAdmin and Demographics) with lookup relationship. i have inserted one record successfully into two objects.  i have created one detailed VF page , that page contains two pageBlockSections with two object fields data. on that page both objects(LabAdmin and Demographics)  data is displayed and one EDIT Button is there.

 

Now i want to update the Demographics data through this VFpage.

 

-->Click on EDIT Button-->Now this page displays in Editable mode (all fields data are in Editable mode) and This editable mode page contains Two Buttons like UPDATE and CANCEL buttons.

 

-->In Demographic section Phone Field data is 9563214255(this field having validations. It allows only numbers).

 

-->Now i try to update the Phone Field with letters(RDFEDSS). RDFEDSS these letters are caused for validations rule firing (When i click on Update Button that time the page is refreshing).

 

--> Error message is  displayed and 

--> on Phone filed (RDFEDSS) these letters are get cleared and previous data(9563214255) is displayed.

 

actually i am facing this problem. Not only that field all fields are get cleared when error is occured.

 

i am also mentioned the code Bellow ..   

 

//////// page code ///////////
<apex:page sidebar="false" showHeader="false" controller="LabAdminCtrl">
<apex:form >
<apex:pageBlock title="My Profile">

<apex:outputPanel rendered="{!profileMainForm }" >
<apex:pageBlockSection Title="LabAdmin Details" collapsible="true">
<apex:outputfield value="{!LabAdmin.FName__c}"/>
<apex:outputField value="{!LabAdmin.LName__c}"/>
<apex:outputField value="{!LabAdmin.PPhone__c }"/>
<apex:outputField value="{!LabAdmin.PEmail__c}"/>
<apex:outputField value="{!LabAdmin.PFax__c}"/>

</apex:pageBlockSection>
<apex:pageBlockSection title="Demographic Details">
<apex:outputField value="{!demographic.AddType__c}"/>
<apex:outputField value="{!demographic.AddLine1__c}"/>
<apex:outputField value="{!demographic.AddLine2__c}"/>
<apex:outputField value="{!demographic.Landmark__c}"/>
<apex:outputField value="{!demographic.City__c}"/>
<apex:outputField value="{!demographic.State__c}"/>

<apex:outputField value="{!demographic.Country__c}"/>
<apex:outputField value="{!demographic.Pincode__c}"/>
<apex:outputField value="{!demographic.Email__c}"/>
<apex:outputField value="{!demographic.Phone__c}"/>
<apex:outputField value="{!demographic.Fax__c}"/>


</apex:pageblockSection>
<center> <apex:commandButton value="Edit" action="{!profileEdit}" /></center>
</apex:outputPanel>

<apex:outputpanel rendered="{!profileEditForm }">
<apex:pageMessages ></apex:pageMessages>
<center><apex:outputtext rendered="{!LabAdminUpdateInformationError}">

<apex:pageBlockSection Title="LabAdmin Details">
<apex:inputField value="{!LabAdmin.FName__c}" styleClass="blockno"/>

<apex:inputField value="{!LabAdmin.LName__c}" styleClass="blockno"/>
<apex:inputField value="{!LabAdmin.PPhone__c}" styleClass="blockno"/>
<apex:inputField value="{!LabAdmin.PEmail__c}" styleClass="blockno"/>
<apex:inputField value="{!LabAdmin.PFax__c}" styleClass="blockno"/>
</apex:pageBlockSection>

<apex:pageblockSection title="Demographic Details">

<apex:inputField value="{!demographic.AddLine1__c}" style="resize:none;" styleClass="blockno"/>
<apex:inputField value="{!demographic.Landmark__c}" style="resize:none;" styleClass="blockno"/>
<apex:inputField value="{!demographic.City__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.State__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.Country__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.Pincode__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.Email__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.Phone__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.Fax__c}" styleClass="blockno"/>

</apex:pageblockSection>
<center>
<apex:commandButton value="Update" action="{!updateProfile}" />
<apex:commandButton value="Cancel" action="{!cancelChanges}"/>
</center>
</apex:outputpanel>
</apex:pageBlock>
</apex:form >
</apex:page>


//////////////// Controller code ///////////////
//Called When Click on Profile Edit Button
public void profileEdit()
{
LabAdminUpdateInformationError=false;
profileMainForm = false;
profileEditForm = true; //opens Editable Mode
}

//Called When click on Update Btton in Profile Edit form
public void updateProfile()
{
Savepoint labTechProfilesp = Database.setSavepoint();
if(labadmin.FName__c!=null && labadmin.LName__c!=null && labadmin.PEmail__c!=null && demographic.AddType__c!=null && demographic.AddLine1__c!=null)
{
LabAdminUpdateInformationError=false;

try
{
update labadmin;
update demographic;
profileMainForm = true; //After click on UpdateButton it will render to Profle form
profileEditForm = false;
}
catch(Exception e)
{
ApexPages.addMessages(e);
profileMainForm = false; //After click on UpdateButton it will render to Profle form
profileEditForm = true;
Database.rollback(labTechProfilesp);

}

}
else
{
LabAdminUpdateInformationError=true;
}
}

//////////////////////////////////////////////

please give me solution.

 

Thanks,

yarram

 

 

 


yarramyarram

Hi,

 

What i am saying, i have two objects(LabAdmin and Demographics) with lookup relationship. i have inserted one record successfully into two objects.  i have created one detailed VF page , that page contains two pageBlockSections with two object fields data. on that page both objects(LabAdmin and Demographics)  data is displayed and one EDIT Button is there.

 

Now i want to update the Demographics data through this VFpage.

 

-->Click on EDIT Button-->Now this page displays in Editable mode (all fields data are in Editable mode) and This editable mode page contains Two Buttons like UPDATE and CANCEL buttons.

 

-->In Demographic section Phone Field data is 9563214255(this field having validations. It allows only numbers).

 

-->Now i try to update the Phone Field with letters(RDFEDSS). RDFEDSS these letters are caused for validations rule firing (When i click on Update Button that time the page is refreshing).

 

--> Error message is  displayed and 

--> on Phone filed (RDFEDSS) these letters are get cleared and previous data(9563214255) is displayed.

 

actually i am facing this problem. Not only that field all fields are get cleared when error is occured.

 

i am also mentioned the code Bellow ..   

 

//////// page code ///////////
<apex:page sidebar="false" showHeader="false" controller="LabAdminCtrl">
<apex:form >
<apex:pageBlock title="My Profile">

<apex:outputPanel rendered="{!profileMainForm }" >
<apex:pageBlockSection Title="LabAdmin Details" collapsible="true"> 
<apex:outputfield value="{!LabAdmin.FName__c}"/> 
<apex:outputField value="{!LabAdmin.LName__c}"/> 
<apex:outputField value="{!LabAdmin.PPhone__c }"/> 
<apex:outputField value="{!LabAdmin.PEmail__c}"/>
<apex:outputField value="{!LabAdmin.PFax__c}"/>

</apex:pageBlockSection>
<apex:pageBlockSection title="Demographic Details">
<apex:outputField value="{!demographic.AddType__c}"/>
<apex:outputField value="{!demographic.AddLine1__c}"/>
<apex:outputField value="{!demographic.AddLine2__c}"/> 
<apex:outputField value="{!demographic.Landmark__c}"/>
<apex:outputField value="{!demographic.City__c}"/>
<apex:outputField value="{!demographic.State__c}"/>

<apex:outputField value="{!demographic.Country__c}"/> 
<apex:outputField value="{!demographic.Pincode__c}"/>
<apex:outputField value="{!demographic.Email__c}"/>
<apex:outputField value="{!demographic.Phone__c}"/>
<apex:outputField value="{!demographic.Fax__c}"/>


</apex:pageblockSection>
<center> <apex:commandButton value="Edit" action="{!profileEdit}" /></center>
</apex:outputPanel>

<apex:outputpanel rendered="{!profileEditForm }">
<apex:pageMessages ></apex:pageMessages>
<center><apex:outputtext rendered="{!LabAdminUpdateInformationError}">

<apex:pageBlockSection Title="LabAdmin Details">
<apex:inputField value="{!LabAdmin.FName__c}" styleClass="blockno"/>

<apex:inputField value="{!LabAdmin.LName__c}" styleClass="blockno"/>
<apex:inputField value="{!LabAdmin.PPhone__c}" styleClass="blockno"/> 
<apex:inputField value="{!LabAdmin.PEmail__c}" styleClass="blockno"/>
<apex:inputField value="{!LabAdmin.PFax__c}" styleClass="blockno"/>
</apex:pageBlockSection>

<apex:pageblockSection title="Demographic Details">

<apex:inputField value="{!demographic.AddLine1__c}" style="resize:none;" styleClass="blockno"/> 
<apex:inputField value="{!demographic.Landmark__c}" style="resize:none;" styleClass="blockno"/>
<apex:inputField value="{!demographic.City__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.State__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.Country__c}" styleClass="blockno"/> 
<apex:inputField value="{!demographic.Pincode__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.Email__c}" styleClass="blockno"/> 
<apex:inputField value="{!demographic.Phone__c}" styleClass="blockno"/>
<apex:inputField value="{!demographic.Fax__c}" styleClass="blockno"/> 

</apex:pageblockSection>
<center>
<apex:commandButton value="Update" action="{!updateProfile}" />
<apex:commandButton value="Cancel" action="{!cancelChanges}"/>
</center>
</apex:outputpanel>
</apex:pageBlock>
</apex:form >
</apex:page>


//////////////// Controller code ///////////////
//Called When Click on Profile Edit Button
public void profileEdit()
{
LabAdminUpdateInformationError=false;
profileMainForm = false;
profileEditForm = true; //opens Editable Mode
}

//Called When click on Update Btton in Profile Edit form 
public void updateProfile()

Savepoint labTechProfilesp = Database.setSavepoint();
if(labadmin.FName__c!=null && labadmin.LName__c!=null && labadmin.PEmail__c!=null && demographic.AddType__c!=null && demographic.AddLine1__c!=null)
{
LabAdminUpdateInformationError=false;

try
{
update labadmin;
update demographic; 
profileMainForm = true; //After click on UpdateButton it will render to Profle form
profileEditForm = false; 
}
catch(Exception e)
{
ApexPages.addMessages(e); 
profileMainForm = false; //After click on UpdateButton it will render to Profle form
profileEditForm = true; 
Database.rollback(labTechProfilesp);

}

}
else
{
LabAdminUpdateInformationError=true;

}

//////////////////////////////////////////////

please give me solution.

 

Thanks,

yarram

 

 

 

tukmoltukmol

again, how did you instantiated (or set the value of) your Employee (LabAdmin) and Department (Demographics) objects.

 

Also where in your controller class you instantiated those objects?

yarramyarram

Hi, 

 

Leave it Employee and department. Remember only LabAdmin and Demographics objects.

 

 

This is my controller code.

 

 

 

//////////////// Controller code ///////////////
global with sharing class LabAdminCtrl
{
public LabAdmin__c labadmin; //store the labadmin Information
public Demographic__c demographic; //store the Demographics Information

//Default constructor
public LabAdminCtrl()
{
labadmin= LabAdminUtil.getLabAdminDetails(LabadminId);
}
//Parameterised constructor
public LabAdminCtrl(String labId)
{
LabadminId = labId;
labadmin= LabAdminUtil.getLabAdminDetails(LabadminId);
}

// return the selected Labadmin record
public LabAdmin__c getLabAdmin()
{

// call method from LabadminUtil
labadmin= LabAdminUtil.getLabAdminDetails(LabadminId);

return labadmin;
}


//Get demographics information from DemographicUtil and display in Profile form
public Demographic__c getDemographic(){

//get labadmin demographic information from demographic util by labadminid
demographic = DemographicsUtil.getLabAdminDemoraphicDetails(LabadminId);

return demographic ;

}
//Called When Click on Profile Edit Button
public void profileEdit()
{
LabAdminUpdateInformationError=false;
profileMainForm = false;
profileEditForm = true; //opens Editable Mode
}

//Called When click on Update Btton in Profile Edit form
public void updateProfile()
{
Savepoint labTechProfilesp = Database.setSavepoint();
if(labadmin.FName__c!=null && labadmin.LName__c!=null && labadmin.PEmail__c!=null && demographic.AddType__c!=null && demographic.AddLine1__c!=null)
{
LabAdminUpdateInformationError=false;

try
{
update labadmin;
update demographic;
profileMainForm = true; //After click on UpdateButton it will render to Profle form
profileEditForm = false;
}
catch(Exception e)
{
ApexPages.addMessages(e);
profileMainForm = false; //After click on UpdateButton it will render to Profle form
profileEditForm = true;
Database.rollback(labTechProfilesp);

}

}
else
{
LabAdminUpdateInformationError=true;
}
}

 

 

please give me solution.

 

 

Thanks,

Yarram.

tukmoltukmol

that's what i was telling. you may somehow reinitializing your sobject. Everytime your VFpage refers to LabAdmin (via getLabAdmin()), it is being reinitialized. effect is, cleared fields because your code keep discarding it:

 

public LabAdmin__c getLabAdmin()
{

// call method from LabadminUtil
labadmin= LabAdminUtil.getLabAdminDetails(LabadminId); // this line resets/clears your fields

return labadmin;
}

 

since you already initialized "labadmin" in your class constructor, your getLabAdmin should be just like this:

public LabAdmin__c getLabAdmin()
{

    return this.labadmin;

}

 

This was selected as the best answer
yarramyarram

HI,

 

Its working, But even displaying the error message with that wrong data also the wrong data is get Updated in that sobjects.

 

 

How it's possible?

 

That wrong data should not get updated those sobjects if any error occurred..

 

 

 

public LabAdmin__c getLabAdmin()
{

    return this.labadmin;

}

 

public Demographic__c getDemographic(){

return this.demographic ;
}

 

public void updateProfile()
{

if(labadmin.FName__c!=null && labadmin.LName__c!=null && labadmin.PEmail__c!=null && demographic.AddType__c!=null && demographic.AddLine1__c!=null)
{
LabAdminUpdateInformationError=false;
Savepoint labTechProfilesp = Database.setSavepoint();
try
{

update labadmin;
update demographic;
profileMainForm = true; //After click on UpdateButton it will render to Profle form
profileEditForm = false;
}
catch(Exception e)
{
ApexPages.addMessages(e);
profileMainForm = false; //After click on UpdateButton it will render to Profle form
profileEditForm = true;
Database.rollback(labTechProfilesp);

}

}
else
{
LabAdminUpdateInformationError=true;
}
}

 

Please Tell me what's wrong with my side in the UpdateProfile().

 

Thanks,

Yarram.

 

yarramyarram

HI,

 

Its working, But even displaying the error message with that wrong data also the wrong data is get Updated in that sobjects.

 

 

How it's possible?

 

That wrong data should not get updated those sobjects if any error occurred..

 

 

 

public LabAdmin__c getLabAdmin()
{

    return this.labadmin;

}

 

public Demographic__c getDemographic(){

return this.demographic ;
}

 

public void updateProfile()


if(labadmin.FName__c!=null && labadmin.LName__c!=null && labadmin.PEmail__c!=null && demographic.AddType__c!=null && demographic.AddLine1__c!=null)
{
LabAdminUpdateInformationError=false;
Savepoint labTechProfilesp = Database.setSavepoint();
try
{

update labadmin;
update demographic; 
profileMainForm = true; //After click on UpdateButton it will render to Profle form
profileEditForm = false; 
}
catch(Exception e)
{
ApexPages.addMessages(e); 
profileMainForm = false; //After click on UpdateButton it will render to Profle form
profileEditForm = true; 
Database.rollback(labTechProfilesp);

}

}
else
{
LabAdminUpdateInformationError=true;

}

 

Please Tell me what's wrong with my side in the UpdateProfile().

 

Thanks,

Yarram.

yarramyarram

Thanks tukmol.

Its working fine in LabAdmin Object. But i am facing same problem with Second(Demographics Object). Because of i am not initialized "demographic" in Class constructor. 

 

How can I resolve this. 

 

please give me Suggestion for this one.

.

 

 

global with sharing class LabAdminCtrl
{
public LabAdmin__c labadmin; //store the labadmin Information
public Demographic__c demographic; //store the Demographics Information

//Default constructor
public LabAdminCtrl()
{
labadmin= LabAdminUtil.getLabAdminDetails(LabadminId);
}
//Parameterised constructor
public LabAdminCtrl(String labId)
{
LabadminId = labId;
labadmin= LabAdminUtil.getLabAdminDetails(LabadminId);
}

// return the selected Labadmin record
public LabAdmin__c getLabAdmin()
{
// call method from LabadminUtil
return this.labadmin;
}


//Get demographics information from DemographicUtil and display in Profile form
public Demographic__c getDemographic(){

//get labadmin demographic information from demographic util by labadminid
demographic = DemographicsUtil.getLabAdminDemoraphicDetails(LabadminId);

return demographic ;

}

 

 }

tukmoltukmol

you can try putting the initialization of demographic in the constructor as well, just like labadmin, i.e.:

 

//Default constructor
public LabAdminCtrl()
{
   labadmin= LabAdminUtil.getLabAdminDetails(LabadminId);

   demographic = DemographicsUtil.getLabAdminDemoraphicDetails(LabadminId);
}
//Parameterised constructor
public LabAdminCtrl(String labId)
{
   LabadminId = labId;
   labadmin= LabAdminUtil.getLabAdminDetails(LabadminId);

   demographic = DemographicsUtil.getLabAdminDemoraphicDetails(LabadminId);
}

 

then remove/comment out the culprit line:

 

public Demographic__c getDemographic(){

//get labadmin demographic information from demographic util by labadminid
//demographic = DemographicsUtil.getLabAdminDemoraphicDetails(LabadminId); //this clears the fields

return demographic ;

}

yarramyarram

 

Thanks tukmol, Thanks alot.

 

I am getting solution without initialization of demographic in the constructor. 

 

Now its working fine. 

 

Thanks,

Yarram.