You need to sign in to do that
Don't have an account?
Varun Teja
How to add total number of contacts in custom field if we click add another contact button in VF page
I have created one custom filed i.e. Total_Contacts_Added_till_Now__c In contact object,In VF page If We click 'Add More Contacts' button ,Total_Contacts_Added_till_Now__c value should be increasd to 1, if I click one more time 'Add More Contacts' button that filed should be automatically increased to 2 .Please help me on this how to do.
<apex:page standardController="Contact">
<apex:form >
<apex:pageBlock title="Insert Contact Record">
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockSection >
<apex:outputText label="Account Name" value="{!$CurrentPage.parameters.accountName}" />
<apex:inputField value="{! Contact.FirstName }" />
<apex:inputField value="{! Contact.LastName }" />
<apex:inputField value="{! Contact.Birthdate }" />
<apex:inputField value="{! Contact.Description }" />
<apex:inputField value="{! Contact.Email }" />
<apex:inputField value="{! Contact.HomePhone }" />
<apex:inputField value="{! Contact.Level__c }" />
<apex:inputField id="total" value="{!Contact.Total_Contacts_Added_till_Now__c}" />
</apex:pageBlockSection>
<apex:pageblockButtons location="bottom">
<apex:commandButton style="float:centre" action="{! addMoreContacts }" value="Add More Contacts" />
<apex:commandButton style="float:centre" value="I don't want to create contact" />
<apex:commandButton style="float:centre" value="Submit Contact's" />
</apex:pageblockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:page standardController="Contact">
<apex:form >
<apex:pageBlock title="Insert Contact Record">
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockSection >
<apex:outputText label="Account Name" value="{!$CurrentPage.parameters.accountName}" />
<apex:inputField value="{! Contact.FirstName }" />
<apex:inputField value="{! Contact.LastName }" />
<apex:inputField value="{! Contact.Birthdate }" />
<apex:inputField value="{! Contact.Description }" />
<apex:inputField value="{! Contact.Email }" />
<apex:inputField value="{! Contact.HomePhone }" />
<apex:inputField value="{! Contact.Level__c }" />
<apex:inputField id="total" value="{!Contact.Total_Contacts_Added_till_Now__c}" />
</apex:pageBlockSection>
<apex:pageblockButtons location="bottom">
<apex:commandButton style="float:centre" action="{! addMoreContacts }" value="Add More Contacts" />
<apex:commandButton style="float:centre" value="I don't want to create contact" />
<apex:commandButton style="float:centre" value="Submit Contact's" />
</apex:pageblockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
You may use the following code that will populate the total contact and increase by 1 after clicking the Add more contacts.
Let me know if this helps you.
--
Thanks,
Prashant