• Francisco Garcia 34
  • NEWBIE
  • 50 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 9
    Replies
Hey guys I am completed a controller extension that sends data to a VF page and then the VF page displays it as a table.

Now, I wrote a unit test class for the controller extension. It has 100% coverage but it is failing unfortunately... 

This is my VF page:
 
<apex:page standardController="Case" extensions="FirstProjectController"> 
       
    <!-- Accounts with Open Cases -->
    <apex:pageBlock title="Table of Accounts with Open Cases">
        <apex:pageBlockTable value="{!Cases}" var="c">
            <apex:column value="{!c.AccountId}"/>
            <apex:column value="{!c.Status}"/>
            <apex:column value="{!c.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
  
    <!-- Accounts with No Cases -->
    <apex:pageBlock title="Table of Accounts with no Cases">
        <apex:pageBlockTable value="{!Accounts}" var="a">
            <apex:column value="{!a.Name}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
    <!-- Five most Recent Cases -->
    <apex:pageBlock title="Table of the Five most Recent Cases">
        <apex:pageBlockTable value="{!cases2}" var="c">
            <apex:column value="{!c.Subject}"/>
            <apex:column value="{!c.CreatedDate}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
       
</apex:page>

This is my Apex code: 
public class FirstProjectController {
	public Case myCase {get; set;}
    
    //Lists used to transfer data into the VF page
    public List<Case> cases {get; set;} 
    public List<Account> accounts {get; set;} 
    public List<Case> cases2 {get; set;} 
    
    //Lists that initialize the querys   
    //Query Obtains the Accounts with open cases 
	public List<Case> queryOne = [SELECT AccountId, Status, Subject FROM Case WHERE IsClosed = False ORDER BY AccountId DESC];   

    //Query Obtains the Accounts with no cases
    public List<Account> queryTwo = [Select Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM Case) ORDER BY Name ASC];

    //Query Obtains the 5 most recent cases
    public List<Case> queryThree = [SELECT Subject, CreatedDate FROM Case ORDER BY CreatedDate DESC Limit 5];
    
    public FirstProjectController(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();   
    
        //Transfer the data into the VF page
        this.cases = queryOne;         	      
    	this.accounts = queryTwo;            
        this.cases2 = queryThree;        
    }
}

This is my actual test code:
 
@isTest 
public class FirstProjectControllerTest {

    public static testMethod void testMyController() {
        
        //Create a new Case
        Case caseOne = new Case(Subject='Testing 1');
        
        //Insert the new Case into Cases
        insert caseOne;
        
        //Check that caseOne is not null
        System.assertNotEquals(caseOne,null);
        
        //Instantiate the extension and controller
        ApexPages.StandardController ctrl = new ApexPages.StandardController(caseOne);
		FirstProjectController ext = new FirstProjectController(ctrl);
        
        //Run the first query from the FirstProject Class
        List<Case> queryOne = [SELECT AccountId, Status, Subject FROM Case WHERE Id =:caseOne.Id];
        
        //Check that caseOne has the correct subject
        System.assertEquals('Testing 1', caseOne.Subject);
        
        //Check that caseOne is a new Case
        System.assertEquals('new', caseOne.Status);
        
    }
}

Any form of help would be greatly appreciated!
 
Hey guys I am working with the Sample Console and I want to embed this visualforce page along with its Apex code into the left hand panel. Could anybody help me out, or point me to a good source that does this? 

Here is my Apex code:
public class controllerClass {
    public Case myCase {get; set;} 
    public List<Case> cases {get; set;} 
    public List<Account> accounts {get; set;} 
    public List<Case> cases2 {get; set;} 
    
    public controllerClass(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();   
        
        //Query Obtains the Accounts with open cases and displays them as a table in firstProject.vfp
        this.cases = [SELECT AccountId, Status, Subject FROM Case WHERE IsClosed = False ORDER BY AccountId DESC];       
    	
        //Query Obtains the Accounts with no cases
    	this.accounts = [Select Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM Case) ORDER BY Name ASC];
        
        //Query Obtains the 5 most recent cases
        this.cases2 = [SELECT Subject, CreatedDate FROM Case ORDER BY CreatedDate DESC Limit 5];     
    }	
}

This is my Visualforce page:
<apex:page standardController="Case" extensions="controllerClass"> 
    
    <apex:pageBlock title="Table of Accounts with Open Cases">
        <apex:pageBlockTable value="{!Cases}" var="c">
            <apex:column value="{!c.AccountId}"/>
            <apex:column value="{!c.Status}"/>
            <apex:column value="{!c.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
    <apex:pageBlock title="Table of Accounts with no Cases">
        <apex:pageBlockTable value="{!Accounts}" var="a">
            <apex:column value="{!a.Name}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
       
    <apex:pageBlock title="Table of 5 most recent cases">
        <apex:pageBlockTable value="{!cases2}" var="c">
            <apex:column value="{!c.Subject}"/>
            <apex:column value="{!c.CreatedDate}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
	   
</apex:page>

Note: My Apex and VF are 100% functional, I am wondering where do I go next. I read about apex:component on this source, but I am not sure if this is the starting point I am looking for:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_component.htm

Thanks guys!
Hey guys! This should be my last question for a while, thanks for all the help so far!

I dont think i understand how data is passed between Apex into the controller... I though you create a List of objects and and you store a query to make it display on the table

Here is my Apex:
public class controllerClass {
    public Case myCase {get; set;} 
    public List<Case> cases {get; set;} 
    public List<Account> accounts {get; set;} 
    public List<Case> cases2 {get; set;} 
    
    public controllerClass(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();   
        
        //Query Obtains the Accounts with open cases and displays them as a table in firstProject.vfp
        this.cases = [SELECT AccountId, Status, Subject FROM Case WHERE IsClosed = False ORDER BY AccountId DESC];       
    	
        //Query Obtains the Accounts with no cases
    	this.accounts = [Select Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM Case)];
        
        //Query Obtains the 5 most recent cases
        this.cases2 = [SELECT Subject, CreatedDate FROM Case ORDER BY CreatedDate Limit 5];     
    }	
}

I think it the line this.case2 is completely wrong and it causing the issue... I dont think it is even transferring data... Could somebody help me fix it and also explain (or share a source) how the query information is actually being transfer into my visualforce page.

This is my VF page:
<apex:page standardController="Case" extensions="controllerClass"> 
    
    <apex:pageBlock title="Table of Accounts with Open Cases">
        <apex:pageBlockTable value="{!Cases}" var="c">
            <apex:column value="{!c.AccountId}"/>
            <apex:column value="{!c.Status}"/>
            <apex:column value="{!c.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
    <apex:pageBlock title="Table of Accounts with no Cases">
        <apex:pageBlockTable value="{!Accounts}" var="a">
            <apex:column value="{!a.Name}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
    <apex:pageBlock title="Table of 5 most recent cases">
        <apex:pageBlockTable value="{!Cases}" var="c">
            <apex:column value="{!c.Subject}"/>
            <apex:column value="{!c.CreatedDate}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
</apex:page>

The first two tables are correct. The last should display a table of the 5 most recent cases, however my program crashes when I attempt to preview this code I have shared.

Once again thanks for all the amazing support!
Hey guys,

I am looking to query the accounts that do not have any case. I have managed to query the accounts with cases in the first query statement of the code:
 
public class controllerClass {
    Public Case myCase {get; set;} 
    public List<Case> cases {get; set;} 
    public List<Account> accounts {get; set;} 
    
    
    Public controllerClass(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();   
        
        //Query Obtains the Accounts with cases and displays them as a table in firstProject.vfp
        this.cases = [SELECT AccountId, Status, Subject FROM Case ORDER BY AccountId DESC];       
    	
        //This line is supposed to obtain the Accounts with no cases
    	this.accounts = [Select Name FROM Account];
    }	
}

How could I use that result to find out the Accounts with no cases? I dont think it is necessary to provide the visualforce page.

Thanks
 
I need to pass a number from my Apex Class into my visualforce page.

This is my Apex Class:
public class controllerClass {
    Public Case myCase {get; set;} 
    public List<Case> cases {get; set;}    
    
    List<Case> openedCases = [SELECT AccountId, Status, Subject FROM Case WHERE IsClosed = False ORDER BY AccountId DESC];
    
    Public controllerClass(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();        
        this.cases = openedCases;     
    }	
    
	//This is the integer I want to pass into visualforce
	Integer temp = openedCases.size();
	
    
}

This is my Visualforce page:
 
<apex:page standardController="Case" extensions="controllerClass"> 
    
    <apex:pageBlock title="Table of Open Cases">
        <apex:pageBlockTable value="{!Cases}" var="c">
            <apex:column value="{!c.AccountId}"/>
            <apex:column value="{!c.Status}"/>
            <apex:column value="{!c.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
    <!-- Variable should go below-->
    <apex:variable var="" value="" />
    <p>The number from apex is <!-- Apex Number -->.</p>

        
</apex:page>

 
Hello, I am trying to display a table with all my cases. However the table only has one row... I think as the for loop iterates it replaces the previous row.

This is my Apex code:
public class controllerClass {
    Public Case myCase {get; set;}
    
    Public controllerClass(ApexPages.StandardController stdController){ 
        
        this.myCase = (Case)stdController.getRecord();
        
        List<Case> cases = [SELECT CaseNumber, AccountId, Status, Subject FROM Case];
            
        for(Integer i = 0; i < cases.size(); i++){
        	myCase.AccountId = cases[i].AccountId;
        	myCase.Status = cases[i].Status;
        	myCase.Subject = cases[i].Subject; 
        }
        
    }	
}

This is my visualforce page: 
<apex:page standardController="Case" extensions="controllerClass"> 
    <apex:pageBlock title="Table of Cases">
        <apex:pageBlockTable value="{!Case}" var="c">
            <apex:column value="{!Case.AccountId}"/>
            <apex:column value="{!Case.Status}"/>
            <apex:column value="{!Case.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
</apex:page>

This is a picture of the VF page when it is generated:
User-added image

I have a feeling that the issue comes from apex:PageBlockTable of my VF. Could somebody please help figure out what is going on? I read that in my apex, I should have Public List<Case> myCases {get; set;} instead of Public <Case> myCases {get; set;} But it crashes everytime i replace it!

Any help would be appreciated!
Hello, I am trying to display a table with all my cases. However the table only has one row... I think as the for loop iterates it replaces the previous row.

This is my Apex code:
public class controllerClass {
    Public Case myCase {get; set;}
    
    Public controllerClass(ApexPages.StandardController stdController){ 
        
        this.myCase = (Case)stdController.getRecord();
        
        List<Case> cases = [SELECT CaseNumber, AccountId, Status, Subject FROM Case];
            
        for(Integer i = 0; i < cases.size(); i++){
        	myCase.AccountId = cases[i].AccountId;
        	myCase.Status = cases[i].Status;
        	myCase.Subject = cases[i].Subject; 
        }
        
    }	
}

This is my visualforce page: 
<apex:page standardController="Case" extensions="controllerClass"> 
    <apex:pageBlock title="Table of Cases">
        <apex:pageBlockTable value="{!Case}" var="c">
            <apex:column value="{!Case.AccountId}"/>
            <apex:column value="{!Case.Status}"/>
            <apex:column value="{!Case.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
</apex:page>

This is a picture of the VF page when it is generated:
User-added image

I have a feeling that the issue comes from apex:PageBlockTable of my VF. Could somebody please help figure out what is going on? I read that in my apex, I should have Public List<Case> myCases {get; set;} instead of Public <Case> myCases {get; set;} But it crashes everytime i replace it!

Any help would be appreciated!
Hey guys I am completed a controller extension that sends data to a VF page and then the VF page displays it as a table.

Now, I wrote a unit test class for the controller extension. It has 100% coverage but it is failing unfortunately... 

This is my VF page:
 
<apex:page standardController="Case" extensions="FirstProjectController"> 
       
    <!-- Accounts with Open Cases -->
    <apex:pageBlock title="Table of Accounts with Open Cases">
        <apex:pageBlockTable value="{!Cases}" var="c">
            <apex:column value="{!c.AccountId}"/>
            <apex:column value="{!c.Status}"/>
            <apex:column value="{!c.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
  
    <!-- Accounts with No Cases -->
    <apex:pageBlock title="Table of Accounts with no Cases">
        <apex:pageBlockTable value="{!Accounts}" var="a">
            <apex:column value="{!a.Name}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
    <!-- Five most Recent Cases -->
    <apex:pageBlock title="Table of the Five most Recent Cases">
        <apex:pageBlockTable value="{!cases2}" var="c">
            <apex:column value="{!c.Subject}"/>
            <apex:column value="{!c.CreatedDate}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
       
</apex:page>

This is my Apex code: 
public class FirstProjectController {
	public Case myCase {get; set;}
    
    //Lists used to transfer data into the VF page
    public List<Case> cases {get; set;} 
    public List<Account> accounts {get; set;} 
    public List<Case> cases2 {get; set;} 
    
    //Lists that initialize the querys   
    //Query Obtains the Accounts with open cases 
	public List<Case> queryOne = [SELECT AccountId, Status, Subject FROM Case WHERE IsClosed = False ORDER BY AccountId DESC];   

    //Query Obtains the Accounts with no cases
    public List<Account> queryTwo = [Select Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM Case) ORDER BY Name ASC];

    //Query Obtains the 5 most recent cases
    public List<Case> queryThree = [SELECT Subject, CreatedDate FROM Case ORDER BY CreatedDate DESC Limit 5];
    
    public FirstProjectController(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();   
    
        //Transfer the data into the VF page
        this.cases = queryOne;         	      
    	this.accounts = queryTwo;            
        this.cases2 = queryThree;        
    }
}

This is my actual test code:
 
@isTest 
public class FirstProjectControllerTest {

    public static testMethod void testMyController() {
        
        //Create a new Case
        Case caseOne = new Case(Subject='Testing 1');
        
        //Insert the new Case into Cases
        insert caseOne;
        
        //Check that caseOne is not null
        System.assertNotEquals(caseOne,null);
        
        //Instantiate the extension and controller
        ApexPages.StandardController ctrl = new ApexPages.StandardController(caseOne);
		FirstProjectController ext = new FirstProjectController(ctrl);
        
        //Run the first query from the FirstProject Class
        List<Case> queryOne = [SELECT AccountId, Status, Subject FROM Case WHERE Id =:caseOne.Id];
        
        //Check that caseOne has the correct subject
        System.assertEquals('Testing 1', caseOne.Subject);
        
        //Check that caseOne is a new Case
        System.assertEquals('new', caseOne.Status);
        
    }
}

Any form of help would be greatly appreciated!
 
Hey guys I am working with the Sample Console and I want to embed this visualforce page along with its Apex code into the left hand panel. Could anybody help me out, or point me to a good source that does this? 

Here is my Apex code:
public class controllerClass {
    public Case myCase {get; set;} 
    public List<Case> cases {get; set;} 
    public List<Account> accounts {get; set;} 
    public List<Case> cases2 {get; set;} 
    
    public controllerClass(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();   
        
        //Query Obtains the Accounts with open cases and displays them as a table in firstProject.vfp
        this.cases = [SELECT AccountId, Status, Subject FROM Case WHERE IsClosed = False ORDER BY AccountId DESC];       
    	
        //Query Obtains the Accounts with no cases
    	this.accounts = [Select Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM Case) ORDER BY Name ASC];
        
        //Query Obtains the 5 most recent cases
        this.cases2 = [SELECT Subject, CreatedDate FROM Case ORDER BY CreatedDate DESC Limit 5];     
    }	
}

This is my Visualforce page:
<apex:page standardController="Case" extensions="controllerClass"> 
    
    <apex:pageBlock title="Table of Accounts with Open Cases">
        <apex:pageBlockTable value="{!Cases}" var="c">
            <apex:column value="{!c.AccountId}"/>
            <apex:column value="{!c.Status}"/>
            <apex:column value="{!c.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
    <apex:pageBlock title="Table of Accounts with no Cases">
        <apex:pageBlockTable value="{!Accounts}" var="a">
            <apex:column value="{!a.Name}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
       
    <apex:pageBlock title="Table of 5 most recent cases">
        <apex:pageBlockTable value="{!cases2}" var="c">
            <apex:column value="{!c.Subject}"/>
            <apex:column value="{!c.CreatedDate}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
	   
</apex:page>

Note: My Apex and VF are 100% functional, I am wondering where do I go next. I read about apex:component on this source, but I am not sure if this is the starting point I am looking for:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_component.htm

Thanks guys!
Hey guys! This should be my last question for a while, thanks for all the help so far!

I dont think i understand how data is passed between Apex into the controller... I though you create a List of objects and and you store a query to make it display on the table

Here is my Apex:
public class controllerClass {
    public Case myCase {get; set;} 
    public List<Case> cases {get; set;} 
    public List<Account> accounts {get; set;} 
    public List<Case> cases2 {get; set;} 
    
    public controllerClass(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();   
        
        //Query Obtains the Accounts with open cases and displays them as a table in firstProject.vfp
        this.cases = [SELECT AccountId, Status, Subject FROM Case WHERE IsClosed = False ORDER BY AccountId DESC];       
    	
        //Query Obtains the Accounts with no cases
    	this.accounts = [Select Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM Case)];
        
        //Query Obtains the 5 most recent cases
        this.cases2 = [SELECT Subject, CreatedDate FROM Case ORDER BY CreatedDate Limit 5];     
    }	
}

I think it the line this.case2 is completely wrong and it causing the issue... I dont think it is even transferring data... Could somebody help me fix it and also explain (or share a source) how the query information is actually being transfer into my visualforce page.

This is my VF page:
<apex:page standardController="Case" extensions="controllerClass"> 
    
    <apex:pageBlock title="Table of Accounts with Open Cases">
        <apex:pageBlockTable value="{!Cases}" var="c">
            <apex:column value="{!c.AccountId}"/>
            <apex:column value="{!c.Status}"/>
            <apex:column value="{!c.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
    <apex:pageBlock title="Table of Accounts with no Cases">
        <apex:pageBlockTable value="{!Accounts}" var="a">
            <apex:column value="{!a.Name}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
    <apex:pageBlock title="Table of 5 most recent cases">
        <apex:pageBlockTable value="{!Cases}" var="c">
            <apex:column value="{!c.Subject}"/>
            <apex:column value="{!c.CreatedDate}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
</apex:page>

The first two tables are correct. The last should display a table of the 5 most recent cases, however my program crashes when I attempt to preview this code I have shared.

Once again thanks for all the amazing support!
Hey guys,

I am looking to query the accounts that do not have any case. I have managed to query the accounts with cases in the first query statement of the code:
 
public class controllerClass {
    Public Case myCase {get; set;} 
    public List<Case> cases {get; set;} 
    public List<Account> accounts {get; set;} 
    
    
    Public controllerClass(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();   
        
        //Query Obtains the Accounts with cases and displays them as a table in firstProject.vfp
        this.cases = [SELECT AccountId, Status, Subject FROM Case ORDER BY AccountId DESC];       
    	
        //This line is supposed to obtain the Accounts with no cases
    	this.accounts = [Select Name FROM Account];
    }	
}

How could I use that result to find out the Accounts with no cases? I dont think it is necessary to provide the visualforce page.

Thanks
 
I need to pass a number from my Apex Class into my visualforce page.

This is my Apex Class:
public class controllerClass {
    Public Case myCase {get; set;} 
    public List<Case> cases {get; set;}    
    
    List<Case> openedCases = [SELECT AccountId, Status, Subject FROM Case WHERE IsClosed = False ORDER BY AccountId DESC];
    
    Public controllerClass(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();        
        this.cases = openedCases;     
    }	
    
	//This is the integer I want to pass into visualforce
	Integer temp = openedCases.size();
	
    
}

This is my Visualforce page:
 
<apex:page standardController="Case" extensions="controllerClass"> 
    
    <apex:pageBlock title="Table of Open Cases">
        <apex:pageBlockTable value="{!Cases}" var="c">
            <apex:column value="{!c.AccountId}"/>
            <apex:column value="{!c.Status}"/>
            <apex:column value="{!c.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
    <!-- Variable should go below-->
    <apex:variable var="" value="" />
    <p>The number from apex is <!-- Apex Number -->.</p>

        
</apex:page>

 
Hello, I am trying to display a table with all my cases. However the table only has one row... I think as the for loop iterates it replaces the previous row.

This is my Apex code:
public class controllerClass {
    Public Case myCase {get; set;}
    
    Public controllerClass(ApexPages.StandardController stdController){ 
        
        this.myCase = (Case)stdController.getRecord();
        
        List<Case> cases = [SELECT CaseNumber, AccountId, Status, Subject FROM Case];
            
        for(Integer i = 0; i < cases.size(); i++){
        	myCase.AccountId = cases[i].AccountId;
        	myCase.Status = cases[i].Status;
        	myCase.Subject = cases[i].Subject; 
        }
        
    }	
}

This is my visualforce page: 
<apex:page standardController="Case" extensions="controllerClass"> 
    <apex:pageBlock title="Table of Cases">
        <apex:pageBlockTable value="{!Case}" var="c">
            <apex:column value="{!Case.AccountId}"/>
            <apex:column value="{!Case.Status}"/>
            <apex:column value="{!Case.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
</apex:page>

This is a picture of the VF page when it is generated:
User-added image

I have a feeling that the issue comes from apex:PageBlockTable of my VF. Could somebody please help figure out what is going on? I read that in my apex, I should have Public List<Case> myCases {get; set;} instead of Public <Case> myCases {get; set;} But it crashes everytime i replace it!

Any help would be appreciated!