• Andreas Yannelos
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hi!

I have the query below in the controller of one of my visualforce pages:
 
SELECT Id, Name, Title, Company, Country, CreatedDate, Status FROM Lead WHERE Status='New' AND OwnerId= :UserInfo.getUserID() ORDER BY CreatedDate DESC

What I would like to do some kind of outer join to check if the Lead.Company field exists as a Account.Name so I can show this on the Visualforce page.

Any ideas on how to do this?

Hi!

Have tried to get this to work for many hours now, but can't find a solution. I have written a cusom controller for a visualforce page that looks like the one below. And get 0% code coverage on the Apex Class.

Any idea what's wrong?

Controller:

public class outboundLeadStart {
    // ApexPages.StandardSetController must be instantiated
    // for standard list controllers
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT Id, Name, Company, Country, CreatedDate, Status FROM Lead WHERE Status='New' AND OwnerId= :UserInfo.getUserID() ORDER BY CreatedDate DESC LIMIT 100]));
            }
            setCon.setPageSize(setCon.getResultSize());
            return setCon;
        }
        set;
    }
    
    public integer getCountLeads() {
            String statusStage = 'New';
            String ownerId = UserInfo.getUserID();
            return(Database.countQuery('SELECT count() FROM Lead WHERE Status= :statusStage AND OwnerId= :ownerId')); // Returns Integer        
    }
    
    // Initialize setCon and return a list of records
    public List<Lead> getLeads() {
        return (List<Lead>) setCon.getRecords();
    }
    
    public PageReference save() {
        
        try {
            update setCon.getRecords();
        } catch(DMLException e) {
            Apexpages.addmessages(e);
        }
        
        PageReference pageRef = new PageReference('/lightning/n/Outbound_Planning');
        pageRef.setRedirect(true);
        return pageRef;        
    }    
}

And the test class looks like this:
@isTest
private class testoutboundLeadStartTest {
    static testMethod void testoutboundLeadStartTest() 
    {
        User u = new User(
            ProfileId = [SELECT Id FROM Profile WHERE Name = 'Sales Representative'].Id,
            LastName = 'last',
            Email = 'last@example.com',
            Username = 'last@example.com' + System.currentTimeMillis(),
            CompanyName = 'TEST',
            Title = 'title',
            Alias = 'alias',
            TimeZoneSidKey = 'America/Los_Angeles',
            EmailEncodingKey = 'UTF-8',
            LanguageLocaleKey = 'en_US',
            LocaleSidKey = 'en_US'
        );
        
        insert u;
        
        Id theOwnerId = UserInfo.getUserID();
        
        ApexPages.StandardSetController setCon;
        PageReference pageRef = Page.outboundLeadsStart;
        
        List <Lead> addedLeads = new List<Lead>();
        
        Lead testLead = new Lead();
        testLead.LastName='Test Lead';
        testLead.Company='Test Company1';
        testLead.Status='New';
        testLead.OwnerId=theOwnerId;
        insert testLead;
        
        List<Lead> cus = new List<Lead>{};
            
        Test.startTest();
        System.assertEquals('Test Lead', testLead.LastName);
        Test.setCurrentPage(pageRef);
        outboundLeadStart controller = new outboundLeadStart();
        Test.stopTest();
        
    }        
}
 

Can't understand why this get 0% code coverage on the Apex Class.

BR,
Andreas


 
Hi!

I have the query below in the controller of one of my visualforce pages:
 
SELECT Id, Name, Title, Company, Country, CreatedDate, Status FROM Lead WHERE Status='New' AND OwnerId= :UserInfo.getUserID() ORDER BY CreatedDate DESC

What I would like to do some kind of outer join to check if the Lead.Company field exists as a Account.Name so I can show this on the Visualforce page.

Any ideas on how to do this?

Hi!

Have tried to get this to work for many hours now, but can't find a solution. I have written a cusom controller for a visualforce page that looks like the one below. And get 0% code coverage on the Apex Class.

Any idea what's wrong?

Controller:

public class outboundLeadStart {
    // ApexPages.StandardSetController must be instantiated
    // for standard list controllers
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT Id, Name, Company, Country, CreatedDate, Status FROM Lead WHERE Status='New' AND OwnerId= :UserInfo.getUserID() ORDER BY CreatedDate DESC LIMIT 100]));
            }
            setCon.setPageSize(setCon.getResultSize());
            return setCon;
        }
        set;
    }
    
    public integer getCountLeads() {
            String statusStage = 'New';
            String ownerId = UserInfo.getUserID();
            return(Database.countQuery('SELECT count() FROM Lead WHERE Status= :statusStage AND OwnerId= :ownerId')); // Returns Integer        
    }
    
    // Initialize setCon and return a list of records
    public List<Lead> getLeads() {
        return (List<Lead>) setCon.getRecords();
    }
    
    public PageReference save() {
        
        try {
            update setCon.getRecords();
        } catch(DMLException e) {
            Apexpages.addmessages(e);
        }
        
        PageReference pageRef = new PageReference('/lightning/n/Outbound_Planning');
        pageRef.setRedirect(true);
        return pageRef;        
    }    
}

And the test class looks like this:
@isTest
private class testoutboundLeadStartTest {
    static testMethod void testoutboundLeadStartTest() 
    {
        User u = new User(
            ProfileId = [SELECT Id FROM Profile WHERE Name = 'Sales Representative'].Id,
            LastName = 'last',
            Email = 'last@example.com',
            Username = 'last@example.com' + System.currentTimeMillis(),
            CompanyName = 'TEST',
            Title = 'title',
            Alias = 'alias',
            TimeZoneSidKey = 'America/Los_Angeles',
            EmailEncodingKey = 'UTF-8',
            LanguageLocaleKey = 'en_US',
            LocaleSidKey = 'en_US'
        );
        
        insert u;
        
        Id theOwnerId = UserInfo.getUserID();
        
        ApexPages.StandardSetController setCon;
        PageReference pageRef = Page.outboundLeadsStart;
        
        List <Lead> addedLeads = new List<Lead>();
        
        Lead testLead = new Lead();
        testLead.LastName='Test Lead';
        testLead.Company='Test Company1';
        testLead.Status='New';
        testLead.OwnerId=theOwnerId;
        insert testLead;
        
        List<Lead> cus = new List<Lead>{};
            
        Test.startTest();
        System.assertEquals('Test Lead', testLead.LastName);
        Test.setCurrentPage(pageRef);
        outboundLeadStart controller = new outboundLeadStart();
        Test.stopTest();
        
    }        
}
 

Can't understand why this get 0% code coverage on the Apex Class.

BR,
Andreas