• Avesh Lakha
  • NEWBIE
  • 25 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies
I have one VF page which opens when someone clicks on View document. I want this document to be open based on the user selection. So if the user selects PDF and save the record and then click on the button then doc should be open in PDF and if user select word then doc should be opened in word. I have reviewed many articles but unable to get how to achieve this.
Can anyone please help me?
I am facing this error when I am refreshing my VF page. I know this is because SOQL query is written inside the for loops but I am struggling with removing the SOQL outside the for loop. 

Here is the method which is called when constructor runs when the page loads

Can anyone please help me in this case.

Thanks
Avesh Lakha​
public List<selectedProductClass> getSelectedProductClassString(){
       
       
        List<List<String>> lstProductsInCategory = new List<List<String>>();
        lstAllAccountProductClassString = new List<selectedProductClass>();
        
        Map <List<String>,String> mapProductCategory = new Map <List<String>,String>();
        Map <List<String>,String> mapShow = new Map <List<String>,String>();
        
        
       for(Account_Product__c accProducts : [SELECT Id,Account__c,Product_Category__c,Show__c,Products__c from Account_Product__c where Account__c =: this.iAccountId]){
                   
           for(String pd : accProducts.Products__c.split(';')) {
           selectedProductClass objClass = new selectedProductClass ();
                objClass.selectedShow = accProducts.Show__c ;
                objClass.selectedCategory = accProducts.Product_Category__c;
                objClass.selectProduct = pd;
                                                 
           Product__c[] prod  = [SELECT Id from Product__c where  Name =:pd AND Product_Category__c =: accProducts.Product_Category__c AND Show__c =:accProducts.Show__c limit 1];
              if (prod.size() > 0)
                objClass.ProductId = prod[0].Id;
                lstAllAccountProductClassString.add(objClass); 
            }
               lstProductsInCategory.add(accProducts.Products__c.split(';'));
               mapProductCategory.put(accProducts.Products__c.split(';'),accProducts.Product_Category__c);
               mapShow.put(accProducts.Products__c.split(';'),accProducts.Show__c);
        }
        

        return lstAllAccountProductClassString;
    }

 

Hi,

I have created a Trigger and used Helper class in the trigger and created the Test Class which is covering 96% of helper class but when I am trying to deploy the code then it is showing 20% code coverage bcoz of which I am unable to deploy the code. Can anyone help?

 

Trigger

trigger lead_agent_trigger on Lead (before insert,before Update) 
    {   
    
    Lead_Agent_Trigger_Helper.Agent(trigger.new);
    
        
    }

Helper Class:-

public class Lead_Agent_Trigger_Helper {

public void Agent(List<Lead> Leads)
{
    for(Lead loopVar : Leads)
    {
        try
        {
            string country = loopVar.Country;
            //Agents__c agent = [select Id,Agent_Name__c,agent_email__c  from Agents__c where Country__c like : country and Active__c = True and Edition__c =: loopVar.Edition__c limit 1];
            if(loopVar.Sent_to_Agent__c==true)
           {
                if(loopVar.Sector_show__c == null && loopVar.Sectors__c == null)
                {
                    Agents__c agent = [select Id,Agent_Name__c,agent_email__c,Sector_show__c,Sectors__c from Agents__c where 
                                       Country__c like : country and 
                                       Active__c = True and 
                                       Edition__c =: loopVar.Edition__c and
                                       Sector_show__c = null and
                                       Sectors__c = null limit 1];
                    loopVar.Agent__c = agent.Agent_Name__c;
                    loopVar.agent_email__c= agent.agent_email__c;
                    
                    Contact contact = [select AccountId,Email from Contact where Id =: agent.Agent_Name__c limit 1];
                    loopVar.Agent_Account__c = contact.AccountId;
                    loopVar.Agents__c = agent.Id;
                    loopVar.Date_sent_to_Agent__c = date.Today();
                }
                else if(loopVar.Sector_show__c != null && loopVar.Sectors__c != null)
                {
                    String sector = loopVar.Sectors__c;
                    Agents__c agent1 = [select Id,Agent_Name__c,agent_email__c,Sector_show__c,Sectors__c from Agents__c 
                                        where Country__c like : country 
                                        and Active__c = True and Edition__c =: loopVar.Edition__c 
                                        and Sector_show__c =: loopVar.Sector_show__c
                                        and Sectors__c  Includes (:sector) limit 1];
                    loopVar.Agent__c = agent1.Agent_Name__c;
                    loopVar.agent_email__c= agent1.agent_email__c;
                    
                    Contact contact1 = [select AccountId,Email from Contact where Id =: agent1.Agent_Name__c limit 1];
                    loopVar.Agent_Account__c = contact1.AccountId;
                    loopVar.Agents__c = agent1.Id;
                    loopVar.Date_sent_to_Agent__c = date.Today();
                }           
            }
        }
        
        catch(Exception E){}
}
}
}

 

Test Class:-

public class Lead_Agent_Trigger_Helper {

public void Agent(List<Lead> Leads)
{
    for(Lead loopVar : Leads)
    {
        try
        {
            string country = loopVar.Country;
            //Agents__c agent = [select Id,Agent_Name__c,agent_email__c  from Agents__c where Country__c like : country and Active__c = True and Edition__c =: loopVar.Edition__c limit 1];
            if(loopVar.Sent_to_Agent__c==true)
           {
                if(loopVar.Sector_show__c == null && loopVar.Sectors__c == null)
                {
                    Agents__c agent = [select Id,Agent_Name__c,agent_email__c,Sector_show__c,Sectors__c from Agents__c where 
                                       Country__c like : country and 
                                       Active__c = True and 
                                       Edition__c =: loopVar.Edition__c and
                                       Sector_show__c = null and
                                       Sectors__c = null limit 1];
                    loopVar.Agent__c = agent.Agent_Name__c;
                    loopVar.agent_email__c= agent.agent_email__c;
                    
                    Contact contact = [select AccountId,Email from Contact where Id =: agent.Agent_Name__c limit 1];
                    loopVar.Agent_Account__c = contact.AccountId;
                    loopVar.Agents__c = agent.Id;
                    loopVar.Date_sent_to_Agent__c = date.Today();
                }
                else if(loopVar.Sector_show__c != null && loopVar.Sectors__c != null)
                {
                    String sector = loopVar.Sectors__c;
                    Agents__c agent1 = [select Id,Agent_Name__c,agent_email__c,Sector_show__c,Sectors__c from Agents__c 
                                        where Country__c like : country 
                                        and Active__c = True and Edition__c =: loopVar.Edition__c 
                                        and Sector_show__c =: loopVar.Sector_show__c
                                        and Sectors__c  Includes (:sector) limit 1];
                    loopVar.Agent__c = agent1.Agent_Name__c;
                    loopVar.agent_email__c= agent1.agent_email__c;
                    
                    Contact contact1 = [select AccountId,Email from Contact where Id =: agent1.Agent_Name__c limit 1];
                    loopVar.Agent_Account__c = contact1.AccountId;
                    loopVar.Agents__c = agent1.Id;
                    loopVar.Date_sent_to_Agent__c = date.Today();
                }           
            }
        }
        
        catch(Exception E){}
}
}

Error:-
 Code Coverage Error

How to write a trigger code with handler class to copy few field value from one object (A)to another object (B) ?


Condition :1
Object A

picklist Field : Subodh            Salary =5000
picklist Field : Subodh             Salary =7000

Object B 
picklist Field : Subodh       Total Salary :12000

Condition : 2

Object : A

picklist Field : Subodh             Salary =7000
picklist Field : Rahul                Salary =7000
picklist Field : Amit                  Salary =5000
picklist Field : Rahul                Salary =7000
picklist Field : Amit                   Salary =5000


Object : B

picklist Field : Subodh            Total Salary =7000
picklist Field : Rahul               Total Salary =14000
picklist Field : Amit                  Total Salary =10000


Thanks
Subodh
I am facing this error when I am refreshing my VF page. I know this is because SOQL query is written inside the for loops but I am struggling with removing the SOQL outside the for loop. 

Here is the method which is called when constructor runs when the page loads

Can anyone please help me in this case.

Thanks
Avesh Lakha​
public List<selectedProductClass> getSelectedProductClassString(){
       
       
        List<List<String>> lstProductsInCategory = new List<List<String>>();
        lstAllAccountProductClassString = new List<selectedProductClass>();
        
        Map <List<String>,String> mapProductCategory = new Map <List<String>,String>();
        Map <List<String>,String> mapShow = new Map <List<String>,String>();
        
        
       for(Account_Product__c accProducts : [SELECT Id,Account__c,Product_Category__c,Show__c,Products__c from Account_Product__c where Account__c =: this.iAccountId]){
                   
           for(String pd : accProducts.Products__c.split(';')) {
           selectedProductClass objClass = new selectedProductClass ();
                objClass.selectedShow = accProducts.Show__c ;
                objClass.selectedCategory = accProducts.Product_Category__c;
                objClass.selectProduct = pd;
                                                 
           Product__c[] prod  = [SELECT Id from Product__c where  Name =:pd AND Product_Category__c =: accProducts.Product_Category__c AND Show__c =:accProducts.Show__c limit 1];
              if (prod.size() > 0)
                objClass.ProductId = prod[0].Id;
                lstAllAccountProductClassString.add(objClass); 
            }
               lstProductsInCategory.add(accProducts.Products__c.split(';'));
               mapProductCategory.put(accProducts.Products__c.split(';'),accProducts.Product_Category__c);
               mapShow.put(accProducts.Products__c.split(';'),accProducts.Show__c);
        }
        

        return lstAllAccountProductClassString;
    }

 

Hi,

I have created a Trigger and used Helper class in the trigger and created the Test Class which is covering 96% of helper class but when I am trying to deploy the code then it is showing 20% code coverage bcoz of which I am unable to deploy the code. Can anyone help?

 

Trigger

trigger lead_agent_trigger on Lead (before insert,before Update) 
    {   
    
    Lead_Agent_Trigger_Helper.Agent(trigger.new);
    
        
    }

Helper Class:-

public class Lead_Agent_Trigger_Helper {

public void Agent(List<Lead> Leads)
{
    for(Lead loopVar : Leads)
    {
        try
        {
            string country = loopVar.Country;
            //Agents__c agent = [select Id,Agent_Name__c,agent_email__c  from Agents__c where Country__c like : country and Active__c = True and Edition__c =: loopVar.Edition__c limit 1];
            if(loopVar.Sent_to_Agent__c==true)
           {
                if(loopVar.Sector_show__c == null && loopVar.Sectors__c == null)
                {
                    Agents__c agent = [select Id,Agent_Name__c,agent_email__c,Sector_show__c,Sectors__c from Agents__c where 
                                       Country__c like : country and 
                                       Active__c = True and 
                                       Edition__c =: loopVar.Edition__c and
                                       Sector_show__c = null and
                                       Sectors__c = null limit 1];
                    loopVar.Agent__c = agent.Agent_Name__c;
                    loopVar.agent_email__c= agent.agent_email__c;
                    
                    Contact contact = [select AccountId,Email from Contact where Id =: agent.Agent_Name__c limit 1];
                    loopVar.Agent_Account__c = contact.AccountId;
                    loopVar.Agents__c = agent.Id;
                    loopVar.Date_sent_to_Agent__c = date.Today();
                }
                else if(loopVar.Sector_show__c != null && loopVar.Sectors__c != null)
                {
                    String sector = loopVar.Sectors__c;
                    Agents__c agent1 = [select Id,Agent_Name__c,agent_email__c,Sector_show__c,Sectors__c from Agents__c 
                                        where Country__c like : country 
                                        and Active__c = True and Edition__c =: loopVar.Edition__c 
                                        and Sector_show__c =: loopVar.Sector_show__c
                                        and Sectors__c  Includes (:sector) limit 1];
                    loopVar.Agent__c = agent1.Agent_Name__c;
                    loopVar.agent_email__c= agent1.agent_email__c;
                    
                    Contact contact1 = [select AccountId,Email from Contact where Id =: agent1.Agent_Name__c limit 1];
                    loopVar.Agent_Account__c = contact1.AccountId;
                    loopVar.Agents__c = agent1.Id;
                    loopVar.Date_sent_to_Agent__c = date.Today();
                }           
            }
        }
        
        catch(Exception E){}
}
}
}

 

Test Class:-

public class Lead_Agent_Trigger_Helper {

public void Agent(List<Lead> Leads)
{
    for(Lead loopVar : Leads)
    {
        try
        {
            string country = loopVar.Country;
            //Agents__c agent = [select Id,Agent_Name__c,agent_email__c  from Agents__c where Country__c like : country and Active__c = True and Edition__c =: loopVar.Edition__c limit 1];
            if(loopVar.Sent_to_Agent__c==true)
           {
                if(loopVar.Sector_show__c == null && loopVar.Sectors__c == null)
                {
                    Agents__c agent = [select Id,Agent_Name__c,agent_email__c,Sector_show__c,Sectors__c from Agents__c where 
                                       Country__c like : country and 
                                       Active__c = True and 
                                       Edition__c =: loopVar.Edition__c and
                                       Sector_show__c = null and
                                       Sectors__c = null limit 1];
                    loopVar.Agent__c = agent.Agent_Name__c;
                    loopVar.agent_email__c= agent.agent_email__c;
                    
                    Contact contact = [select AccountId,Email from Contact where Id =: agent.Agent_Name__c limit 1];
                    loopVar.Agent_Account__c = contact.AccountId;
                    loopVar.Agents__c = agent.Id;
                    loopVar.Date_sent_to_Agent__c = date.Today();
                }
                else if(loopVar.Sector_show__c != null && loopVar.Sectors__c != null)
                {
                    String sector = loopVar.Sectors__c;
                    Agents__c agent1 = [select Id,Agent_Name__c,agent_email__c,Sector_show__c,Sectors__c from Agents__c 
                                        where Country__c like : country 
                                        and Active__c = True and Edition__c =: loopVar.Edition__c 
                                        and Sector_show__c =: loopVar.Sector_show__c
                                        and Sectors__c  Includes (:sector) limit 1];
                    loopVar.Agent__c = agent1.Agent_Name__c;
                    loopVar.agent_email__c= agent1.agent_email__c;
                    
                    Contact contact1 = [select AccountId,Email from Contact where Id =: agent1.Agent_Name__c limit 1];
                    loopVar.Agent_Account__c = contact1.AccountId;
                    loopVar.Agents__c = agent1.Id;
                    loopVar.Date_sent_to_Agent__c = date.Today();
                }           
            }
        }
        
        catch(Exception E){}
}
}

Error:-
 Code Coverage Error

We are currently deploying using ANT or eclipse but to validate we are using only eclipse. 

Can we do validation using ANT. If so can any one please let me know how to do it.

 

Thanks in advance.