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
AnithaThanAnithaThan 

Unable to Use Satndard Feild "Name" of Account Object & Product Lookup in Visualforce Page

Hi Folks!!


I have created a vf page using Account Satndard Controller. Here my Requirement is "Account_Type__C"((Custom Feild Picklist Type with Doctor/Chemist values). Save the Block of Info to Account Object dependin on the Selected Value.


Here no recordtypes its PE. So i have used javascript. Unable to Save Chemist Info coz the "Error: Required fields are missing: [Name]"

One more problem is while selecting product form lookup in chemist block it is get selected in Doctor Block instead of chemist. Why???????? it is always taking first feild into consideration....though i have used id's differently...


Please Suggest a better solution for this ASAP.


My Code is as Follows....

========================================================


<apex:page standardController="Account">
    <apex:form id="myFirstForm">
        <script src="/soap/ajax/18.0/connection.js"></script>
        <script type="text/javascript">
            window.onload = LoadDefaultData;
            sforce.connection.sessionId = "{!$Api.Session_ID}";
            function LoadDefaultData()
            {
                document.getElementById("{!$Component.myFirstForm.docpgblkid}").style.display= 'none';
                document.getElementById("{!$Component.myFirstForm.chempgblkid}").style.display= 'none';
                document.getElementById("{!$Component.myFirstForm.actionblockid}").style.display= 'none';
            }
            function GetSelectedAccountInfo()
            {
               var selectedaccounttype = document.getElementById("{!$Component.myFirstForm.acctypepgblkid.acctypepgblksecid.acctypeid}").value;
               if(selectedaccounttype=="")
               {
                    document.getElementById("{!$Component.myFirstForm.docpgblkid}").style.display= 'none';
                    document.getElementById("{!$Component.myFirstForm.chempgblkid}").style.display= 'none';
                    document.getElementById("{!$Component.myFirstForm.actionblockid}").style.display= 'none';
                    alert('Please Select An Account Type');                     
               }
               else if(selectedaccounttype=="Doctor")
               {
                    document.getElementById("{!$Component.myFirstForm.docpgblkid}").style.display= 'block';
                    document.getElementById("{!$Component.myFirstForm.chempgblkid}").style.display= 'none';
                    document.getElementById("{!$Component.myFirstForm.actionblockid}").style.display= 'block';
               }
               else if(selectedaccounttype=="Chemist")
               {
                    document.getElementById("{!$Component.myFirstForm.docpgblkid}").style.display= 'none';
                    document.getElementById("{!$Component.myFirstForm.chempgblkid}").style.display= 'block';
                    document.getElementById("{!$Component.myFirstForm.actionblockid}").style.display= 'block';                    
               }
            }
        </script>
        <apex:PageBlock id="acctypepgblkid">
            <apex:pageBlockSection id="acctypepgblksecid" title="Account Type Section">
                <apex:inputField id="acctypeid" value="{!Account.Account_Type__c}" onchange="GetSelectedAccountInfo()" >
                </apex:inputField>
            </apex:pageBlockSection>
        </apex:PageBlock>
        <apex:PageBlock id="docpgblkid">    
            <apex:pageBlockSection id="docbaseinfopgblksecid" title="Doctor Basic Information">
                <apex:inputField id="doctornameid" value="{!Account.Name}" required="false"/>
                <apex:inputField id="doctorcodeid" value="{!Account.Account_Code__c}"/>

                <apex:inputField id="productid" value="{!Account.Product__c}"/>
                <apex:inputField id="hospitalid" value="{!Account.Hospital__c}"/>
                <apex:inputField id="emailid" value="{!Account.Email__c}"/>
                <apex:inputField id="phonenoid" value="{!Account.Phone__c}"/>
            </apex:pageBlockSection>
        </apex:PageBlock>
        <apex:PageBlock id="chempgblkid">
            <apex:pageBlockSection id="chempgblksecid" title="Chemist Information" >
                <apex:inputField id="chemistnameid" value="{!Account.Name}" required="false"/>
                <apex:inputField id="chemistcodeid" value="{!Account.Account_Code__c}"/>
                <apex:inputField id="chemistproductid" value="{!Account.Product__c}"/>
                <apex:inputField id="chemistemailid" value="{!Account.Email__c}"/>
                <apex:inputField id="chemistphonenoid" value="{!Account.Phone__c}"/>
                <apex:inputField id="chemistdescid" value="{!Account.Description}"/>
            </apex:pageBlockSection>
        </apex:PageBlock>
        <apex:PageBlock id="actionblockid">            
            <apex:pageBlockButtons location="bottom" >
                <apex:commandButton id="btnSave" action="{!save}" value="Save"/>
                <apex:commandButton id="btnCancel" onclick="ClearFeilds()" value="Cancel"/>
            </apex:pageBlockButtons>
        </apex:PageBlock>
    </apex:form>
</apex:page>


========================================================


Thanks!!!!!!!!!

Sanjana.

new2forcenew2force

If I were right, depending on the id value, u r trying to give different input. One block is displayed evrytime based on id value but still the other block is in the page but invsible. so since the name is mandatory, it is throwing an error. then i observed u added atttrtibute required="false". i think it will not overrride the standard mandatory field. in the VF page if u see red bar beside the name input label, then definitely u cannot override the required attribute value.

 

to overcome this problem , as far as I know, it is better to use just one name field.

 

hope u got my point. wait n see, other people may come up with better solution

AnithaThanAnithaThan

Thak you..

 

I will try to Show/Hide the Feilds instead of Blocks then it wont be a problem......