Get detail page :-12/27/12
We have a scenario , In the controller Create an object instance and use it in VF page.
Enter values for the object fields in VF page and save button upserts value
in that object if id exist in url then update else insert.
And it should go into Detail page not Record page.
<apex:page controller="practice1">
<apex:form id="main">
<apex:pageBlock >
<apex:pageBlockSection title="Account Section" columns="1" id="thePageBlock" rendered="{!showtable==false}">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Account ID"/>
<apex:inputText value="{!str}"/>
</apex:pageBlockSectionItem>
<apex:inputField value="{!accobj.Name}"/>
<apex:inputField value="{!accobj.AccountNumber}"/>
<apex:inputField value="{!accobj.Active__c}"/>
<apex:inputField value="{!accobj.Phone}"/>
<apex:inputField value="{!accobj.Type}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:outputPanel >
<apex:commandButton value="Save" action="{!cussave}">
<apex:actionSupport event="onclick" rerender="thePageBlock"
status="status"/>
<apex:actionStatus startText="saving values..." id="status"/>
</apex:commandButton>
</apex:outputPanel>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Account Values" rendered="{!showtable==true}">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Account ID"/>
<apex:outputText value="{!str}"/>
</apex:pageBlockSectionItem>
<apex:outputField value="{!accobj.Name}"/>
<apex:outputField value="{!accobj.AccountNumber}"/>
<apex:outputField value="{!accobj.Active__c}"/>
<apex:outputField value="{!accobj.Phone}"/>
<apex:outputField value="{!accobj.Type}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class practice1 {
public String str { get; set; }
Public Account accobj{get;set;}
public boolean showtable{get;set;}
public practice1 (){
accobj=new Account();
}
public void cussave(){
try{
Account acc=new Account();
List<Account> varacc=[select id,name,AccountNumber,Active__c,Phone,Type from Account Where id=:str];
if(varacc.size()!=0){
varacc[0].Name=accobj.Name;
varacc[0].AccountNumber=accobj.AccountNumber;
varacc[0].Active__c=accobj.Active__c;
varacc[0].Phone=accobj.Phone;
varacc[0].Type=accobj.Type;
update varacc[0];
}
else{
acc.Name=accobj.Name;
acc.AccountNumber=accobj.AccountNumber;
acc.Active__c=accobj.Active__c;
acc.Phone=accobj.Phone;
acc.Type=accobj.Type;
insert acc;
str=acc.id;
}
showtable=true;
}
catch(Exception e){
}
}
}
No comments:
Post a Comment