• DavidD
  • NEWBIE
  • 25 Points
  • Member since 2008

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
HI, I am very new to VF and Apex Classes. 
I just created a VF page with a custom controller in Sandbox. Now I need to do unit test before deployment. I have no clue how to write the unit test:

What I built is a search page, user can type in search criteria and then click on search

Here is my Page:
<apex:page Controller="BannerAdsLocalController" id="page1">
  <!-- Begin Default Content REMOVE THIS -->
<h1>Search for Banner Ads Local</h1>
 
<apex:form id="searchForm"  >
<apex:outputLabel value="Category:" for="CategorySelected"/>

<apex:selectList id="Category" value="{!Category}" size="1" >
<apex:selectOptions value="{!Categories}"  />
</apex:selectList> 
&nbsp;&nbsp;&nbsp;

<apex:outputLabel value="Postcode:" for="postcode"/>
<input id="postcode" name="postcode" value="{!$CurrentPage.parameters.postcode}" size="15" maxlength="10" />
&nbsp;&nbsp;&nbsp;

<apex:outputLabel value="Start date:" for="startDate"/>
<input id="startDate" name="startDate" value="{!$CurrentPage.parameters.startDate}" size="7" maxlength="10" />(yyyy-mm-dd)
&nbsp;&nbsp;&nbsp;
<apex:outputLabel value="End date:" for="endDate"/>
<input id="endDate"   name="endDate"   value="{!$CurrentPage.parameters.endDate}" size="7"  maxlength="10" />(yyyy-mm-dd)
<input type="submit" name="search" value="Search" />
<br /><br />
</apex:form>

<apex:pageBlock title="Banner Ads Local Search Results"  rendered="{!NOT(ISNULL(Products))}"  >
<apex:pageBlockTable value="{!Products}" var="product">

<apex:column value="{!product.PricebookEntry.Name}"/>
<apex:column value="{!product.ListPrice}"/>

<apex:column headerValue="Opportunity Name" rendered="{!NOT(ISNULL(product))}" >
<apex:outputLink value="/{!product.Opportunity.id}">
{!product.Opportunity.Name}
</apex:outputLink>
</apex:column>
<apex:column value="{!product.Opportunity.StageName}"/>
<apex:column value="{!product.Opportunity.Campaign_Start_Date__c}"/>
<apex:column value="{!product.Opportunity.Campaign_End_Date__c}"/>


</apex:pageBlockTable>

</apex:pageBlock>

  <!-- End Default Content REMOVE THIS -->
</apex:page>

Here is my controller:
public class BannerAdsLocalController {

Transient List<OpportunityLineItem> Products;
Transient String Category  = null;
Transient String postcode  = null;
Transient Date   startDate = null;
Transient Date   endDate   = null;

Transient String s_start = null;
Transient String s_end   = null;

public List<SelectOption> getCategories()
{
    List<SelectOption> options = new List<SelectOption>();
   
    options.add(new SelectOption('','All categories'));

    Schema.DescribeFieldResult categoryField = Schema.sObjectType.Product2.fields.Categories__c;
    Schema.PicklistEntry [] values           = categoryField.getPickListValues();
   
    for(Schema.PicklistEntry val : values)
    {
      options.add(new SelectOption(val.getValue(), val.getLabel()));
    }
    return options;
}

public Date getStartDate()
{
    return startDate;
}

public Date getEndDate()
{
    return endDate;
}

public String getCategory()
{
    return Category;
}
public void setCategory(String Category) {
    this.Category = Category;
}


public List<OpportunityLineItem> getProducts()
{
  
   
    s_start  = ApexPages.currentPage().getParameters().get('startDate');
    s_end    = ApexPages.currentPage().getParameters().get('endDate');
    postcode = ApexPages.currentPage().getParameters().get('postcode');
   
    //dynamic SOQL, SOSL and dynamic DML are    currently in pilot, and not enabled for all organizations. If you need them
    //for your application and are interested in the pilot program, contact your salesforce.com representative.
    //so, we have to do the 6 combinnations:
    //Error: Compile Error: Dynamic Apex not allowed in this organization, so we have to do the following combinations:           
    //Products = Database.query(  conditions  + order_by );
   
    if (s_start != null && s_start<>'' && s_end != null && s_end <>'' && (Category=='' || Category == null) && (postcode ==null || postcode==''))
    {   
        //Date Range only:
        startDate = Date.valueOf(s_start);
        endDate   = Date.valueOf(s_end);

        Products = [SELECT  Opportunity.Id, Opportunity.Name,Opportunity.StageName,Opportunity.Payment_Stage__c,
                Opportunity.Amount,Opportunity.Campaign_Start_Date__c,  Opportunity.Campaign_End_Date__c,
                PricebookEntry.Name, PricebookEntry.ProductCode,PricebookEntry.Product2.Postcode__c,
                Quantity, TotalPrice, UnitPrice, ListPrice, Price_Ex_GST__c, Total_Ex_GST__c, ServiceDate,
                End_Date__c ,  Description 
                FROM OpportunityLineItem 
                WHERE     Opportunity.RecordTypeId= '012R00000008dGY'
                          AND 
                          (  
                            (Opportunity.Campaign_End_Date__c   >= :startDate and Opportunity.Campaign_End_Date__c   <= :endDate )    OR
                            (Opportunity.Campaign_Start_Date__c >= :startDate and Opportunity.Campaign_Start_Date__c <= :endDate )    OR
                            (Opportunity.Campaign_End_Date__c   >= :endDate   and Opportunity.Campaign_End_Date__c   <= :startDate )  OR
                            (Opportunity.Campaign_Start_Date__c >= :endDate   and Opportunity.Campaign_Start_Date__c <= :startDate )
                          )
               
                ORDER BY Opportunity.Campaign_End_Date__c,Opportunity.Name,ListPrice DESC 
                ];
    }
    else if ((s_start == null || s_start =='') && (s_end == null || s_end=='') && (Category !='' && Category != null) && (postcode == null || postcode == ''))
    {
        //only category selected:
   
        Products = [SELECT  Opportunity.Id, Opportunity.Name,Opportunity.StageName,Opportunity.Payment_Stage__c,
                Opportunity.Amount,Opportunity.Campaign_Start_Date__c,  Opportunity.Campaign_End_Date__c,
                PricebookEntry.Name, PricebookEntry.ProductCode,PricebookEntry.Product2.Postcode__c,
                Quantity, TotalPrice, UnitPrice, ListPrice, Price_Ex_GST__c, Total_Ex_GST__c, ServiceDate,
                End_Date__c ,  Description 
                FROM OpportunityLineItem 
                WHERE     Opportunity.RecordTypeId= '012R00000008dGY'
                          AND  PricebookEntry.Product2.Categories__c = :Category                          
                ORDER BY Opportunity.Campaign_End_Date__c,Opportunity.Name,ListPrice DESC 
                ];
    }
    else
    {
    ....
    }
    return Products;
}


}


Can someone give me some hints please?

Any feedback much appriciated!

Regards,

David


  • August 19, 2008
  • Like
  • 0
Hi,
 
I am new to Visualforce, this may be a stupid question. what we'd like to achive is to create a dynamic HTML table, this table has dynamic columns.
e.g.
1 The number of columns for this HTML table will be the number of VF users in our organization.
2.The title for each column will be the user's full name in our organization.
3. and the data for each row will contain some kind of data for all users in our organization.
 
I was wondering how to create this dynamic HTML table using VF.
 
Any ideas or help would be much appreciated!
 
Thanks in advance.
 
Best Regards,
 
David
  • August 01, 2008
  • Like
  • 0
HI, I am very new to VF and Apex Classes. 
I just created a VF page with a custom controller in Sandbox. Now I need to do unit test before deployment. I have no clue how to write the unit test:

What I built is a search page, user can type in search criteria and then click on search

Here is my Page:
<apex:page Controller="BannerAdsLocalController" id="page1">
  <!-- Begin Default Content REMOVE THIS -->
<h1>Search for Banner Ads Local</h1>
 
<apex:form id="searchForm"  >
<apex:outputLabel value="Category:" for="CategorySelected"/>

<apex:selectList id="Category" value="{!Category}" size="1" >
<apex:selectOptions value="{!Categories}"  />
</apex:selectList> 
&nbsp;&nbsp;&nbsp;

<apex:outputLabel value="Postcode:" for="postcode"/>
<input id="postcode" name="postcode" value="{!$CurrentPage.parameters.postcode}" size="15" maxlength="10" />
&nbsp;&nbsp;&nbsp;

<apex:outputLabel value="Start date:" for="startDate"/>
<input id="startDate" name="startDate" value="{!$CurrentPage.parameters.startDate}" size="7" maxlength="10" />(yyyy-mm-dd)
&nbsp;&nbsp;&nbsp;
<apex:outputLabel value="End date:" for="endDate"/>
<input id="endDate"   name="endDate"   value="{!$CurrentPage.parameters.endDate}" size="7"  maxlength="10" />(yyyy-mm-dd)
<input type="submit" name="search" value="Search" />
<br /><br />
</apex:form>

<apex:pageBlock title="Banner Ads Local Search Results"  rendered="{!NOT(ISNULL(Products))}"  >
<apex:pageBlockTable value="{!Products}" var="product">

<apex:column value="{!product.PricebookEntry.Name}"/>
<apex:column value="{!product.ListPrice}"/>

<apex:column headerValue="Opportunity Name" rendered="{!NOT(ISNULL(product))}" >
<apex:outputLink value="/{!product.Opportunity.id}">
{!product.Opportunity.Name}
</apex:outputLink>
</apex:column>
<apex:column value="{!product.Opportunity.StageName}"/>
<apex:column value="{!product.Opportunity.Campaign_Start_Date__c}"/>
<apex:column value="{!product.Opportunity.Campaign_End_Date__c}"/>


</apex:pageBlockTable>

</apex:pageBlock>

  <!-- End Default Content REMOVE THIS -->
</apex:page>

Here is my controller:
public class BannerAdsLocalController {

Transient List<OpportunityLineItem> Products;
Transient String Category  = null;
Transient String postcode  = null;
Transient Date   startDate = null;
Transient Date   endDate   = null;

Transient String s_start = null;
Transient String s_end   = null;

public List<SelectOption> getCategories()
{
    List<SelectOption> options = new List<SelectOption>();
   
    options.add(new SelectOption('','All categories'));

    Schema.DescribeFieldResult categoryField = Schema.sObjectType.Product2.fields.Categories__c;
    Schema.PicklistEntry [] values           = categoryField.getPickListValues();
   
    for(Schema.PicklistEntry val : values)
    {
      options.add(new SelectOption(val.getValue(), val.getLabel()));
    }
    return options;
}

public Date getStartDate()
{
    return startDate;
}

public Date getEndDate()
{
    return endDate;
}

public String getCategory()
{
    return Category;
}
public void setCategory(String Category) {
    this.Category = Category;
}


public List<OpportunityLineItem> getProducts()
{
  
   
    s_start  = ApexPages.currentPage().getParameters().get('startDate');
    s_end    = ApexPages.currentPage().getParameters().get('endDate');
    postcode = ApexPages.currentPage().getParameters().get('postcode');
   
    //dynamic SOQL, SOSL and dynamic DML are    currently in pilot, and not enabled for all organizations. If you need them
    //for your application and are interested in the pilot program, contact your salesforce.com representative.
    //so, we have to do the 6 combinnations:
    //Error: Compile Error: Dynamic Apex not allowed in this organization, so we have to do the following combinations:           
    //Products = Database.query(  conditions  + order_by );
   
    if (s_start != null && s_start<>'' && s_end != null && s_end <>'' && (Category=='' || Category == null) && (postcode ==null || postcode==''))
    {   
        //Date Range only:
        startDate = Date.valueOf(s_start);
        endDate   = Date.valueOf(s_end);

        Products = [SELECT  Opportunity.Id, Opportunity.Name,Opportunity.StageName,Opportunity.Payment_Stage__c,
                Opportunity.Amount,Opportunity.Campaign_Start_Date__c,  Opportunity.Campaign_End_Date__c,
                PricebookEntry.Name, PricebookEntry.ProductCode,PricebookEntry.Product2.Postcode__c,
                Quantity, TotalPrice, UnitPrice, ListPrice, Price_Ex_GST__c, Total_Ex_GST__c, ServiceDate,
                End_Date__c ,  Description 
                FROM OpportunityLineItem 
                WHERE     Opportunity.RecordTypeId= '012R00000008dGY'
                          AND 
                          (  
                            (Opportunity.Campaign_End_Date__c   >= :startDate and Opportunity.Campaign_End_Date__c   <= :endDate )    OR
                            (Opportunity.Campaign_Start_Date__c >= :startDate and Opportunity.Campaign_Start_Date__c <= :endDate )    OR
                            (Opportunity.Campaign_End_Date__c   >= :endDate   and Opportunity.Campaign_End_Date__c   <= :startDate )  OR
                            (Opportunity.Campaign_Start_Date__c >= :endDate   and Opportunity.Campaign_Start_Date__c <= :startDate )
                          )
               
                ORDER BY Opportunity.Campaign_End_Date__c,Opportunity.Name,ListPrice DESC 
                ];
    }
    else if ((s_start == null || s_start =='') && (s_end == null || s_end=='') && (Category !='' && Category != null) && (postcode == null || postcode == ''))
    {
        //only category selected:
   
        Products = [SELECT  Opportunity.Id, Opportunity.Name,Opportunity.StageName,Opportunity.Payment_Stage__c,
                Opportunity.Amount,Opportunity.Campaign_Start_Date__c,  Opportunity.Campaign_End_Date__c,
                PricebookEntry.Name, PricebookEntry.ProductCode,PricebookEntry.Product2.Postcode__c,
                Quantity, TotalPrice, UnitPrice, ListPrice, Price_Ex_GST__c, Total_Ex_GST__c, ServiceDate,
                End_Date__c ,  Description 
                FROM OpportunityLineItem 
                WHERE     Opportunity.RecordTypeId= '012R00000008dGY'
                          AND  PricebookEntry.Product2.Categories__c = :Category                          
                ORDER BY Opportunity.Campaign_End_Date__c,Opportunity.Name,ListPrice DESC 
                ];
    }
    else
    {
    ....
    }
    return Products;
}


}


Can someone give me some hints please?

Any feedback much appriciated!

Regards,

David


  • August 19, 2008
  • Like
  • 0
Hi,
 
I am new to Visualforce, this may be a stupid question. what we'd like to achive is to create a dynamic HTML table, this table has dynamic columns.
e.g.
1 The number of columns for this HTML table will be the number of VF users in our organization.
2.The title for each column will be the user's full name in our organization.
3. and the data for each row will contain some kind of data for all users in our organization.
 
I was wondering how to create this dynamic HTML table using VF.
 
Any ideas or help would be much appreciated!
 
Thanks in advance.
 
Best Regards,
 
David
  • August 01, 2008
  • Like
  • 0
The Email services API provides the BinaryAttachment and TextAttachment objects to represent attachments to emails.

If I send an email with an email attachment (Content-Type: message/rfc822, Content-Disposition: attachment), it doesn't end up in either collection - so it's not accessible from the Email services API.

Is there any thought to support email attachments?  Ideally they would be in a form easily transformable into a new Messaging.InboundEmail object.

thanks,
john

  • November 23, 2007
  • Like
  • 0

Hi,

How do we handle the attachments in inbound mail? I need to capture email attachment as attachment in Salesforce.  I had created Salesforce (case) records from the contents of email but struggling to handle attachment. Any detail update on this is highly appreciated.

How we can handle this through Apex EMAIL SERVICES
 
Thanks
Nazeer

Message Edited by Nazeer on 11-23-2007 07:35 AM

  • November 21, 2007
  • Like
  • 0
I am working on the Event example that comes with the Print Anything (V 8.1.11) AppExchange offering and can't get past the 1st query.  I seemed to have followed the customization instructions exactly and can't figure out what the hang up is.
 
I created the button, created a new package, added the queries, and created a new Event. When I execute the Print Invitation button the debug result 1 is:  retrieve single row - Event:Undefined. It seems as if it can't find the Event.
 
Any ideas on how to get past the 1st query?  Thanks!