• Mohmad Sohel
  • NEWBIE
  • 25 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies
Hi, please help on writing test class for below controller:
public class DataTableExampleController {
    public List<Contact> contactList{
        get{
            if(contactList ==Null){
                contactList = [select Account.Name, FirstName, LastName, Phone from Contact limit 10000];
            }
            return contactList;
        }
        set;
            }
        }
     Test class:
@isTest
public class Test_DataTableExampleController {
    static testMethod void testSave(){
           Test.setCurrentPage(Page.DataTablePage);
        Account acc = new Account(Name = 'Test');
        insert acc;
        Contact con = new Contact(LastName = 'Test', AccountId = acc.Id );
        insert con;
        
        DataTableExampleController dt = new DataTableExampleController ();
 //   dt.contactList = 'test';
   //     System.assertEquals(contactList, 'test');
    }
}
Thank You.
Hi All,
Kindly help me on writing test class for below Standard Controller Extension. Currently I am getting 47 % code coverage.

Controller:
public class SpeakerControllerExtension {

    public blob picture { get; set; }
    public String errorMessage { get; set; }

    private final Speaker__c speaker;
    private ApexPages.StandardController stdController;

    public SpeakerControllerExtension(ApexPages.StandardController stdController) {
        this.speaker = (Speaker__c)stdController.getRecord();
        this.stdController = stdController;
    }

    public PageReference save() {
        errorMessage = '';
        try {
            upsert speaker;
            if (picture != null) {
                Attachment attachment = new Attachment();
                attachment.body = picture;
                attachment.name = 'speaker_' + speaker.id + '.jpg';
                attachment.parentid = speaker.id;
                attachment.ContentType = 'application/jpg';
                insert attachment;
                speaker.Picture_Path__c = '/servlet/servlet.FileDownload?file='
                                          + attachment.id;
                update speaker;
            }
            return new ApexPages.StandardController(speaker).view();
        } catch(System.Exception ex) {
            errorMessage = ex.getMessage();
            return null;
        }
    }
}

Test class: 

@isTest
public class Test_SpeaketControllerExtension {
     static  testMethod void testSave(){
         
        
        Speaker__c sp = new Speaker__c(); // Speaker__c is Standard Controller
        insert sp;
       
        ApexPages.StandardController controller = new ApexPages.StandardController(sp);
       
        SpeakerControllerExtension extension = new SpeakerControllerExtension(controller); // controller extension
        extension.save();
        
        PageReference pageRef = Page.SpeakerForm; // SpeakerForm is visualforce page
        
        Test.setCurrentPageReference(pageRef);
    }
}

Thanks in advance
Hi all. I need Vf page & controller to fetch the records of selected users or specified email.

User-added image
Upon clicking Search, if Data is selected, the app will search all data for the User Name OR Email Address and then present the first 10-20 records in a table underneath the Search button with the following columns:
• Object
• Field
• Field Value
• Record ID
• Record Name

I created a VF page:
<apex:page standardController="User_Locator__c" >
<apex:sectionHeader title="User Locator" subtitle="{!User_Locator__c.name}"/>
<apex:form >
<apex:pageBlock mode="edit">

<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Search" action="{!search}"/> 
</apex:pageBlockButtons>

<apex:pageBlockSection title="Information" columns="2">

<apex:inputField value="{!User_Locator__c.User_Name__c}" required="false"/>

<apex:inputField value="{!User_Locator__c.Email_Address__c}" required="false"/>

</apex:pageBlockSection>


<apex:pageBlockSection title="Search in:" columns="2">
<apex:inputField value="{!User_Locator__c.Data__c}" required="false"/>
<apex:inputField value="{!User_Locator__c.Configuration__c}" required="false"/>
</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>

Hi, please help on writing test class for below controller:
public class DataTableExampleController {
    public List<Contact> contactList{
        get{
            if(contactList ==Null){
                contactList = [select Account.Name, FirstName, LastName, Phone from Contact limit 10000];
            }
            return contactList;
        }
        set;
            }
        }
     Test class:
@isTest
public class Test_DataTableExampleController {
    static testMethod void testSave(){
           Test.setCurrentPage(Page.DataTablePage);
        Account acc = new Account(Name = 'Test');
        insert acc;
        Contact con = new Contact(LastName = 'Test', AccountId = acc.Id );
        insert con;
        
        DataTableExampleController dt = new DataTableExampleController ();
 //   dt.contactList = 'test';
   //     System.assertEquals(contactList, 'test');
    }
}
Thank You.
Hi All,
Kindly help me on writing test class for below Standard Controller Extension. Currently I am getting 47 % code coverage.

Controller:
public class SpeakerControllerExtension {

    public blob picture { get; set; }
    public String errorMessage { get; set; }

    private final Speaker__c speaker;
    private ApexPages.StandardController stdController;

    public SpeakerControllerExtension(ApexPages.StandardController stdController) {
        this.speaker = (Speaker__c)stdController.getRecord();
        this.stdController = stdController;
    }

    public PageReference save() {
        errorMessage = '';
        try {
            upsert speaker;
            if (picture != null) {
                Attachment attachment = new Attachment();
                attachment.body = picture;
                attachment.name = 'speaker_' + speaker.id + '.jpg';
                attachment.parentid = speaker.id;
                attachment.ContentType = 'application/jpg';
                insert attachment;
                speaker.Picture_Path__c = '/servlet/servlet.FileDownload?file='
                                          + attachment.id;
                update speaker;
            }
            return new ApexPages.StandardController(speaker).view();
        } catch(System.Exception ex) {
            errorMessage = ex.getMessage();
            return null;
        }
    }
}

Test class: 

@isTest
public class Test_SpeaketControllerExtension {
     static  testMethod void testSave(){
         
        
        Speaker__c sp = new Speaker__c(); // Speaker__c is Standard Controller
        insert sp;
       
        ApexPages.StandardController controller = new ApexPages.StandardController(sp);
       
        SpeakerControllerExtension extension = new SpeakerControllerExtension(controller); // controller extension
        extension.save();
        
        PageReference pageRef = Page.SpeakerForm; // SpeakerForm is visualforce page
        
        Test.setCurrentPageReference(pageRef);
    }
}

Thanks in advance
Hi all. I need Vf page & controller to fetch the records of selected users or specified email.

User-added image
Upon clicking Search, if Data is selected, the app will search all data for the User Name OR Email Address and then present the first 10-20 records in a table underneath the Search button with the following columns:
• Object
• Field
• Field Value
• Record ID
• Record Name

I created a VF page:
<apex:page standardController="User_Locator__c" >
<apex:sectionHeader title="User Locator" subtitle="{!User_Locator__c.name}"/>
<apex:form >
<apex:pageBlock mode="edit">

<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Search" action="{!search}"/> 
</apex:pageBlockButtons>

<apex:pageBlockSection title="Information" columns="2">

<apex:inputField value="{!User_Locator__c.User_Name__c}" required="false"/>

<apex:inputField value="{!User_Locator__c.Email_Address__c}" required="false"/>

</apex:pageBlockSection>


<apex:pageBlockSection title="Search in:" columns="2">
<apex:inputField value="{!User_Locator__c.Data__c}" required="false"/>
<apex:inputField value="{!User_Locator__c.Configuration__c}" required="false"/>
</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>