• JeffTrier
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies

Hello everyone,

I am familiar with Unit Testing in general, but have been having a heck of a time implementing this using APEX with VisualForce Extensions. I have been searching the internet and docs for doing this, but I can't find a straightforward example. Can someone please post a unit test example for me? I would greatly appreciate it! 

Below is the class I am creating a Unit Test for. The VF page calling this extension is named "DynamicCase", and I am using the Force.com Eclipse plugin for this... if any of that helps. Thanks all!

-Jeff


public with sharing class VistaCaseExtension {

    // Create extension hook
    public ApexPages.StandardController controller {get;set;}
    
    // accessable variables
    public Case caseCont {get;set;}      // case controller global    
    public String testRet {get;set;}     // test return
    public String caseType {get;set;}    // used for caseType dropdown list

    // List objects for iteration    
    public List<Contact> contacts {get; set;}
    public List<Account> accounts {get; set;}
    
    // Constructor
    public VistaCaseExtension(ApexPages.StandardController std){
        // set global case controller
        controller = std;
        caseCont = (Case) controller.getRecord();
        
        // set default caseType selection state
        caseType = 'select';
        
        // populate account
        PopulateCase();
        
        
        testRet = 'SELECT CASE TYPE';
    }
    
    // populate the case page with all associated info
    public void PopulateCase() {
           
        // Retrieve Account for this Case
        if(caseCont.AccountId != NULL){
        
            // get all account info, to prepopulate fields
            getAccount(caseCont.AccountId);
            
            // get all contacts for this cases account, to prepopulate fields
            getAllContacts();
            
            // Set Primary Contact if field is empty
            if(caseCont.ContactID == NULL){
                setPrimaryContract();
            }                        
        }
                          
        // set ownerID if the field is empty
        if(caseCont.OwnerID == NULL){
            caseCont.OwnerID = UserInfo.getUserId();
        }
                
        // test
        testRet = caseCont.Type;
                            
    }  
    
    
    // Set Contact
    public void setPrimaryContract(){
        // Select the first contact from the account's list if none has been assigned
        //   or else assign the accounts primary technician
        if(caseCont.Account.PrimaryTechnicalContact__c == NULL){// use null, not ''
            //getPrimaryContact();
            // set the specified case accounts primary contact
            caseCont.Contact = [select id, phone, email, name
                                from Contact
                                where AccountID=:caseCont.AccountId
                                LIMIT 1];
                             
            // assign the contact ID                         
            caseCont.ContactID = caseCont.Contact.id;                    
        }else{
            caseCont.ContactID = caseCont.Account.PrimaryTechnicalContact__c;
        }    
    }
    
    // get list of all contacts associated with the cases account
    // used for contact lists
    public void getAllContacts(){
        contacts = [select id, Email, Phone, Name, Title
                    from Contact
                    where AccountID=:caseCont.AccountId
                    order by firstname asc];   
        
    }
    
    // populate account
    public void getAccount(String relObjectID){
        caseCont.Account = [select id, AccountNumber, ShippingStreet, Name, OwnerID, Phone, PrimaryTechnicalContact__c, Account_No__c
                            from Account
                            where id=:relObjectID
                            LIMIT 1];
    }

}

 

Hi guys and gals,

 

I am trying to wrap my head around actionSupport calls within VisualForce, and I keep getting this error:

java.lang.IllegalArgumentException: Illegal view ID

 

I scoured the web, various SFDC entries, and I still can't figure out why this error is happening. Any help would be greatly appreciated.

 

Thanks!

-Jeff

 

 

VisualForce Page:

 

<apex:page StandardController="Case" extensions="VistaCaseExtension">
    <apex:form>
        
        
        <apex:outputPanel id="counter">
            <apex:outputText value="Click Me!" />
            <apex:actionSupport event="onclick"  action="{!myTest}" rerender="counter2" status="refreshstatus" /> 
        </apex:outputPanel>  
        
        <apex:actionStatus id="refreshstatus" startstyle="color:green;" startText="Refreshing...."></apex:actionStatus>
          
        <apex:outputPanel id="counter2">
            <p>
            <apex:outputText value="I want to change!" />
            </p>
        </apex:outputPanel> 
              
    </apex:form>
    
</apex:page>

 

Apex Class

public class VistaCaseExtension {

    // Create extension hook
    private ApexPages.StandardController controller;
    
    String testRet = 'clicked... now what?';
    
    // Constructor
    public VistaCaseExtension(ApexPages.StandardController std){
        controller = std;
    }
    
    public void AccountPopulated() {
        Case cont=(Case) controller.getRecord();
        cont.Account=[select AccountNumber, Site, ShippingStreet from Account where id=:cont.AccountId];
    }    
    
    public String myTest(){
        return testRet;
    }  
    
    
}

 


Hi all,

 

I am using a filter within the Case objects "Contact" Lookup field, so it will only list Contacts attached to an Account.  This works great, with one exception... it only lists records that were "Recently Viewed".

 

This throws a wrench in my plan, since some Contacts haven't been viewed in over a year... and wont be listed.

 

Is there a way to remove this flag?

 

Thanks!

-Jeff

Hi all,

 

I have been pouring over documentation and tutorials, and have yet to find a way to run a report based on lookup tables.

 

Basically what I want to do is create a master table that is used to populate a custom "read only" field in an Account page, based on the Account pages address fields. I have read about Master-Detail relationships, which seems to be what I'm looking for... but being a bit new to SFDC (tutorials and reading withstanding), I am not sure how to tie that into what I am looking to do... or if that's the right way to do it. :)

 

Any help would be great, and please let me know if you need more clarification.

 

Thanks!

-Jeff

 

Hello everyone,

I am familiar with Unit Testing in general, but have been having a heck of a time implementing this using APEX with VisualForce Extensions. I have been searching the internet and docs for doing this, but I can't find a straightforward example. Can someone please post a unit test example for me? I would greatly appreciate it! 

Below is the class I am creating a Unit Test for. The VF page calling this extension is named "DynamicCase", and I am using the Force.com Eclipse plugin for this... if any of that helps. Thanks all!

-Jeff


public with sharing class VistaCaseExtension {

    // Create extension hook
    public ApexPages.StandardController controller {get;set;}
    
    // accessable variables
    public Case caseCont {get;set;}      // case controller global    
    public String testRet {get;set;}     // test return
    public String caseType {get;set;}    // used for caseType dropdown list

    // List objects for iteration    
    public List<Contact> contacts {get; set;}
    public List<Account> accounts {get; set;}
    
    // Constructor
    public VistaCaseExtension(ApexPages.StandardController std){
        // set global case controller
        controller = std;
        caseCont = (Case) controller.getRecord();
        
        // set default caseType selection state
        caseType = 'select';
        
        // populate account
        PopulateCase();
        
        
        testRet = 'SELECT CASE TYPE';
    }
    
    // populate the case page with all associated info
    public void PopulateCase() {
           
        // Retrieve Account for this Case
        if(caseCont.AccountId != NULL){
        
            // get all account info, to prepopulate fields
            getAccount(caseCont.AccountId);
            
            // get all contacts for this cases account, to prepopulate fields
            getAllContacts();
            
            // Set Primary Contact if field is empty
            if(caseCont.ContactID == NULL){
                setPrimaryContract();
            }                        
        }
                          
        // set ownerID if the field is empty
        if(caseCont.OwnerID == NULL){
            caseCont.OwnerID = UserInfo.getUserId();
        }
                
        // test
        testRet = caseCont.Type;
                            
    }  
    
    
    // Set Contact
    public void setPrimaryContract(){
        // Select the first contact from the account's list if none has been assigned
        //   or else assign the accounts primary technician
        if(caseCont.Account.PrimaryTechnicalContact__c == NULL){// use null, not ''
            //getPrimaryContact();
            // set the specified case accounts primary contact
            caseCont.Contact = [select id, phone, email, name
                                from Contact
                                where AccountID=:caseCont.AccountId
                                LIMIT 1];
                             
            // assign the contact ID                         
            caseCont.ContactID = caseCont.Contact.id;                    
        }else{
            caseCont.ContactID = caseCont.Account.PrimaryTechnicalContact__c;
        }    
    }
    
    // get list of all contacts associated with the cases account
    // used for contact lists
    public void getAllContacts(){
        contacts = [select id, Email, Phone, Name, Title
                    from Contact
                    where AccountID=:caseCont.AccountId
                    order by firstname asc];   
        
    }
    
    // populate account
    public void getAccount(String relObjectID){
        caseCont.Account = [select id, AccountNumber, ShippingStreet, Name, OwnerID, Phone, PrimaryTechnicalContact__c, Account_No__c
                            from Account
                            where id=:relObjectID
                            LIMIT 1];
    }

}

 

Hi guys and gals,

 

I am trying to wrap my head around actionSupport calls within VisualForce, and I keep getting this error:

java.lang.IllegalArgumentException: Illegal view ID

 

I scoured the web, various SFDC entries, and I still can't figure out why this error is happening. Any help would be greatly appreciated.

 

Thanks!

-Jeff

 

 

VisualForce Page:

 

<apex:page StandardController="Case" extensions="VistaCaseExtension">
    <apex:form>
        
        
        <apex:outputPanel id="counter">
            <apex:outputText value="Click Me!" />
            <apex:actionSupport event="onclick"  action="{!myTest}" rerender="counter2" status="refreshstatus" /> 
        </apex:outputPanel>  
        
        <apex:actionStatus id="refreshstatus" startstyle="color:green;" startText="Refreshing...."></apex:actionStatus>
          
        <apex:outputPanel id="counter2">
            <p>
            <apex:outputText value="I want to change!" />
            </p>
        </apex:outputPanel> 
              
    </apex:form>
    
</apex:page>

 

Apex Class

public class VistaCaseExtension {

    // Create extension hook
    private ApexPages.StandardController controller;
    
    String testRet = 'clicked... now what?';
    
    // Constructor
    public VistaCaseExtension(ApexPages.StandardController std){
        controller = std;
    }
    
    public void AccountPopulated() {
        Case cont=(Case) controller.getRecord();
        cont.Account=[select AccountNumber, Site, ShippingStreet from Account where id=:cont.AccountId];
    }    
    
    public String myTest(){
        return testRet;
    }  
    
    
}

 


Hi all,

 

I am using a filter within the Case objects "Contact" Lookup field, so it will only list Contacts attached to an Account.  This works great, with one exception... it only lists records that were "Recently Viewed".

 

This throws a wrench in my plan, since some Contacts haven't been viewed in over a year... and wont be listed.

 

Is there a way to remove this flag?

 

Thanks!

-Jeff

Hi all,

 

I have been pouring over documentation and tutorials, and have yet to find a way to run a report based on lookup tables.

 

Basically what I want to do is create a master table that is used to populate a custom "read only" field in an Account page, based on the Account pages address fields. I have read about Master-Detail relationships, which seems to be what I'm looking for... but being a bit new to SFDC (tutorials and reading withstanding), I am not sure how to tie that into what I am looking to do... or if that's the right way to do it. :)

 

Any help would be great, and please let me know if you need more clarification.

 

Thanks!

-Jeff