+ Start a Discussion
Sandra WicketSandra Wicket 

deploy custom controller for visualforce page

Hi guys,
 
i created this custom controller for a visualforce page.  It shows all leads of the user with high priority.  The user is able to filter Leads by the Industry. The new variable industryPickvalue is just to select "all" Leads. It works fine for me in the sandbox, but i am not able to deploy it.  I am not a developer but it would be great to hear some solutions or ideas.

public class LeadPageControllerFilter {
    public string industryPickvalue{get; set;}
    public list<lead> leadList{get; set;}
     
    public void getLeads() {
        
        if (industryPickvalue == 'All'){

        leadList = new list<lead>([SELECT Id, Name, Company, Owner.name , Status, Industry, Lead_ScoreFinal__c from Lead  
        WHERE 
            OwnerId = :UserInfo.getUserId() 
            AND Time_LastModified__c != TODAY 
            AND Status != 'TEST'
            
        ORDER BY 
            Lead_ScoreFinal__c DESC       
        LIMIT 10]);
        
        } else {
        
        leadList = new list<lead>([SELECT Id, Name, Company, Owner.name , Status, Industry, Lead_ScoreFinal__c from Lead 
        WHERE 
              OwnerId = :UserInfo.getUserId() 
              AND Industry = :industryPickvalue 
              AND Time_LastModified__c != TODAY  
              AND Status != '40 - Demo Termin vereinbart'
                  
        ORDER BY 
            Lead_ScoreFinal__c DESC       
        LIMIT 10]);
        }      
    }
}


Testclass : 
@isTest 
public class LeadPageControllerFilterTest
{
    static testMethod void testMethod1() 
    {
        // create a Lead
        Lead lead=new Lead(
        LastName='Doe', 
        FirstName='John', 
        Company = 'Test', 
        Status = 'test' ,
        Country = 'Deutschland', 
        LeadSource = 'Import',
        PostalCode = '83024',
        Phone = '0300340340',
        Industry = 'Sonstige Branche' );
        
        insert lead;   

        Test.StartTest();

            LeadPageControllerFilter obj = new LeadPageControllerFilter();
           
            obj.industryPickvalue ='All';
            obj.getLeads();        
            obj.industryPickvalue ='Sonstige Branche';
            obj.getLeads();
           
        Test.StopTest();        
        
    }
}

The problem is the variable "industryPickvalue". I need the testclass for this controller, but i can't deploy it, because the variable "industryPickvalue" doesen't exist in the production. Maybe i have to deploy the varibale separately ?  Or maybe i can create the filter "all" with the visualforce page ?  Thanks for your help and your time ! 

 
SFDC RJSFDC RJ
Hi,
I like to hear if it is showing any error while deploying the apex class to production ? as i don't think 'industryPickvalue' variable can be a issue .
Thanks 
Sandra WicketSandra Wicket
Hi,
thanks for your respose rj.  

User-added image

I get this error message when i try to deploy the testclass. 
 
Dave HummDave Humm
I think that the best fix is to seperately deploy the picklist to production and make sure that it is visible to the System Administrator profile and then deploy the Controller and Test Class. 

I am not sure with deployment that the object updates occur before the apex code deployment meaning that when the tests run they would not be able to find the picklist and its values. 
SFDC RJSFDC RJ
@sandra

Remove this line 
obj.industryPickvalue ='Sonstige Branche';
and then try to run the test and see coverage and then deploy it to production.
Thanks
Sandra WicketSandra Wicket
@dave 
its not a picklist field. Its more or less just a value of the filter.

@sfdc rj 
unfortunately i dont have enough code coverage. (66%)
Sandra WicketSandra Wicket
Hey experts, 

Unfortunately i am still stuck at this controller. I cancelled the filter to deploy the controller in a lower form. 
 
public class LeadPageController {
    public List<Lead> getLeads() {       
        return [SELECT Id, Company,Lead_ScoreFinal__c from Lead WHERE OwnerId = :UserInfo.getUserId() 
        AND Time_LastModified__c != Today
        ORDER BY Lead_ScoreFinal__c DESC         
        ];
    }
}

Now i have problems with the testclass. I tried this one : 


@isTest 
public class LeadPageControllerTest 
{
    static testMethod void testMethod1() 
    {
        // create a Lead
        Lead lead=new Lead(
        LastName='Doe', 
        FirstName='John', 
        Company = 'Test', 
        Status = '10 - qualifizierte Lead' ,
        Country = 'Deutschland', 
        LeadSource = 'Import',
        PostalCode = '83024',
        Phone = '0300340340',
        Time_LastModified__c = System.Today() - 10,
        Time_LastDownrate__c = System.Today() - 10, 
        Anzahl_Mitarbeiter__c ='Keine Angaben',
        Time_Task__c = System.Today(), 
        Lead_Score__c = 88.939,
        Industry = 'Sonstige Branche' );
        
        insert lead;
           
        
    }
}

Please help experts :(