Hi Mohan,Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.Note: You can change the Object name and fields name as per your requirement.Visualforce: <apex:page controller="AutofillBasedOnPicklist">
<apex:form >
<apex:pageBlock >
Rating: <apex:selectList size="1" value="{!selectedRating}" multiselect="false">
<apex:actionSupport event="onchange" action="{!pageLoad}" reRender="t"/>
<apex:selectOptions value="{!RList}"/>
</apex:selectList>
<apex:pageBlockSection>
<apex:inputField value="{!acc.Amount__c}" id="t"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex:
I hope it helps you.Kindly mark this as solved if the information was helpful. It will help to keep this community clean.public class AutofillBasedOnPicklist {
public string string1 {get;set;}
public List<User> UserTemp = new List<User>();
public string selectedRating {get;set;}
public Account acc {get;set;}
public AutofillBasedOnPicklist(){
acc = new Account();
}
public List<SelectOption> getRList() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('--None--', ''));
Schema.DescribeFieldResult fieldResult = Account.rating.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple) {
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
public PageReference pageLoad() {
if(selectedRating == 'Hot'){
acc.Amount__c=300;
}
if(selectedRating == 'Warm'){
acc.Amount__c=200;
}
if(selectedRating == 'Cold'){
acc.Amount__c=100;
}
return null;
}
}
Regards,
Khan Anas
3 answers