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
siva kumar 201siva kumar 201 

Need help?

Here are my apex controller and visual force page. And the problem is when I click on delete button all values entered in remaining sections are vanished
<apex:page standardController="Contact" extensions="RegFormController"
           title="Devotee Registration Page" showHeader="false" >

<style>
    .body{
    Width:980px;
    }
    .listHoverLinks{
    margin: 5px 6px 15px;
    font-size: 90%;
    text-align: center;
    display: block;
    line-height: 1.5em;
    }
    span.pipe{
    width:14px;
    height:9px;
    }
    .linklet{
    padding-top: 3px;
    padding-right: 0;
    padding-bottom: 6px;
    padding-left: 4px;
    position: relative;
    }
</style>
    <script>
    jQuery.noConflict();
    jQuery(function($){
        $(".buStyle").val($("[id$='buStyle']").val());
        $(".regionStyle").val($("[id$='regionStyle']").val());
        $(".areaStyle").val($("[id$='areaStyle']").val());
        $(".buDescStyle").val($("[id$='buDescStyle']").val());
        $(".chk").click(function() {
            if($(".chk").attr('checked')) {
                $("[id$='sstreet']").val($("[id$='pstreet']").val());
                $("[class^='sauto']").val($("[class^='pauto']").val());
                $('.cityStyle1').val($('.cityStyle').val());
                $('.stateStyle1').val($('.stateStyle').val())
                $('.countryStyle1').val($('.countryStyle').val());
                $("[id$='cityStyle1']").val($("[id$='cityStyle']").val());
                $("[id$='stateStyle1']").val($("[id$='stateStyle']").val());
                $("[id$='pinStyle1']").val($("[id$='pinStyle']").val());
                $("[id$='countryStyle1']").val($("[id$='countryStyle']").val());
                }
           else {
               $("[id$='sstreet']").val("");
               $("[class^='sauto']").val("");
               $('.cityStyle1').val("");
               $('.stateStyle1').val("")
               $('.countryStyle1').val("");
               $("[id$='cityStyle1']").val("");
               $("[id$='stateStyle1']").val("");
               $("[id$='pinStyle1']").val("");
               $("[id$='countryStyle1']").val("");  
                }
           });
           
        });
    
 </script>
    <apex:outputpanel >
        <apex:actionstatus id="actStatusId">
            <apex:facet name="start">
                <div class="waitingSearchDiv"  style="background-color: #DCD6D6;
                       height: 400%;opacity:0.75;width:100%;">
                    <div class="waitingHolder" style="Position: fixed; top:10;Left:0;Right:0;Bottom:0; width: 91px;">
                        <img  src="{!$Resource.loadingicon}" title="Please Wait..." />
                        <span >Fetching info...</span>
                    </div>
                </div>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputpanel>
    <center >
        <apex:form >
            <apex:image url="{!$Resource.YBanner}" />
            <div class="body">
                <apex:pageBlock title="Primary Member Details" mode="edit" >
                    <apex:pageblocksection columns="3" >
                        <apex:inputField value="{!newcon.FirstName}" required="true" />
                        <apex:inputField value="{!newcon.MiddleName__c}"/> 
                        <apex:inputField value="{!newcon.LastName}"/>
                        <apex:pageBlockSectionItem ><apex:outputlabel value="Postal Code & Village"></apex:outputlabel>
                            <apex:outputPanel >
                                <div class = "requiredInput">
                                    <div class = "requiredBlock"></div>
                                    <c:AutocompleteZipcodes labelField="Name" valueField="Id" SObject="Postal_Code__c" 
                                                            targetField="{!newcon.Postal_Code__c}" id="combobox" />
                                    <apex:inputHidden value="{!pinValue}" id="pinStyle"/>
                                </div>
                            </apex:outputPanel>
                        </apex:pageBlockSectionItem>
                        <apex:pageBlockSectionItem >
                            <apex:outputLabel value="Phone"/>
                            <apex:panelGrid columns="2">
                                <apex:inputField value="{!Contact.Ccode__c}"  style="width:30px;" />
                                <apex:inputField value="{!Contact.Phone}"  required="true" style="Width:125px" />
                            </apex:panelGrid>
                        </apex:pageBlockSectionItem>
                        <apex:inputField value="{!Contact.Language__c}" style="Width:173px" />
                        <apex:inputField value="{!Contact.Street_Adress__c}" label="Street Adress" style="Width:168px"/>
                        <apex:inputField value="{!Contact.Adress_Line2__c}" label="Adress Line2" style="Width:168px"/>
                        <apex:pageBlockSectionItem >
                            <apex:outputlabel value="District"></apex:outputlabel>
                            <apex:outputPanel >
                                <apex:inputtext disabled="true" styleClass="cityStyle"  value="{!newcon.District__c}"/>
                                <apex:inputHidden value="{!cityValue}" id="cityStyle"/>
                            </apex:outputPanel>
                        </apex:pageBlockSectionItem>
                        <apex:pageBlockSectionItem >
                            <apex:outputlabel value="State"></apex:outputlabel>
                            <apex:outputPanel >
                                <apex:inputtext disabled="true" styleClass="stateStyle"  value="{!newcon.State__c}"/>
                                <apex:inputHidden value="{!stateValue}" id="stateStyle"/>
                            </apex:outputPanel>
                        </apex:pageBlockSectionItem>
                        <apex:pageBlockSectionItem >
                            <apex:outputlabel value="Country"></apex:outputlabel>
                            <apex:outputPanel > 
                                <apex:inputtext disabled="true" styleClass="countryStyle"   value="{!newcon.Country__c}"/>
                                <apex:inputHidden value="{!countryValue}" id="countryStyle"/>
                            </apex:outputPanel>
                        </apex:pageBlockSectionItem>
                        <apex:inputField value="{!Contact.Email}" />
                        <apex:inputField value="{!Contact.Profession__c}" label="Profession"  />
                        <apex:inputField value="{!Contact.Rasi_Zodiac_Sign__c}"  label="Rasi/Zodiac Sign"  style="Width:175px" />
                        <apex:inputField value="{!Contact.Nakshatram_Birth_Star__c}" label="Nakshatram/Birth Star"  style="Width:175px"  />
                        <apex:inputField value="{!Contact.Gotram__c}"  label="Gotram" />
                        <apex:pageBlockSectionItem ><b>Your Picture (Wearing Datta Vastram)</b>
                        <apex:inputFile value="{!picture}" accept="image/*" /></apex:pageBlockSectionItem> 
                        <apex:inputField value="{!Contact.Do_You_Volunteer__c}"  style="Width:175px" />
                        <apex:inputfield value="{!Contact.Volunteer_skills__c}"  />
                        <apex:outputPanel id="panel">
                            <apex:actionRegion >
                                <apex:outputLabel value="How many additional family members do you like to register?" 
                                                  styleclass="labelCol vfLabelColTextWrap"/>
                                <apex:inputField value="{!Contact.add__c}"  style="Width:175px" >
                                    <apex:actionSupport action="{!addcontacts}"  event="onchange" reRender="additonalContacts"
                                                        status="actStatusId" />
                                </apex:inputField>
                            </apex:actionRegion>
                        </apex:outputPanel>
                    </apex:pageblocksection>
                    
                    
                    <apex:pageBlockSection id="additonalContacts" collapsible="true">
                        <apex:variable value="{!0}" var="x"/>
                        <apex:param value="{!x+1}" />
                        <apex:repeat value="{!newconList}"  var="c"   >
                            <apex:pageBlocksection title="Additional Member {!x+1} "  columns="3" >
                                <apex:inputField value="{!c.cont.FirstName}" required="true"   />
                                <apex:inputField value="{!c.cont.MiddleName__c}"/>
                                <apex:inputField value="{!c.cont.LastName}"/>
                                <apex:inputField value="{!c.cont.Postal_Code__c}" label="Postal Code & Village"/>
                                <apex:pageBlockSectionItem >
                                    <apex:outputLabel value="Phone"/>
                                    <apex:panelGrid columns="2">
                                        <apex:inputField value="{!c.cont.Ccode__c}"  style="width:30px;" />
                                        <apex:inputField value="{!c.cont.Phone}"  required="true" style="Width:125px" />
                                    </apex:panelGrid>
                                </apex:pageBlockSectionItem>
                                <apex:inputField value="{!c.cont.Language__c}" style="Width:173px"  />
                                <apex:inputField value="{!c.cont.Street_Adress__c}" label="Street Adress" style="Width:168px" />
                                <apex:inputField value="{!c.cont.Adress_Line2__c}" label="Adress Line2" style="Width:168px" />
                                <apex:inputField value="{!c.cont.District__c}" label="District" />
                                <apex:inputField value="{!c.cont.State__c}" label="State" />
                                <apex:inputField value="{!c.cont.Country__c}" label="Country" />
                                <apex:inputField value="{!c.cont.Email}" />
                                <apex:inputField value="{!c.cont.Profession__c}" label="Profession" />
                                <apex:inputField value="{!c.cont.Rasi_Zodiac_Sign__c}"  label="Rasi/Zodiac Sign" style="Width:175px"/>
                                <apex:inputField value="{!c.cont.Nakshatram_Birth_Star__c}" label="Nakshatram/Birth Star"  style="Width:175px" />
                                <apex:inputField value="{!c.cont.Gotram__c}"  label="Gotram"/>
                                <apex:pageBlockSectionItem ><b>Your Picture (Wearing Datta Vastram)</b>
                                <apex:inputFile value="{!c.picture}" accept="image/*" /></apex:pageBlockSectionItem>        
                                <apex:inputField value="{!c.cont.Do_You_Volunteer__c}"  style="Width:175px" />
                                <apex:inputfield value="{!c.cont.Volunteer_skills__c}"   />
                                <apex:actionRegion >
                                    <apex:commandButton action="{!deletecon}" value="Delete"
                                                        status="actStatusId" reRender="additonalContacts,panel" >
                                        <apex:param name="rowIndex" value="{!x}" />
                                    </apex:commandButton>
                                </apex:actionRegion>
                                
                            </apex:pageBlocksection>
                            <apex:variable value="{!x+1}" var="x"/>
                        </apex:repeat></apex:pageBlockSection>
                    <apex:pageBlockButtons location="bottom" >
                        <apex:commandButton action="{!save}" value="Submit" />
                        <apex:commandButton action="{!Cancel}" value="Cancel" />
                    </apex:pageBlockButtons>
                </apex:pageBlock>
            </div>
        </apex:form>
    </center>
</apex:page>
 
public with sharing class RegFormController {
    public Contact newCon {get;set;}
    public List<blob> pictureList {get;set;}
    public blob picture {get;set;}
    public String errorMessage {get;set;}
    public boolean add {get;set;}
    public List<contact> conlist {get;set;}
    public List<ContactWrapper> newConList {get;set;}
    public integer TotalMembers {get;set;}
    public integer rowIndex {get;set;}
    public Account a;
    private final Contact image;
    public String pinValue {get;set;}
    public String cityValue {get;set;}
    public String stateValue {get;set;}
    public String countryValue {get;set;}
    public String countyValue {get;set;}
    public String pinValue1 {get;set;}
    private ApexPages.StandardController stdController;
    
    public RegFormController (ApexPages.StandardController stdController) {
        this.image = (Contact)stdController.getRecord();
        this.stdController = stdController;
        conlist = new List<contact>();
        TotalMembers = 0 ;
        rowIndex = 0;
        newConList = new List<ContactWrapper>();
        id id1 = ApexPages.currentPage().getParameters().get('recordtype');
        string s = ApexPages.currentPage().getParameters().get('rTypeName');
        id id2 = Apexpages.currentpage().getparameters().get('id');
        newcon  = (Contact)stdcontroller.getRecord();
        
        
        if(id2 != null) {
            
            newcon= [select name,postal_code__c,MailingPostalcode,MailingCity,State__c,Country__c from contact where id=:id2];
            
        pinValue=  newcon.postal_code__c;
        cityValue= newcon.District__c;
        stateValue=newcon.State__c;
        countryValue =newcon.Country__c ;
    }
}
  
    public void addcontacts() {
       // String s = (String)ApexPages.currentPage().getParameters().get('text');
       // System.debug('debug s '+s);
       System.debug('newcon '+newcon.FirstName);
        if(newcon.add__c != null) 
            TotalMembers = integer.valueOf(newcon.add__c);
        else
        TotalMembers =0;
        newConList.clear();
        if(TotalMembers >0 ) {
            for(Integer i = 1; i <= TotalMembers; i++) {
                ContactWrapper c = new ContactWrapper();
                c.cont.Ccode__c = '+91';
                //c.cont.Postal_code__c = '517325,Madanapalli';
                //c.cont.District__c = 'Chittor';
                //c.cont.State__c ='ANDHRAPRADESH';
                //c.cont.country__c ='INDIA';
                newconlist.add(c);
            }
        }
    }
    public void deletecon() {
        rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
        newconlist.remove(rowIndex);
        
        if(newConList.size()>0)
            newcon.add__c = String.Valueof(newConList.size());
        else
            newcon.add__c = null;
            rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
        
        if(newConList.size()>0)
            newcon.add__c = String.Valueof(newConList.size());
        else
            newcon.add__c = null;
    }
    public pagereference save() {
        if( newCon.MiddleName__c == null) {
            newCon.MiddleName__c = '';
        }
        a = New Account(Name = newCon.FirstName + ' ' + newCon.MiddleName__c+ ' ' + newCon.LastName ,Phone=newcon.ccode__c+' '+newcon.Phone,
                             postal_code__c= newcon.Postal_Code__c,billingStreet = newcon.Street_Adress__c,
                             BillingState = newcon.State__c, BillingCountry = newcon.Country__c,
                             billingcity=newcon.District__c,recordTypeId = '01241000000rvGd'); 
        pinValue1=  a.postal_code__c;
        insert a;
        newCon.AccountID = a.id;
        insert newCon;
        errorMessage = '';
        try{
            newcon.postal_code__c = pinvalue ; 
            newcon.District__c = cityValue;
            newcon.Country__c = countryValue;
            newcon.State__c = stateValue;
            a.postal_code__c = pinValue1;
            upsert newCon;
            
            if (picture != null) {
                Attachment attachment = new Attachment();
                attachment.body = picture;
                attachment.name = 'image_' + newCon.id + '.jpg';
                attachment.parentid = newCon.id;
                attachment.ContentType = 'application/jpg';
                insert attachment;
                newCon.Picture_Path__c = '/servlet/servlet.FileDownload?file='+ attachment.id;
                update newCon;
            }
        }
        catch(System.Exception ex) {
            errorMessage = ex.getMessage();
            return null;
        }
        for(ContactWrapper cw : newConList) {
            cw.cont.AccountId = a.id;
            insert cw.cont;    
        }
        for(contactWrapper contacts : newconlist) {
            
            try {
                if (contacts.picture!= null) {
                    Attachment attachment = new Attachment();
                    attachment.body = contacts.picture;
                    attachment.name = 'image_' + contacts.cont.id + '.jpg';
                    attachment.parentid = contacts.cont.id;
                    attachment.ContentType = 'application/jpg';
                    insert attachment;
                    contacts.cont.Picture_Path__c = '/servlet/servlet.FileDownload?file='+ attachment.id;
                }
                upsert contacts.cont;
            }
            catch(System.Exception ex) {
                errorMessage = ex.getMessage();
                return null;
            }
        }
        return new pagereference('/apex/Thank_u');
    }
}
Peter FribergPeter Friberg
I think the problem is that by definition an apex command button in a form will either refresh the page/form or navigate to a new page depending no the attributes set on the button. Check https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_commandButton.htm where it says "The button executes an action defined by a controller, and then either refreshes the current page, or navigates to a different page based on the PageReference variable that is returned by the action.​".