I have one Custom Object Patient__c.On VF page onclick of commandlink button I am filling all the correspondant fields of Patient like firstname, middle name like that. I am getting the particular id also. Now my requirment is this to insert the new patient if we did not get the id from SQL query else update the patient if we got the id. Suppose the variable name in which I am getting the id is PatientID on Apex page
Please tell me I got stuck here ??
Controller
public class ExtentionController1
{
public Patient__c objPatient {get;set;}
public string PatientID{get;set;}
public ExtentionController1()
{
objPatient = new Patient__c();
objAccession = new Case_Accession__c();
}
public PageRefrence save()
{
insertpatient()
upsert objPatient;
return Null;
objAccession.Patient__c = objPatient.id;
}
public void insertPatient()
{
if( Patientid == null )
{
objPatient = new Patient__c();
}
else
{
objPatient = [select ID,name,FirstName__c,LastName__c,MiddleName__c from Patient__c where id = :Patientid ];
}
}
}
Visualforce Page
<apex:page Controller="ExtentionController1" >
<apex:form >
<apex:pageblock title="Accessioning" >
<apex:dataTable id="dtPatientRecords" value="{!objPatientList}" var="pt" width="100%" >
<apex:param name="PatientID" assignTo="{!PatientID}" value="{!pt.id}"/>
<apex:pageBlockSection title="Patient">
<apex:inputHidden value="{!PatientID}"/>
<label> Patient ID </label>
<apex:inputText value="{!testPatientid}"/>
<apex:inputField value="{!objPatient.FirstName__c}" />
<apex:inputField value="{!objPatient.MiddleName__c}" />
<apex:inputField value="{!objPatient.LastName__c}" />
<apex:inputField value="{!objPatient.Address__c}"/>
<apex:inputField value="{!objPatient.Country__c}"/>
<apex:inputField value="{!objPatient.State__c}"/>
<apex:inputField value="{!objPatient.City__c}"/>
<apex:inputField value="{!objPatient.Gender__c}"/>
<apex:inputField value="{!objPatient.DOB__c}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons>
<apex:commandButton action="{!save}" value="Done"/>
</apex:pageBlockButtons>
</apex:pageblock>
</apex:form>
</apex:page>
FYI :: I am getting the patientid no issues in that, I cheked with static id also but no success, please help me !!!
Regards Raman
testPatientid
in Vf page then if the record exists you want to update that record with all the values you entered in the VF page otherwise create a new record and fill it with all the values from VF pages – Prady Jul 12 '13 at 6:43