• siva krishna 61
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 3
    Replies

















I have written test class for below class but code percentage i am getting 29 only would you please give solution for it 



Test Class
-----------------

@isTest
public class CustSearchTest {
    testmethod static void testme()
 {
        
        List<Contact> conlist=new List<Contact>();
  Contact testcon = new Contact();
  testcon.lastname='testcon1' ;
        testcon.FirstName= 'Anil'; 
      testcon.Email = 'ram@gmail.com';
        testcon.MobilePhone= '9898561236';
        conlist.add(testcon);
        
        Contact testcon1 = new Contact();
  testcon1.lastname='testcon12' ;
        testcon1.FirstName= 'Anil2'; 
      testcon1.Email = 'ram2@gmail.com';
        testcon1.MobilePhone= '9898561136';
  conlist.add(testcon1);
        
        insert conlist;
        
        test.startTest();
  
   ApexPages.StandardController sc = new ApexPages.StandardController(testcon);
            CustSearch cs= new CustSearch(sc);
   
   
  test.stopTest();
    }
    
}

apex class:
-----------------

public class CustSearch {
    
    public contact con{set;get;}
    public list<contact> cont {set;get;}
    
    public CustSearch(Apexpages.StandardController controller){
        cont = new list<contact>();
    // list<string> str = new list<string>{'FirstName','LastName','Email','AccountId','Account.name', 'Customer_Account_Number__c'};  
   
        list<string> str = new list<string>{'FirstName','LastName','Email'};  
            if (!Test.isRunningTest()){
        controller.addFields(str);
        con = (contact)controller.getRecord();  
   
            }
   
    }


    Class
---------------------------
    public void search(){
     transient String lastname= '%'+con.LastName+'%';
     transient string firstname = '%'+con.FirstName+'%';
     transient string email1 = '%'+con.Email+'%';
    transient id accName = con.Accountid;
   //transient String acctno = '%'+con.Customer_Account_Number__c+'%';
   
   transient String mStreet = '%'+con.MailingStreet+'%';
  
        System.debug(accName);
        System.debug(con.AccountId);
        cont = [select id,firstname,lastname,email,phone,contact.account.name, MailingStreet, MailingCity, MailingPostalCode, MailingState  from contact where firstname like : firstname OR lastname like : lastname OR email like : email1 OR MailingStreet like : mStreet  ];
     
            
        if(cont.size()==0)
       ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, ' No Matching Contact Records Found '));

       System.debug(cont.size());
        
    }
  

}
Visualforce page
----------------------

<apex:page standardController="contact" extensions="CustSearch" sidebar="false">
    <apex:form >
        <apex:pageMessages >
        
        </apex:pageMessages>
        
       
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="search" action="{!Search}" />
                          
            </apex:pageBlockButtons>
             
          <apex:pageBlockSection columns="1">
                <apex:inputField value="{!con.FirstName}" />                
                <apex:inputField value="{!con.Email}" />             
                <apex:inputField value="{!con.Customer_Account_Number__c}"/>
                <apex:inputField value="{!con.MailingStreet}"/> 
         
          </apex:pageBlockSection>
             
                           
            <apex:pageBlockTable value="{!cont}"  var="c" rendered="{! cont.size!=0}">  
                 <apex:column headerValue="LastName"><apex:commandLink value="{!c.lastname}" action="{! URLFOR($Action.contact.view,c.id)}"/></apex:column>
                <apex:column value="{!c.firstname}" />
                <apex:column value="{!c.Customer_Account_Number__c}"/>
                <apex:column value="{!c.Enrollment_Status__c}" />                                              
                 <apex:column value="{!c.account.name}" />
                <apex:column value="{!c.email}" />
                <apex:column value="{!c.phone}" /> 
                <apex:column value="{!c.MailingStreet}" />  
                <apex:column value="{!c.MailingCity}" /> 
                  <apex:column value="{!c.MailingPostalCode}" />
                    <apex:column value="{!c.MailingState}" />                      
                </apex:pageBlockTable> 
              
        </apex:pageBlock>
    </apex:form>
</apex:page>


Apex class
-------------



public class CustSearch {
    
    public contact con{set;get;}
    public list<contact> cont {set;get;}
    
    public CustSearch(Apexpages.StandardController controller){
        cont = new list<contact>();
    // list<string> str = new list<string>{'FirstName','LastName','Email','AccountId','Account.name', 'Customer_Account_Number__c'};  
    
    list<string> str = new list<string>{'FirstName','LastName','Email','Customer_Account_Number__c'};  

        controller.addFields(str);
        con = (contact)controller.getRecord();  
    }
    
    public void search(){
     transient String lastname= '%'+con.LastName+'%';
     transient string firstname = '%'+con.FirstName+'%';
     transient string email1 = '%'+con.Email+'%';
   transient id accName = con.Accountid;
   transient String acctno = '%'+con.Customer_Account_Number__c+'%';
   
   transient String mStreet = '%'+con.MailingStreet+'%';
  
        System.debug(accName);
        System.debug(con.AccountId);
        cont = [select id,firstname,lastname,email,phone,contact.account.name, Customer_Account_Number__c, Enrollment_Status__c, MailingStreet, MailingCity, MailingPostalCode, MailingState  from contact where firstname like : firstname OR lastname like : lastname OR email like : email1 OR Customer_Account_Number__c like :acctno OR MailingStreet like : mStreet  ];    
            
        if(cont.size()==0)
       ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, ' No Matching Contact Records Found '));
       System.debug(cont.size());        
    }
}
Apex Class
-------------------
public class Calci {
    
    integer a;
    integer b;
    
    public void cal()
    {
        a=10;
        b=45;
        integer r;
        if(a>b)
        {
            r=a+b;
            system.debug('if a greter than b values should be added'+r);
        }
        else if(a<b)
        {
            r = a-b;
            system.debug('if a is lesser than b values should be subtract'+r);
        }
        else
        {
            system.debug('values are equal');
        }
    }
}


Test Class
--------------
@isTest
public class CalciTest {
    public static testmethod void test(){
       
        Calci c = new Calci();
        c.cal();
    }
}
hi every one
i am create lead record in that i want to add custom button(take any thing) in this custom redirect to vfpage in that page should have 3 section
1 account section, it should have few fields 1 account name(company), 2 Address
2 contact section  it should  have few fields 1 Firstname ,lastname,phone,email
note  account and contact record should have editable option inline (1st  priority) edit button (2nd priority)
3 Inventory  this is custom object     this object should have few fields 1 length(mandatory) 2 width 3 (height) and search button also when i click on search button result should be display few columns like check button, inventoryname,lenght,width,height,price,quantity then after i selected few records i click on addtocort button then those records should be add here display new table or pageblock section inventory name quatity and amount amount should product of price and quantity(formula)
there you can put create quote(button)
Account object and jobs object.
Create report for first job created date for Account this week
We have two objects. It's having look up relationship. I need record count of that object.
Example Account object and contact object. I need count of contacts to each Account.
                        create vf page which display Account name (left side ) && List of contacts of that Account in Right side
Hello Folks,

Opportunity have three buttons like edit, delete, clone. here i want add new button which is redirected to account page how to write code for this requirement

















I have written test class for below class but code percentage i am getting 29 only would you please give solution for it 



Test Class
-----------------

@isTest
public class CustSearchTest {
    testmethod static void testme()
 {
        
        List<Contact> conlist=new List<Contact>();
  Contact testcon = new Contact();
  testcon.lastname='testcon1' ;
        testcon.FirstName= 'Anil'; 
      testcon.Email = 'ram@gmail.com';
        testcon.MobilePhone= '9898561236';
        conlist.add(testcon);
        
        Contact testcon1 = new Contact();
  testcon1.lastname='testcon12' ;
        testcon1.FirstName= 'Anil2'; 
      testcon1.Email = 'ram2@gmail.com';
        testcon1.MobilePhone= '9898561136';
  conlist.add(testcon1);
        
        insert conlist;
        
        test.startTest();
  
   ApexPages.StandardController sc = new ApexPages.StandardController(testcon);
            CustSearch cs= new CustSearch(sc);
   
   
  test.stopTest();
    }
    
}

apex class:
-----------------

public class CustSearch {
    
    public contact con{set;get;}
    public list<contact> cont {set;get;}
    
    public CustSearch(Apexpages.StandardController controller){
        cont = new list<contact>();
    // list<string> str = new list<string>{'FirstName','LastName','Email','AccountId','Account.name', 'Customer_Account_Number__c'};  
   
        list<string> str = new list<string>{'FirstName','LastName','Email'};  
            if (!Test.isRunningTest()){
        controller.addFields(str);
        con = (contact)controller.getRecord();  
   
            }
   
    }


    Class
---------------------------
    public void search(){
     transient String lastname= '%'+con.LastName+'%';
     transient string firstname = '%'+con.FirstName+'%';
     transient string email1 = '%'+con.Email+'%';
    transient id accName = con.Accountid;
   //transient String acctno = '%'+con.Customer_Account_Number__c+'%';
   
   transient String mStreet = '%'+con.MailingStreet+'%';
  
        System.debug(accName);
        System.debug(con.AccountId);
        cont = [select id,firstname,lastname,email,phone,contact.account.name, MailingStreet, MailingCity, MailingPostalCode, MailingState  from contact where firstname like : firstname OR lastname like : lastname OR email like : email1 OR MailingStreet like : mStreet  ];
     
            
        if(cont.size()==0)
       ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, ' No Matching Contact Records Found '));

       System.debug(cont.size());
        
    }
  

}
Hi,

I creating a trigger, that when an Opportunity are closed, I get some of the data of the fields of that opportunity and send these informations to another system.
But I don't know how get theses fields with APEX.

Can someone help me?

Best Regards
Rafael


 
Hello Folks,

Opportunity have three buttons like edit, delete, clone. here i want add new button which is redirected to account page how to write code for this requirement