• mike83
  • NEWBIE
  • 0 Points
  • Member since 2008

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

Ok So I have this trigger on the Opportunity Object

 

trigger OppertunityUpdate on Opportunity (after insert, after update) {

public void UpdateOpportunities(ID opId) {

Opportunity o = [Select o.Id, o.Total_Freight__c, o.Total_Sales_Tax__c, o.Total_Installation__c,

o.Amount, o.Adjustment5__c, o.Adjustment4__c, o.Adjustment3__c,

o.Adjustment2__c, o.Adjustment1__c, o.CanRunTrigger__c

From Opportunity o where o.Id = :opId];

List<PricebookEntry> pbes = [Select p.Product2Id, p.Name, p.Id

From PricebookEntry p

Where p.Product2.name

in ('SalesTax','Freight','Discount1','Discount2','Discount3','Discount4','Discount5','Installation')

order by p.Product2.name ]; List<OpportunityLineItem> oli = [Select o.Id, o.OpportunityId From OpportunityLineItem o

where o.PricebookEntry.id in :pbes

and o.OpportunityId = :o.Id order by o.PricebookEntry.Product2.name];

System.Debug('OliCount: ' + oli.size());

Decimal oliCount = [Select count()

From OpportunityLineItem o

where o.PricebookEntry.id not in :pbes

and o.OpportunityId = :o.Id];

System.Debug('TotalOliSize: ' + oliCount +', o:' + o.id);

if(oliCount < 1) return; if(oli.size() <> 8)

{

System.Debug('Creating new olis');

//Delete oli if size <8 and > 0

if(oli.size() > 0)

delete oli;

oli = new List<OpportunityLineItem>();

//Adding discount1

oli.add( new OpportunityLineItem(Quantity = 1,

OpportunityId = o.Id, TotalPrice = o.Adjustment1__c == null ? 0: o.Adjustment1__c,

PriceBookEntryId = pbes[0].id, order__c = 10001));

//Adding discount2

oli.add( new OpportunityLineItem(Quantity = 1,

OpportunityId = o.Id, TotalPrice = o.Adjustment2__c == null ? 0: o.Adjustment2__c,

PriceBookEntryId = pbes[1].id, order__c = 10002));

//Adding discount3

oli.add( new OpportunityLineItem(Quantity = 1,

OpportunityId = o.Id, TotalPrice = o.Adjustment3__c == null ? 0: o.Adjustment3__c,

PriceBookEntryId = pbes[2].id, order__c = 10003));

//Adding discount4

oli.add( new OpportunityLineItem(Quantity = 1,

OpportunityId = o.Id, TotalPrice = o.Adjustment4__c == null ? 0: o.Adjustment4__c,

PriceBookEntryId = pbes[3].id, order__c = 10004));

//Adding discount5

oli.add( new OpportunityLineItem(Quantity = 1,

OpportunityId = o.Id, TotalPrice = o.Adjustment5__c == null ? 0: o.Adjustment5__c,

PriceBookEntryId = pbes[4].id, order__c = 10005));

//Adding Installation

oli.add( new OpportunityLineItem(Quantity = 1, OpportunityId = o.Id,

TotalPrice = o.Total_Installation__c == null ? 0: o.Total_Installation__c,

PriceBookEntryId = pbes[7].id, order__c = 10006));

//Adding freight

oli.add( new OpportunityLineItem(OpportunityId = o.Id,

Quantity = 1, TotalPrice = o.Total_Freight__c == null ? 0 : o.Total_Freight__c,

PriceBookEntryId = pbes[5].Id, order__c = 10007));

//adding SalesTax

oli.add( new OpportunityLineItem(Quantity = 1, OpportunityId = o.Id,

TotalPrice = o.Total_Sales_Tax__c == null ? 0: o.Total_Sales_Tax__c,

PriceBookEntryId = pbes[6].id, order__c = 10008));

upsert oli;

return;

}

System.Debug('Updating olis');

oli[0].TotalPrice = o.Adjustment1__c == null ? 0: o.Adjustment1__c;

oli[1].TotalPrice = o.Adjustment2__c == null ? 0: o.Adjustment2__c;

oli[2].TotalPrice = o.Adjustment3__c == null ? 0: o.Adjustment3__c;

oli[3].TotalPrice = o.Adjustment4__c == null ? 0: o.Adjustment4__c;

oli[4].TotalPrice = o.Adjustment5__c == null ? 0: o.Adjustment5__c;

oli[5].TotalPrice = o.Total_Installation__c == null ? 0: o.Total_Installation__c;

oli[6].TotalPrice = o.Total_Freight__c == null ? 0 : o.Total_Freight__c;

oli[7].TotalPrice = o.Total_Sales_Tax__c == null ? 0: o.Total_Sales_Tax__c;

Decimal counter = 1;

for(OpportunityLineItem ol: oli)

{

ol.order__c = 10000 + counter;

counter ++;

}

update oli;

}

}

 


 

 

 

 

Heres my test case in a seperate class

@isTest

private class TestOpportunityTriggers {

public static testMethod void testOppTrigger(){

Opportunity z = new Opportunity( name='Test',StageName='Closed Won',

CloseDate=Date.valueof('2008-05-01'), Amount=1.25, Adjustment5__c=1.25,

Adjustment4__c=1.25, Adjustment3__c=7.25, Adjustment2__c=0, Adjustment1__c=3,

CanRunTrigger__c=true);

insert z;

update z;

}

}

 


 

 

 

But my Force.com IDE keeps saying 0% of my trigger is covered and I need atleast 1% but when I run in the the browser it says it has 100% coverage.

 

What am i missing? Please any help would be great

Message Edited by mike83 on 09-18-2009 09:26 AM
Message Edited by mike83 on 09-18-2009 09:32 AM
  • September 18, 2009
  • Like
  • 0

Ok I have a big nasty controller. At the top I have all these private variables I use Like:

public class pageController {      
private String secondaryLink =''; 

Then I have a get method

 

public String  getRequiredProducts() {
 secondaryLink =''; 
lib = [Select Link__C, Sales_Library_Link_2__c, Sales__c, Thumbnail__c, Headline__c, Teaser_Text__c From Sales_Library__c Where Required__c = true AND Sales_Library_Category__c = 'Product Information'];
if(lib.Sales__c!=null && lib.Sales_Library_Link_2__c!=null )  { 
 secondaryLink=lib.Sales_Library_Link_2__c;  
}		

 

My problem is I have code coverage on the get require products method but its complaing about not testing the variable secondaryLink... how do I test a private variable in a test class?

 

Heres what I have For the test class

 

 public static testMethod void PageTester()    
{        
string secondaryLink ='';        
string LiveID='00530000001f0fkAAA'; // I know this needs to be a query but dont care right now.       
PageReference pageRef2 = Page.ICHomepage;        
Test.setCurrentPageReference(pageRef2);        
ApexPages.currentPage().getParameters().put('uid', LiveID);        
PageController controller  = new PageController();        
controller.getC();        
controller.getRequiredProducts();         

} 

 So why does it complain about that variable not being covered?  And how do i cover it?

 

Message Edited by mike83 on 07-10-2009 11:26 AM
Message Edited by mike83 on 07-10-2009 11:27 AM

Ok So i have this big nasty controller and I am hitting 70% on my code coverage. There are no setters only getters. Which I have to do because sites doesnt let you use a standard controller. heres one of the pieces its complaining about.

 

public class repPageController { 

 String prods='';

public String getRequiredProducts()

{prods= '';

lib = [Select Link__C, Sales__c, Thumbnail__c, Headline__c, Teaser_Text__c From Sales_Library__c

Where Required__c = true AND Sales_Library_Category__c = 'Product Information'];

prods='<div class="floatLeft" style="width:70%"><p><h3><a href="'+lib.Link__c +'" target="_blank">'

+lib.Headline__c+'</a></h3><br/>'+lib.Teaser_Text__c+'&nbsp;&nbsp;<a href="'+lib.Link__c

+'" target="_blank">More...</a>'+secondaryLink+' </p></div><div class="floatRight" style="width:28%">'

+imgLink+'</div><div class"clear"></div>';

return prods; 

} 

 

 

So heres my test statement.

 

public class TestRepPageControllers {

  public static testMethod void RepPageTester()

{

  string LiveID='00530000001f0fkAAA';

PageReference pageRef2 = Page.ICHomepage;

Test.setCurrentPageReference(pageRef2);

ApexPages.currentPage().getParameters().put('uid', LiveID);

RepPageController controller = new RepPageController();

controller.getRequiredProducts();

 

} 

 

Best I can tell its saying that I dont have coverage on the Lib variable But I am not sure how else to any help would be great

 

Message Edited by mike83 on 05-11-2009 03:14 PM

I am having trouble accessing the business hours object from a custom object.

 

I have a custom object with a look up to the business hours object and I am trying to pull in the monday start times and end times and it keeps giving me an error  

 

{!Rep_Page__c.Business_Hours__r.MondayStartTime} 

 

The error says "Unsupported type shared.xml.soap.Time encountered."

 

 

What does the error mean and what am I doing wrong here? 

 

  • January 29, 2009
  • Like
  • 0

So I have all these sales people images that they would like to have displayed on the sales page relative to the users alias. So I name all the images  the same as the users alias and load them up in the static resources. I just want to call them.  I am imagingin something liek this but I am not sure how to dynaically populate the name of the resource based on the users alias 

So heres a static example  where "initals" is the users alias name.

 

 <img id="repImage" src="{!$Resource.img_initials}" alt="{!Rep_Page__c.User__r.Name}" />

 

 

What I'd like to do is something like this. 

<img id="repImage" src="{!$Resource.img_{!Rep_Page__c.User__r.Alias}}" alt="{!Rep_Page__c.User__r.Name}" /> 

 

I am open to any other options ... ideas? 

  • January 29, 2009
  • Like
  • 0
Ok so I am totally new to this and need some help.  I have an APEX page with that uses a custom Object and a standard Controller. Like this:
<apex:page standardController="Rep_Page__c" showheader="false">
I get a field from that object like this
<p>{!Rep_Page__c.Welcome_Message__c}</p>

Rep_Page_c has a look up field: {!Rep_Page__c.Sales_Library_Item_1__c}
this does a lookup on another custom object named sales_library which is basically a listing
of articles with fields for headlines teasers content and other stuff I want to pull that
data into the page as well through that lookup. Do I need to build a custom class for that?

Basically I dont know how to call the data from that object onto the same page where a standard
controler is delared for another object. It seems like there should be an easy way to do this
since the two objects are related via that lookup but I dont know what that is. Any help would
be greatly appreciated even just a kick in the right direction.

  • December 17, 2008
  • Like
  • 0

Ok So I have this trigger on the Opportunity Object

 

trigger OppertunityUpdate on Opportunity (after insert, after update) {

public void UpdateOpportunities(ID opId) {

Opportunity o = [Select o.Id, o.Total_Freight__c, o.Total_Sales_Tax__c, o.Total_Installation__c,

o.Amount, o.Adjustment5__c, o.Adjustment4__c, o.Adjustment3__c,

o.Adjustment2__c, o.Adjustment1__c, o.CanRunTrigger__c

From Opportunity o where o.Id = :opId];

List<PricebookEntry> pbes = [Select p.Product2Id, p.Name, p.Id

From PricebookEntry p

Where p.Product2.name

in ('SalesTax','Freight','Discount1','Discount2','Discount3','Discount4','Discount5','Installation')

order by p.Product2.name ]; List<OpportunityLineItem> oli = [Select o.Id, o.OpportunityId From OpportunityLineItem o

where o.PricebookEntry.id in :pbes

and o.OpportunityId = :o.Id order by o.PricebookEntry.Product2.name];

System.Debug('OliCount: ' + oli.size());

Decimal oliCount = [Select count()

From OpportunityLineItem o

where o.PricebookEntry.id not in :pbes

and o.OpportunityId = :o.Id];

System.Debug('TotalOliSize: ' + oliCount +', o:' + o.id);

if(oliCount < 1) return; if(oli.size() <> 8)

{

System.Debug('Creating new olis');

//Delete oli if size <8 and > 0

if(oli.size() > 0)

delete oli;

oli = new List<OpportunityLineItem>();

//Adding discount1

oli.add( new OpportunityLineItem(Quantity = 1,

OpportunityId = o.Id, TotalPrice = o.Adjustment1__c == null ? 0: o.Adjustment1__c,

PriceBookEntryId = pbes[0].id, order__c = 10001));

//Adding discount2

oli.add( new OpportunityLineItem(Quantity = 1,

OpportunityId = o.Id, TotalPrice = o.Adjustment2__c == null ? 0: o.Adjustment2__c,

PriceBookEntryId = pbes[1].id, order__c = 10002));

//Adding discount3

oli.add( new OpportunityLineItem(Quantity = 1,

OpportunityId = o.Id, TotalPrice = o.Adjustment3__c == null ? 0: o.Adjustment3__c,

PriceBookEntryId = pbes[2].id, order__c = 10003));

//Adding discount4

oli.add( new OpportunityLineItem(Quantity = 1,

OpportunityId = o.Id, TotalPrice = o.Adjustment4__c == null ? 0: o.Adjustment4__c,

PriceBookEntryId = pbes[3].id, order__c = 10004));

//Adding discount5

oli.add( new OpportunityLineItem(Quantity = 1,

OpportunityId = o.Id, TotalPrice = o.Adjustment5__c == null ? 0: o.Adjustment5__c,

PriceBookEntryId = pbes[4].id, order__c = 10005));

//Adding Installation

oli.add( new OpportunityLineItem(Quantity = 1, OpportunityId = o.Id,

TotalPrice = o.Total_Installation__c == null ? 0: o.Total_Installation__c,

PriceBookEntryId = pbes[7].id, order__c = 10006));

//Adding freight

oli.add( new OpportunityLineItem(OpportunityId = o.Id,

Quantity = 1, TotalPrice = o.Total_Freight__c == null ? 0 : o.Total_Freight__c,

PriceBookEntryId = pbes[5].Id, order__c = 10007));

//adding SalesTax

oli.add( new OpportunityLineItem(Quantity = 1, OpportunityId = o.Id,

TotalPrice = o.Total_Sales_Tax__c == null ? 0: o.Total_Sales_Tax__c,

PriceBookEntryId = pbes[6].id, order__c = 10008));

upsert oli;

return;

}

System.Debug('Updating olis');

oli[0].TotalPrice = o.Adjustment1__c == null ? 0: o.Adjustment1__c;

oli[1].TotalPrice = o.Adjustment2__c == null ? 0: o.Adjustment2__c;

oli[2].TotalPrice = o.Adjustment3__c == null ? 0: o.Adjustment3__c;

oli[3].TotalPrice = o.Adjustment4__c == null ? 0: o.Adjustment4__c;

oli[4].TotalPrice = o.Adjustment5__c == null ? 0: o.Adjustment5__c;

oli[5].TotalPrice = o.Total_Installation__c == null ? 0: o.Total_Installation__c;

oli[6].TotalPrice = o.Total_Freight__c == null ? 0 : o.Total_Freight__c;

oli[7].TotalPrice = o.Total_Sales_Tax__c == null ? 0: o.Total_Sales_Tax__c;

Decimal counter = 1;

for(OpportunityLineItem ol: oli)

{

ol.order__c = 10000 + counter;

counter ++;

}

update oli;

}

}

 


 

 

 

 

Heres my test case in a seperate class

@isTest

private class TestOpportunityTriggers {

public static testMethod void testOppTrigger(){

Opportunity z = new Opportunity( name='Test',StageName='Closed Won',

CloseDate=Date.valueof('2008-05-01'), Amount=1.25, Adjustment5__c=1.25,

Adjustment4__c=1.25, Adjustment3__c=7.25, Adjustment2__c=0, Adjustment1__c=3,

CanRunTrigger__c=true);

insert z;

update z;

}

}

 


 

 

 

But my Force.com IDE keeps saying 0% of my trigger is covered and I need atleast 1% but when I run in the the browser it says it has 100% coverage.

 

What am i missing? Please any help would be great

Message Edited by mike83 on 09-18-2009 09:26 AM
Message Edited by mike83 on 09-18-2009 09:32 AM
  • September 18, 2009
  • Like
  • 0

Ok I have a big nasty controller. At the top I have all these private variables I use Like:

public class pageController {      
private String secondaryLink =''; 

Then I have a get method

 

public String  getRequiredProducts() {
 secondaryLink =''; 
lib = [Select Link__C, Sales_Library_Link_2__c, Sales__c, Thumbnail__c, Headline__c, Teaser_Text__c From Sales_Library__c Where Required__c = true AND Sales_Library_Category__c = 'Product Information'];
if(lib.Sales__c!=null && lib.Sales_Library_Link_2__c!=null )  { 
 secondaryLink=lib.Sales_Library_Link_2__c;  
}		

 

My problem is I have code coverage on the get require products method but its complaing about not testing the variable secondaryLink... how do I test a private variable in a test class?

 

Heres what I have For the test class

 

 public static testMethod void PageTester()    
{        
string secondaryLink ='';        
string LiveID='00530000001f0fkAAA'; // I know this needs to be a query but dont care right now.       
PageReference pageRef2 = Page.ICHomepage;        
Test.setCurrentPageReference(pageRef2);        
ApexPages.currentPage().getParameters().put('uid', LiveID);        
PageController controller  = new PageController();        
controller.getC();        
controller.getRequiredProducts();         

} 

 So why does it complain about that variable not being covered?  And how do i cover it?

 

Message Edited by mike83 on 07-10-2009 11:26 AM
Message Edited by mike83 on 07-10-2009 11:27 AM

Ok So i have this big nasty controller and I am hitting 70% on my code coverage. There are no setters only getters. Which I have to do because sites doesnt let you use a standard controller. heres one of the pieces its complaining about.

 

public class repPageController { 

 String prods='';

public String getRequiredProducts()

{prods= '';

lib = [Select Link__C, Sales__c, Thumbnail__c, Headline__c, Teaser_Text__c From Sales_Library__c

Where Required__c = true AND Sales_Library_Category__c = 'Product Information'];

prods='<div class="floatLeft" style="width:70%"><p><h3><a href="'+lib.Link__c +'" target="_blank">'

+lib.Headline__c+'</a></h3><br/>'+lib.Teaser_Text__c+'&nbsp;&nbsp;<a href="'+lib.Link__c

+'" target="_blank">More...</a>'+secondaryLink+' </p></div><div class="floatRight" style="width:28%">'

+imgLink+'</div><div class"clear"></div>';

return prods; 

} 

 

 

So heres my test statement.

 

public class TestRepPageControllers {

  public static testMethod void RepPageTester()

{

  string LiveID='00530000001f0fkAAA';

PageReference pageRef2 = Page.ICHomepage;

Test.setCurrentPageReference(pageRef2);

ApexPages.currentPage().getParameters().put('uid', LiveID);

RepPageController controller = new RepPageController();

controller.getRequiredProducts();

 

} 

 

Best I can tell its saying that I dont have coverage on the Lib variable But I am not sure how else to any help would be great

 

Message Edited by mike83 on 05-11-2009 03:14 PM

I am having trouble accessing the business hours object from a custom object.

 

I have a custom object with a look up to the business hours object and I am trying to pull in the monday start times and end times and it keeps giving me an error  

 

{!Rep_Page__c.Business_Hours__r.MondayStartTime} 

 

The error says "Unsupported type shared.xml.soap.Time encountered."

 

 

What does the error mean and what am I doing wrong here? 

 

  • January 29, 2009
  • Like
  • 0

So I have all these sales people images that they would like to have displayed on the sales page relative to the users alias. So I name all the images  the same as the users alias and load them up in the static resources. I just want to call them.  I am imagingin something liek this but I am not sure how to dynaically populate the name of the resource based on the users alias 

So heres a static example  where "initals" is the users alias name.

 

 <img id="repImage" src="{!$Resource.img_initials}" alt="{!Rep_Page__c.User__r.Name}" />

 

 

What I'd like to do is something like this. 

<img id="repImage" src="{!$Resource.img_{!Rep_Page__c.User__r.Alias}}" alt="{!Rep_Page__c.User__r.Name}" /> 

 

I am open to any other options ... ideas? 

  • January 29, 2009
  • Like
  • 0