Skip to main content
i have an custom object called Drink_order

in that i have flavor,size and price fields

 i want to autoupdate price field depending upon the user selecting flavor and size

eg: flavor is apple

and size is large

can anyone please help me.
3 answers
  1. Feb 7, 2019, 2:14 PM
    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:

    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;

    }

    }

    I hope it helps you.

    Kindly mark this as solved if the information was helpful. It will help to keep this community clean.

    Regards,

    Khan Anas
0/9000