• #27448
    Forcetalks

    I want that only my contact section will refresh when i click on delete button

    I want that only my contact section will refresh when i click on delete button

    <apex:page controller="AccountWithConPicklist" sidebar="false">
    <apex:form >
    <apex:pageBlock title="Account Name">
    Account Names
    <apex:selectList value="{!AccId}" size="1">
    <apex:selectOptions value="{!AccountNames}"/>
    <apex:actionSupport event="onchange" reRender="a" action="{!showContact}"/>
    </apex:selectList>
    <apex:pageBlock title="Contacts" id="a">
    <apex:messages />
    <apex:pageBlockTable value="{!listWrapper}" var="wrap">
    <apex:column >
    <apex:inputCheckbox value="{!wrap.checked}"/>
    </apex:column>
    <apex:column headerValue="Name">
    <apex:outputText value="{!wrap.con.Name}" rendered="{!!wrap.checked}"/>
    <apex:inputText value="{!wrap.con.Name}" rendered="{!wrap.checked}"/>
    </apex:column>
    
    <apex:column headerValue="Phone">
    <apex:outputText value="{!wrap.con.Phone}" rendered="{!!wrap.checked}"/>
    <apex:inputText value="{!wrap.con.Phone}" rendered="{!wrap.checked}"/>
    </apex:column>
    
    <apex:column headerValue="Email">
    <apex:outputText value="{!wrap.con.Email}" rendered="{!!wrap.checked}"/>
    <apex:inputText value="{!wrap.con.Email}" rendered="{!wrap.checked}"/>
    </apex:column>
    
    </apex:pageBlockTable>
    <apex:pageBlockButtons >
    <apex:commandButton value="Delete" action="{!del}"/>
    <apex:commandButton value="Edit" action="{!edit}"/>
    <apex:commandButton value="Save" action="{!save}"/>
    <apex:commandButton value="Cancel" action="{!cancel}"/>
    </apex:pageBlockButtons>
    </apex:pageBlock>
    </apex:pageBlock>
    </apex:form>
    </apex:page>
    
    
    

     

    public class AccountWithConPicklist
    {
    public String AccId{get;set;}
    public list<contact> Conlist{get;set;}
    
    public List<SelectOption> getAccountNames()
    {
    List<SelectOption> accOptions= new List<SelectOption>();
    accOptions.add( new SelectOption('','--Select--'));
    for( Account acc : [select Id,name from Account ] )
    {
    accOptions.add( new SelectOption(acc.Id,acc.name));
    }
    return accOptions;
    }
    public List<WrapperClass> listWrapper {get;set;}
    public void showContact()
    {
    listWrapper = new List<WrapperClass>();
    List<Contact> conlist = [SELECT Name,Phone,Email FROM contact where accountid=:AccId AND Name like 'a%'];
    if(conlist.size()>0)
    {
    for(contact con:conlist)
    {
    listWrapper.add(new WrapperClass(con));
    }
    }
    }
    public class WrapperClass
    {
    public Boolean checked {get;set;}
    public contact con {get;set;}
    public WrapperClass(contact con)
    {
    this.con=con;
    checked=false;
    }
    }
    public PageReference del()
    {
    
    List<Contact> listconForDel=new List<Contact>();
    List<WrapperClass> listconWrapper = new List<WrapperClass>();
    for(WrapperClass w : listWrapper)
    {
    if(w.checked==true)
    {
    listconForDel.add(w.con);
    }
    else
    {
    listconWrapper.add(w);
    }
    }
    system.debug('listconWrapper----'+listconWrapper.size());
    system.debug('listconForDel----'+listconForDel.size());
    if(listconForDel.size()>0)
    {
    delete listconForDel;
    listWrapper=listconWrapper;
    return NULL;
    }
    else
    {
    system.debug('---------------');
    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Select atleast one employee to delete')); return NULL;
    }
    }
    public PageReference edit()
    {
    return null;
    }
    public PageReference save()
    {
    return null;
    }
    public PageReference cancel()
    {
    return null;
    }
    }
    

    Tagged: , , , , , ,

    #27497
    Salesforce | Manpreet Manpreet #3
    Forcetalks

    Hi Raghav,

    You need to use Rerender while pressing that Delete commandButton something like this :

    <apex:commandButton value=”Delete” reRender=”a” action=”{!del}”/>

    Thanks.

Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?