• Saie Shendage 7
  • NEWBIE
  • 50 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 19
    Replies
I have to show a report on account object where reason is a multi select picklist. Suppost fot Account 1, if reasons selected are A;B;C,
then the repost should be generated like :
Account Number |    Reason
Account 1            |       A
Account 1            |       B
Account 1            |       C

Please help with the answer if anyone knows
<aura:component controller="AccountRelatedContacts"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="PageHeading" type="String" default="Account and Related Contacts" />
    <!--aura:attribute name="accData" type="List"/>
    <aura:attribute name="conData" type="List"/-->
    <aura:attribute name="show" type="boolean" default="false"/>
    <aura:attribute name="AccountContactWrapper" type="AccConWrapper"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doinit}" />
    
    <div class=" slds-page-header slds-text-heading--large slds-align--absolute-center">       
        {!v.PageHeading}              
    </div>
    <div class="slds-section slds-is-open">
        <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
            <thead>
                <tr class="slds-text-heading--label">
                    <th scope="col"><div class="slds-truncate" title="Account Name">Account Name</div></th>
                    <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>
                </tr>
            </thead>
            <tbody>
                <aura:iteration items="{!v.AccountContactWrapper.accountInfoList}" var="row" indexVar="index">
                    <tr>
                        <th scope="row">
                            <div class="slds-truncate" >
                                <lightning:input name="accName" disabled="true" value="{!row.accName}"/>
                                <!--a onclick="{!c.showCon}" value="{!row}" data-index="{!index}"-->
                            </div>
                        </th>
                        <td><div class="slds-truncate" title="{!row.Phone}">
                            	<lightning:input name="accPhone" disabled="true" value="{!row.accPhone}"/>
                            </div>
                        </td>
                        <td><lightning:button 
                             	label="View Contacts" value="{!index}" onclick="{!c.showCon}" variant="brand"/>
                        </td>
                        <aura:renderIf isTrue="{!v.show}">
                        	<div class="slds-section slds-is-open">
                            <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
                                <thead>
                                    <tr class="slds-text-heading--label">
                                        <th scope="col"><div class="slds-truncate" title="Contact Name">Contact Name</div></th>
                                        <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <aura:iteration items="{!row.relatedContactInfoList}" var="row2">
                                        <tr>
                                            <th scope="row">
                                                <div class="slds-truncate" title="{!row2.Name}">
                                                    <lightning:input name="conName" disabled="true" value="{!row2.conName}"/>
                                                </div>
                                            </th>
                                            <td>
                                                <div class="slds-truncate" title="{!row2.Phone}">
                                                    <lightning:input name="conPhone" disabled="true" value="{!row2.conPhone}"/>
                                                </div>
                                            </td>
                                        </tr>
                                    </aura:iteration>
                                </tbody>
                            </table>
                        </div>
                    	</aura:renderIf>
                    </tr>
                </aura:iteration>
            </tbody>
        </table>
    </div>
    <br/>
    
</aura:component>
 
public class AccConWrapper {
	@AuraEnabled public list<AccountInfo> accountInfoList;
    
    public class AccountInfo{
        @AuraEnabled public String accName;
        @AuraEnabled public String accPhone;
        @AuraEnabled public list<RelatedContactInfo> relatedContactInfoList;
        @AuraEnabled public Boolean showContacts;
        public AccountInfo(){
            showContacts=false;
        }
    }
    
    public class RelatedContactInfo{
        @AuraEnabled public String conName;
        @AuraEnabled public String conPhone;
    }
}
 
public class AccountRelatedContacts {
    @AuraEnabled
    public static AccConWrapper getAccConWrapperList() {
        AccConWrapper ac = new AccConWrapper();
        ac.accountInfoList = new List<AccConWrapper.AccountInfo>();
        for(Account a: [SELECT Id, Name, Phone, (select name,phone from contacts) FROM Account where Id in (Select AccountId from Contact) LIMIT 5])
        {
            AccConWrapper.AccountInfo az = new AccConWrapper.AccountInfo();
            az.accName= a.Name;
            az.accPhone= a.Phone;
            az.relatedContactInfoList = new List<AccConWrapper.RelatedContactInfo> () ;  
            for(Contact c: a.Contacts)
            {
                AccConWrapper.RelatedContactInfo cz = new AccConWrapper.RelatedContactInfo();
                cz.conName= c.Name;
                cz.conPhone= c.Phone;
                az.relatedContactInfoList.add(cz);
            }
            ac.accountInfoList.add(az);
        }
        return ac;        
    }
    
}
 
//aura component js controller
({
    doinit : function(component, event, helper) {
        var action = component.get('c.getAccConWrapperList');
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                var allValues = response.getReturnValue();
                console.log("allValues--->>> " + allValues);
                component.set('v.AccountContactWrapper', allValues);
            }
            else if(state === "ERROR") {
                var errors = response.getError();
                if(errors){
                    if(errors[0] && errors[0].message){
                        console.log("Error Message: " + errors[0].message);
                    }
                }
                else{
                    console.log("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
    },
    
    showCon : function(component, event, helper){
        var AccountContactWrapper = JSON.stringify(component.get("v.AccountContactWrapper"));
        var idx = event.getSource().get("v.value");
        console.log('index',idx)
        
        component.set("v.show",true);
        
    }
}

User-added imageThis is how my UI looks like. When I click on View Contacts button contacts related to all the accounts get fetched. But I dont want that. I want contacts related to only that account on which button was clicked. Please help me.
I am inserting one custom object on visualforce page form using custom controller. On clicking save button the record gets inserted. If the record is inserted successfully, I want to display one alert message 'Record saved successfully'/
Please help out. 
<apex:page controller="Page2_Controller">
    <apex:pageBlock >
    	<apex:pageBlockSection >
        	<apex:pageBlockTable value="{!Societies}" var="s">
                
                <apex:column value="{!s.name}"/>
                <apex:column value="{!s.Secretary__c}"/>
                <apex:column value="{!s.No_of_Members__c}"/>
                <apex:column >
                    <apex:facet name="header">Location</apex:facet>
                    <apex:outputLink value="https://maps.google.com" target="new">
                    <apex:outputText value="{!s.Location__c}"/>
                    	<apex:param name="q" value="{!s.Location__c}"/>
                    </apex:outputLink>
        		</apex:column>
    		</apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
    
    <apex:form >
        <apex:inputHidden value="{!startingFrom}"/>
        <apex:panelGrid columns="2" cellpadding="2px">
            <apex:commandLink action="{!previous}" value="Previous"/>
            <apex:commandLink action="{!next}" value="Next"/>
        </apex:panelGrid>
    </apex:form>
    
</apex:page>
 
public class Page2_Controller {
    private final integer MAX_RECORDS_PER_PAGE = 5;
    public integer startingFrom {get; set;}
    private integer socRecordCount; 
	//View Society
    public Page2_Controller(){
        if(startingFrom == NUll)
            startingFrom=0;
        socRecordCount = [select count() from Society__c];
    }
    public List<Society__c> getSocieties(){
        List<Society__c> results=[select name,Secretary__c,No_Of_Members__c,location__c 
                                  from Society__c limit :MAX_RECORDS_PER_PAGE
               offset : startingFrom];
        return results;  
    }
    
    public PageReference previous()
    {
     	if(startingFrom <= 0)
        {   
            startingFrom = 0;
        } else if(startingFrom >= socRecordCount)
            startingFrom = startingFrom - MAX_RECORDS_PER_PAGE;
        else if(startingFrom < socRecordCount)
        {
            startingFrom = startingFrom - MAX_RECORDS_PER_PAGE;
        }
        
        return ApexPages.currentPage();
    }
    
	public PageReference next()
    {
        if((socRecordCount - startingFrom) > MAX_RECORDS_PER_PAGE)
            startingFrom = startingFrom + MAX_RECORDS_PER_PAGE;
        return ApexPages.currentPage();
    }  
    
    
}

In this table, I am displaying Society object in a table, where when I click on Location field I get directed to new page(maps.google.com) showing location on the map.
Instead of that, I want location to be displayed on the same page on mouseover.
Can you please help me out by providing the code?
<apex:page controller="Page2_Controller">
    <apex:pageBlock >
    	<apex:pageBlockSection >
        	<apex:pageBlockTable value="{!Societies}" var="s">
                
                <apex:column value="{!s.name}"/>
                <apex:column value="{!s.Secretary__c}"/>
                <apex:column value="{!s.No_of_Members__c}"/>
                <apex:column >
                    <apex:facet name="header">Location</apex:facet>
                    <apex:outputLink value="https://maps.google.com" target="new">
                    <apex:outputText value="{!s.Location__c}"/>
                    	<apex:param name="q" value="{!s.Location__c}"/>
                    </apex:outputLink>
        		</apex:column>
    		</apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
    
    <apex:form >
        <apex:inputHidden value="{!startingFrom}"/>
        <apex:panelGrid columns="2" cellpadding="2px">
            <apex:commandLink action="{!previous}" value="Previous"/>
            <apex:commandLink action="{!next}" value="Next"/>
        </apex:panelGrid>
    </apex:form>
    
</apex:page>
 
public class Page2_Controller {
    private final integer MAX_RECORDS_PER_PAGE = 5;
    public integer startingFrom {get; set;}
    private integer socRecordCount; 
	//View Society
    public Page2_Controller(){
        if(startingFrom == NUll)
            startingFrom=0;
        socRecordCount = [select count() from Society__c];
    }
    public List<Society__c> getSocieties(){
        List<Society__c> results=[select name,Secretary__c,No_Of_Members__c,location__c 
                                  from Society__c limit :MAX_RECORDS_PER_PAGE
               offset : startingFrom];
        return results;  
    }
    
    public PageReference previous()
    {
     	if(startingFrom <= 0)
        {   
            startingFrom = 0;
        } else if(startingFrom >= socRecordCount)
            startingFrom = startingFrom - MAX_RECORDS_PER_PAGE;
        else if(startingFrom < socRecordCount)
        {
            startingFrom = startingFrom - MAX_RECORDS_PER_PAGE;
        }
        
        return ApexPages.currentPage();
    }
    
	public PageReference next()
    {
        if((socRecordCount - startingFrom) > MAX_RECORDS_PER_PAGE)
            startingFrom = startingFrom + MAX_RECORDS_PER_PAGE;
        return ApexPages.currentPage();
    }  
    
    
}

In this table, I am displaying Society object in a table, where when I click on Location field I get directed to new page(maps.google.com) showing location on the map.
Instead of that, I want location to be displayed on the same page on mouseover.
Can you please help me out by providing the code?
<apex:page controller="Page3_Controller">
    <script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++){
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
    <apex:form >
        <apex:pageBlock >
        	<apex:pageBlockSection >
                	Society:<apex:selectList value="{!selectedSociety}" size="1">
                        <apex:selectOptions value="{!records}"/>
                    </apex:selectList>
                    
                    Year:<apex:selectList value="{!selectedYear}" size="1">
                        <apex:selectOptions value="{!years}"/>
                    </apex:selectList>
                    
                    Month:<apex:selectList value="{!selectedMonth}" size="1">
                        <apex:selectOptions value="{!months}"/>
                    </apex:selectList>
                <apex:commandButton action="{!showRecords}" value="View Defaulters" rerender="pbt"/>
                <apex:commandButton action="{!addDues}" value="Add Dues" rerender="pbt1"/>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection columns="2" title="Select defaulters to send email to">
            	<apex:pageBlockTable value="{!wrapDuesList}" var="d" id="pbt" >
                    <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
                        <apex:inputCheckbox value="{!d.checked}" id="inputId"/>
                    </apex:column>
                  <apex:column value="{!d.due.Member_Name__c}" />
                  <apex:column value="{!d.due.Dues_Remaining__c}"/>
            </apex:pageBlockTable>
                
                <apex:pageBlockTable id="id1" value="{!checkedDues}" var="d">
            	<apex:column value="{!d.Member_Name__c}" />
                  <apex:column value="{!d.Dues_Remaining__c}"/>
            </apex:pageBlockTable>
            
            <apex:commandButton value="Show selected" action="{!showRecords}" rerender="id1"/>
            <apex:commandButton value="Send Reminder Email" action="{!sendReminderEmail}"/>
            
            
            </apex:pageBlockSection>
            
            <apex:pageBlockSection title="Add Dues">
            	<apex:pageBlockTable value="{!defaulters1}" var="d" id="pbt1">
            	<apex:column value="{!d.Member_Name__c}"/>
                <apex:column value="{!d.Total_dues__c}"/>
                <apex:column value="{!d.Dues_Remaining__c}"/>
                <apex:column headerValue="Dues Paid">                            
                	<apex:inputText value="{!d.Dues_Paid__c}" />                    
          	  	</apex:column>
            	</apex:pageBlockTable>
                <br/>
            	<apex:commandButton value="Add" action="{!add}"/>
            </apex:pageBlockSection>
            
            
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
public class Page3_Controller {
	public string selectedSociety{get;set;}
    public string selectedYear{get;set;}
    public string selectedMonth{get;set;}
    
    public List<wrapDues> wrapDuesList{get;set;}
    public List<Due__c> checkedDues{get;set;}
    
   	public list<selectOption> records{get;set;}
    public list<selectOption> years{get;set;}
    public list<selectOption> months{get;set;}
    
    public list<String> yearsToAdd=new List<String>{'2015','2016','2017','2018','2019','2020','2021'};
    
    public list<String> monthsToAdd=new List<String>{'Jan','Feb','March','April','May','June','July','Aug','Sept','Oct','Nov','Dec'};
        
   	public list<Due__c> defaulters{get;set;}
    public list<Due__c> defaulters1{get;set;}
    public list<Society__c> societies;
   
   
   	public Page3_Controller(){
   
       defaulters=new List<Due__c>();
       
       records=new List<selectOption>();
       years=new List<selectOption>();
       months=new List<selectOption>();
       
       societies=[select id, name from Society__c];
        for(Society__c a:societies){
            records.add(new selectoption(a.id,a.name));
        }
        
        for(String y:yearsToAdd){
            years.add(new selectoption(y,y));
        }
        
        for(String m:monthsToAdd){
            months.add(new selectoption(m,m));
        }
        

   	}
    
    public class wrapDues{
        public Due__c due{get;set;}
        public Boolean checked{get;set;}
        public wrapDues(Due__c d){
            due=d;
            checked=false;
        }
    }
    
   public pageReference showRecords(){
       defaulters=[select id, member_name__c, dues_remaining__c,Member_Name__r.Name, Member_Name__r.Email__c, Month__c from Due__c where 
                   society_name__c=:selectedSociety and year__c=:selectedYear and month__c=:selectedMonth and dues_remaining__c>0];
       if(wrapDuesList==null){
           wrapDuesList = new List<wrapDues>();
            for(Due__c a: defaulters) {
                wrapDuesList.add(new wrapDues(a));
            }
        }
       checkedDues=new List<Due__c>();
       for(wrapDues wrapDuesObj:wrapDuesList){
           if(wrapDuesObj.checked == true) {
                checkedDues.add(wrapDuesObj.due);
            }
       }
   		return null;
   }
    
    public PageReference sendReminderEmail(){
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
        for(Due__c d:checkedDues){
            if(d.Member_Name__r.Email__c!=null){
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                List<String> sendTo = new List<String>();
      			sendTo.add(d.Member_Name__r.Email__c);
      			mail.setToAddresses(sendTo);
                
                mail.setReplyTo('saie_shendage@persistent.com');
      			mail.setSenderDisplayName('Secretary of the Society');
    			mail.setSubject('Remaining Dues Not Paid');
              String body = 'Dear ' + d.Member_Name__r.Name + ', ';
              body += 'Your remaining dues are '+d.Dues_Remaining__c+' for the month of '+d.Month__c;
              body += ' Please pay the dues Asap, otherwise penalty would be added.';
              mail.setHtmlBody(body);
            
              // Step 5. Add your email to the master list
              mails.add(mail);
            }
        }
        Messaging.sendEmail(mails);
        return null;
    }
    
    public PageReference addDues(){
        defaulters1=[select id, member_name__c,Total_Dues__c, dues_remaining__c,Dues_Paid__c from Due__c where 
                   society_name__c=:selectedSociety and year__c=:selectedYear and month__c=:selectedMonth and dues_remaining__c>0];
      	return null;
    }
    
    public void add(){
        update defaulters1;
    }
    
}
I want test class for apex class Page3_Controller. Please help.
public class Page1_Controller {
    //Add Society
    public Society__c soc{get; set;}
    
    //Add Members
    public List<wrapMember> wrapMemberList {get; set;}
    public List<Member__c> selectedMembers{get;set;}
    public Id socId;
    
    //Add Secretary
    public String selectedSecretary{get;set;}
    public List<selectOption> societyMembers{get;set;}
    
    public Page1_Controller(){
        //Add Society
        soc=new Society__c();
        
        //Add Members
        if(wrapMemberList == null) {
            wrapMemberList = new List<wrapMember>();
            for(Member__c a: [select Id,Name from Member__c]) {
                wrapMemberList.add(new wrapMember(a));
            }
        }
        
        //Add Secretary
        //selectedSecretary='';
        societyMembers=new List<selectOption>();
        societyMembers.add(new selectoption('--Select Secretary--','--Select Secretary--'));
        for(Member__c m:[select id,name from member__c]){
            societyMembers.add(new SelectOption(m.id,m.Name));
        }
        
    }
    
    //Add Society
	public PageReference save()  
    {
        try{
            upsert soc; 
            socId=soc.Id;
        }catch(DmlException ex)
        {
   			ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.FATAL, ex.getMessage()));
			return ApexPages.currentPage();
        }
        
     	return ApexPages.currentPage();
    }   
    
    //Add Members
    public void processSelected() {
    selectedMembers = new List<Member__c>();
 
        for(wrapMember wrapMemberObj : wrapMemberList) {
            if(wrapMemberObj.selected == true) {
                selectedMembers.add(wrapMemberObj.mem);
            }
        }
        
    }
 
    
    public class wrapMember {
        public Member__c mem {get; set;}
        public Boolean selected {get; set;}
 
        public wrapMember(Member__c a) {
            mem = a;
            selected = false;
        }
    }
    
    public void addMembers(){
        for(Member__c c:selectedMembers){
            c.Society_Name__c=socId;
        }
        update selectedMembers;
    }
    
    public PageReference addSecretary(){
        soc.Secretary__c=selectedSecretary;
        update soc;
        return ApexPages.currentPage();
    }
    
}
 
@istest
public class TestPage1 {
    @istest public static void testSaveSociety(){
        Society__c testSoc=new Society__c();
        testSoc.Name='Some Name';
        testSoc.Reg_Code__c='12345';
        testSoc.Location__c='Some Location';
        testSoc.Formation_Year__c='2012';
        
        Test.setCurrentPage(Page.Page1);
        Page1_Controller controller=new Page1_Controller();
        controller.soc=testSoc;
        PageReference actual=controller.save();
        PageReference expected=Page.Page1;
        system.assertEquals(expected.getUrl(), actual.getUrl());
    }
}
I need to write test class for above custom controller. I have written just one test method, but not able to figure out how to write other tests. Can someone give me code for test class? Please help.
I am displaying contacts in the table format and selecting required contacts using checkbox. I want a button below that table in order to send email to selected contacts.
Please help and provide the code with VF page and custom apex controller. Thank you in advance
I am displaying contacts in the table format on vf page using custom controller. I have created one custom field Location__c on Contact object. When I display this field in the table, I want to display it as a link and on mouse-over I want to see it on google maps below the table.

Please help and provide the code using visualforce page and apex controller. Thank you in advance.
I want to display account names in the form of dropdown list and when I change the account name from the dropdown, I should be able to see data about contacts(associated with the respective account) in the tabular format using cutom controller.
Please help. Thank you in advance.
User-added image
Note : I am referring Account object as a 'Society' and Contact object as its respective 'Members'. Secretory_Name__c is my custom field on Account object, secretory is nothing but one the contacts associated with the account.

In the 'Add Secretory' section of this page, I want to display dropdown list which shows me contact names associated with the respective account. Then I want to use that selected contact name to assign it to the secretory field.

Please someone help me with VF page and its custom controller. Thank you in advance.
<aura:component controller="AccountRelatedContacts"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="PageHeading" type="String" default="Account and Related Contacts" />
    <!--aura:attribute name="accData" type="List"/>
    <aura:attribute name="conData" type="List"/-->
    <aura:attribute name="show" type="boolean" default="false"/>
    <aura:attribute name="AccountContactWrapper" type="AccConWrapper"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doinit}" />
    
    <div class=" slds-page-header slds-text-heading--large slds-align--absolute-center">       
        {!v.PageHeading}              
    </div>
    <div class="slds-section slds-is-open">
        <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
            <thead>
                <tr class="slds-text-heading--label">
                    <th scope="col"><div class="slds-truncate" title="Account Name">Account Name</div></th>
                    <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>
                </tr>
            </thead>
            <tbody>
                <aura:iteration items="{!v.AccountContactWrapper.accountInfoList}" var="row" indexVar="index">
                    <tr>
                        <th scope="row">
                            <div class="slds-truncate" >
                                <lightning:input name="accName" disabled="true" value="{!row.accName}"/>
                                <!--a onclick="{!c.showCon}" value="{!row}" data-index="{!index}"-->
                            </div>
                        </th>
                        <td><div class="slds-truncate" title="{!row.Phone}">
                            	<lightning:input name="accPhone" disabled="true" value="{!row.accPhone}"/>
                            </div>
                        </td>
                        <td><lightning:button 
                             	label="View Contacts" value="{!index}" onclick="{!c.showCon}" variant="brand"/>
                        </td>
                        <aura:renderIf isTrue="{!v.show}">
                        	<div class="slds-section slds-is-open">
                            <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
                                <thead>
                                    <tr class="slds-text-heading--label">
                                        <th scope="col"><div class="slds-truncate" title="Contact Name">Contact Name</div></th>
                                        <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <aura:iteration items="{!row.relatedContactInfoList}" var="row2">
                                        <tr>
                                            <th scope="row">
                                                <div class="slds-truncate" title="{!row2.Name}">
                                                    <lightning:input name="conName" disabled="true" value="{!row2.conName}"/>
                                                </div>
                                            </th>
                                            <td>
                                                <div class="slds-truncate" title="{!row2.Phone}">
                                                    <lightning:input name="conPhone" disabled="true" value="{!row2.conPhone}"/>
                                                </div>
                                            </td>
                                        </tr>
                                    </aura:iteration>
                                </tbody>
                            </table>
                        </div>
                    	</aura:renderIf>
                    </tr>
                </aura:iteration>
            </tbody>
        </table>
    </div>
    <br/>
    
</aura:component>
 
public class AccConWrapper {
	@AuraEnabled public list<AccountInfo> accountInfoList;
    
    public class AccountInfo{
        @AuraEnabled public String accName;
        @AuraEnabled public String accPhone;
        @AuraEnabled public list<RelatedContactInfo> relatedContactInfoList;
        @AuraEnabled public Boolean showContacts;
        public AccountInfo(){
            showContacts=false;
        }
    }
    
    public class RelatedContactInfo{
        @AuraEnabled public String conName;
        @AuraEnabled public String conPhone;
    }
}
 
public class AccountRelatedContacts {
    @AuraEnabled
    public static AccConWrapper getAccConWrapperList() {
        AccConWrapper ac = new AccConWrapper();
        ac.accountInfoList = new List<AccConWrapper.AccountInfo>();
        for(Account a: [SELECT Id, Name, Phone, (select name,phone from contacts) FROM Account where Id in (Select AccountId from Contact) LIMIT 5])
        {
            AccConWrapper.AccountInfo az = new AccConWrapper.AccountInfo();
            az.accName= a.Name;
            az.accPhone= a.Phone;
            az.relatedContactInfoList = new List<AccConWrapper.RelatedContactInfo> () ;  
            for(Contact c: a.Contacts)
            {
                AccConWrapper.RelatedContactInfo cz = new AccConWrapper.RelatedContactInfo();
                cz.conName= c.Name;
                cz.conPhone= c.Phone;
                az.relatedContactInfoList.add(cz);
            }
            ac.accountInfoList.add(az);
        }
        return ac;        
    }
    
}
 
//aura component js controller
({
    doinit : function(component, event, helper) {
        var action = component.get('c.getAccConWrapperList');
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                var allValues = response.getReturnValue();
                console.log("allValues--->>> " + allValues);
                component.set('v.AccountContactWrapper', allValues);
            }
            else if(state === "ERROR") {
                var errors = response.getError();
                if(errors){
                    if(errors[0] && errors[0].message){
                        console.log("Error Message: " + errors[0].message);
                    }
                }
                else{
                    console.log("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
    },
    
    showCon : function(component, event, helper){
        var AccountContactWrapper = JSON.stringify(component.get("v.AccountContactWrapper"));
        var idx = event.getSource().get("v.value");
        console.log('index',idx)
        
        component.set("v.show",true);
        
    }
}

User-added imageThis is how my UI looks like. When I click on View Contacts button contacts related to all the accounts get fetched. But I dont want that. I want contacts related to only that account on which button was clicked. Please help me.
I am inserting one custom object on visualforce page form using custom controller. On clicking save button the record gets inserted. If the record is inserted successfully, I want to display one alert message 'Record saved successfully'/
Please help out. 
<apex:page controller="Page2_Controller">
    <apex:pageBlock >
    	<apex:pageBlockSection >
        	<apex:pageBlockTable value="{!Societies}" var="s">
                
                <apex:column value="{!s.name}"/>
                <apex:column value="{!s.Secretary__c}"/>
                <apex:column value="{!s.No_of_Members__c}"/>
                <apex:column >
                    <apex:facet name="header">Location</apex:facet>
                    <apex:outputLink value="https://maps.google.com" target="new">
                    <apex:outputText value="{!s.Location__c}"/>
                    	<apex:param name="q" value="{!s.Location__c}"/>
                    </apex:outputLink>
        		</apex:column>
    		</apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
    
    <apex:form >
        <apex:inputHidden value="{!startingFrom}"/>
        <apex:panelGrid columns="2" cellpadding="2px">
            <apex:commandLink action="{!previous}" value="Previous"/>
            <apex:commandLink action="{!next}" value="Next"/>
        </apex:panelGrid>
    </apex:form>
    
</apex:page>
 
public class Page2_Controller {
    private final integer MAX_RECORDS_PER_PAGE = 5;
    public integer startingFrom {get; set;}
    private integer socRecordCount; 
	//View Society
    public Page2_Controller(){
        if(startingFrom == NUll)
            startingFrom=0;
        socRecordCount = [select count() from Society__c];
    }
    public List<Society__c> getSocieties(){
        List<Society__c> results=[select name,Secretary__c,No_Of_Members__c,location__c 
                                  from Society__c limit :MAX_RECORDS_PER_PAGE
               offset : startingFrom];
        return results;  
    }
    
    public PageReference previous()
    {
     	if(startingFrom <= 0)
        {   
            startingFrom = 0;
        } else if(startingFrom >= socRecordCount)
            startingFrom = startingFrom - MAX_RECORDS_PER_PAGE;
        else if(startingFrom < socRecordCount)
        {
            startingFrom = startingFrom - MAX_RECORDS_PER_PAGE;
        }
        
        return ApexPages.currentPage();
    }
    
	public PageReference next()
    {
        if((socRecordCount - startingFrom) > MAX_RECORDS_PER_PAGE)
            startingFrom = startingFrom + MAX_RECORDS_PER_PAGE;
        return ApexPages.currentPage();
    }  
    
    
}

In this table, I am displaying Society object in a table, where when I click on Location field I get directed to new page(maps.google.com) showing location on the map.
Instead of that, I want location to be displayed on the same page on mouseover.
Can you please help me out by providing the code?
<apex:page controller="Page3_Controller">
    <script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++){
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
    <apex:form >
        <apex:pageBlock >
        	<apex:pageBlockSection >
                	Society:<apex:selectList value="{!selectedSociety}" size="1">
                        <apex:selectOptions value="{!records}"/>
                    </apex:selectList>
                    
                    Year:<apex:selectList value="{!selectedYear}" size="1">
                        <apex:selectOptions value="{!years}"/>
                    </apex:selectList>
                    
                    Month:<apex:selectList value="{!selectedMonth}" size="1">
                        <apex:selectOptions value="{!months}"/>
                    </apex:selectList>
                <apex:commandButton action="{!showRecords}" value="View Defaulters" rerender="pbt"/>
                <apex:commandButton action="{!addDues}" value="Add Dues" rerender="pbt1"/>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection columns="2" title="Select defaulters to send email to">
            	<apex:pageBlockTable value="{!wrapDuesList}" var="d" id="pbt" >
                    <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
                        <apex:inputCheckbox value="{!d.checked}" id="inputId"/>
                    </apex:column>
                  <apex:column value="{!d.due.Member_Name__c}" />
                  <apex:column value="{!d.due.Dues_Remaining__c}"/>
            </apex:pageBlockTable>
                
                <apex:pageBlockTable id="id1" value="{!checkedDues}" var="d">
            	<apex:column value="{!d.Member_Name__c}" />
                  <apex:column value="{!d.Dues_Remaining__c}"/>
            </apex:pageBlockTable>
            
            <apex:commandButton value="Show selected" action="{!showRecords}" rerender="id1"/>
            <apex:commandButton value="Send Reminder Email" action="{!sendReminderEmail}"/>
            
            
            </apex:pageBlockSection>
            
            <apex:pageBlockSection title="Add Dues">
            	<apex:pageBlockTable value="{!defaulters1}" var="d" id="pbt1">
            	<apex:column value="{!d.Member_Name__c}"/>
                <apex:column value="{!d.Total_dues__c}"/>
                <apex:column value="{!d.Dues_Remaining__c}"/>
                <apex:column headerValue="Dues Paid">                            
                	<apex:inputText value="{!d.Dues_Paid__c}" />                    
          	  	</apex:column>
            	</apex:pageBlockTable>
                <br/>
            	<apex:commandButton value="Add" action="{!add}"/>
            </apex:pageBlockSection>
            
            
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
public class Page3_Controller {
	public string selectedSociety{get;set;}
    public string selectedYear{get;set;}
    public string selectedMonth{get;set;}
    
    public List<wrapDues> wrapDuesList{get;set;}
    public List<Due__c> checkedDues{get;set;}
    
   	public list<selectOption> records{get;set;}
    public list<selectOption> years{get;set;}
    public list<selectOption> months{get;set;}
    
    public list<String> yearsToAdd=new List<String>{'2015','2016','2017','2018','2019','2020','2021'};
    
    public list<String> monthsToAdd=new List<String>{'Jan','Feb','March','April','May','June','July','Aug','Sept','Oct','Nov','Dec'};
        
   	public list<Due__c> defaulters{get;set;}
    public list<Due__c> defaulters1{get;set;}
    public list<Society__c> societies;
   
   
   	public Page3_Controller(){
   
       defaulters=new List<Due__c>();
       
       records=new List<selectOption>();
       years=new List<selectOption>();
       months=new List<selectOption>();
       
       societies=[select id, name from Society__c];
        for(Society__c a:societies){
            records.add(new selectoption(a.id,a.name));
        }
        
        for(String y:yearsToAdd){
            years.add(new selectoption(y,y));
        }
        
        for(String m:monthsToAdd){
            months.add(new selectoption(m,m));
        }
        

   	}
    
    public class wrapDues{
        public Due__c due{get;set;}
        public Boolean checked{get;set;}
        public wrapDues(Due__c d){
            due=d;
            checked=false;
        }
    }
    
   public pageReference showRecords(){
       defaulters=[select id, member_name__c, dues_remaining__c,Member_Name__r.Name, Member_Name__r.Email__c, Month__c from Due__c where 
                   society_name__c=:selectedSociety and year__c=:selectedYear and month__c=:selectedMonth and dues_remaining__c>0];
       if(wrapDuesList==null){
           wrapDuesList = new List<wrapDues>();
            for(Due__c a: defaulters) {
                wrapDuesList.add(new wrapDues(a));
            }
        }
       checkedDues=new List<Due__c>();
       for(wrapDues wrapDuesObj:wrapDuesList){
           if(wrapDuesObj.checked == true) {
                checkedDues.add(wrapDuesObj.due);
            }
       }
   		return null;
   }
    
    public PageReference sendReminderEmail(){
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
        for(Due__c d:checkedDues){
            if(d.Member_Name__r.Email__c!=null){
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                List<String> sendTo = new List<String>();
      			sendTo.add(d.Member_Name__r.Email__c);
      			mail.setToAddresses(sendTo);
                
                mail.setReplyTo('saie_shendage@persistent.com');
      			mail.setSenderDisplayName('Secretary of the Society');
    			mail.setSubject('Remaining Dues Not Paid');
              String body = 'Dear ' + d.Member_Name__r.Name + ', ';
              body += 'Your remaining dues are '+d.Dues_Remaining__c+' for the month of '+d.Month__c;
              body += ' Please pay the dues Asap, otherwise penalty would be added.';
              mail.setHtmlBody(body);
            
              // Step 5. Add your email to the master list
              mails.add(mail);
            }
        }
        Messaging.sendEmail(mails);
        return null;
    }
    
    public PageReference addDues(){
        defaulters1=[select id, member_name__c,Total_Dues__c, dues_remaining__c,Dues_Paid__c from Due__c where 
                   society_name__c=:selectedSociety and year__c=:selectedYear and month__c=:selectedMonth and dues_remaining__c>0];
      	return null;
    }
    
    public void add(){
        update defaulters1;
    }
    
}
I want test class for apex class Page3_Controller. Please help.
public class Page1_Controller {
    //Add Society
    public Society__c soc{get; set;}
    
    //Add Members
    public List<wrapMember> wrapMemberList {get; set;}
    public List<Member__c> selectedMembers{get;set;}
    public Id socId;
    
    //Add Secretary
    public String selectedSecretary{get;set;}
    public List<selectOption> societyMembers{get;set;}
    
    public Page1_Controller(){
        //Add Society
        soc=new Society__c();
        
        //Add Members
        if(wrapMemberList == null) {
            wrapMemberList = new List<wrapMember>();
            for(Member__c a: [select Id,Name from Member__c]) {
                wrapMemberList.add(new wrapMember(a));
            }
        }
        
        //Add Secretary
        //selectedSecretary='';
        societyMembers=new List<selectOption>();
        societyMembers.add(new selectoption('--Select Secretary--','--Select Secretary--'));
        for(Member__c m:[select id,name from member__c]){
            societyMembers.add(new SelectOption(m.id,m.Name));
        }
        
    }
    
    //Add Society
	public PageReference save()  
    {
        try{
            upsert soc; 
            socId=soc.Id;
        }catch(DmlException ex)
        {
   			ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.FATAL, ex.getMessage()));
			return ApexPages.currentPage();
        }
        
     	return ApexPages.currentPage();
    }   
    
    //Add Members
    public void processSelected() {
    selectedMembers = new List<Member__c>();
 
        for(wrapMember wrapMemberObj : wrapMemberList) {
            if(wrapMemberObj.selected == true) {
                selectedMembers.add(wrapMemberObj.mem);
            }
        }
        
    }
 
    
    public class wrapMember {
        public Member__c mem {get; set;}
        public Boolean selected {get; set;}
 
        public wrapMember(Member__c a) {
            mem = a;
            selected = false;
        }
    }
    
    public void addMembers(){
        for(Member__c c:selectedMembers){
            c.Society_Name__c=socId;
        }
        update selectedMembers;
    }
    
    public PageReference addSecretary(){
        soc.Secretary__c=selectedSecretary;
        update soc;
        return ApexPages.currentPage();
    }
    
}
 
@istest
public class TestPage1 {
    @istest public static void testSaveSociety(){
        Society__c testSoc=new Society__c();
        testSoc.Name='Some Name';
        testSoc.Reg_Code__c='12345';
        testSoc.Location__c='Some Location';
        testSoc.Formation_Year__c='2012';
        
        Test.setCurrentPage(Page.Page1);
        Page1_Controller controller=new Page1_Controller();
        controller.soc=testSoc;
        PageReference actual=controller.save();
        PageReference expected=Page.Page1;
        system.assertEquals(expected.getUrl(), actual.getUrl());
    }
}
I need to write test class for above custom controller. I have written just one test method, but not able to figure out how to write other tests. Can someone give me code for test class? Please help.
I am displaying contacts in the table format and selecting required contacts using checkbox. I want a button below that table in order to send email to selected contacts.
Please help and provide the code with VF page and custom apex controller. Thank you in advance
I want to display account names in the form of dropdown list and when I change the account name from the dropdown, I should be able to see data about contacts(associated with the respective account) in the tabular format using cutom controller.
Please help. Thank you in advance.

Hi Everyone,

 

I need to create a dropdown field on Visualforce page which should display the list of Users based on a query.

Then I need to use the chosen  value in my Controller.

 

How to achieve this??

Plz help its urgent 

 

Thanks,

Ankit