• Ryanh
  • NEWBIE
  • 30 Points
  • Member since 2009

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 12
    Replies

Hi,

 

I've been advised this is the best place to post this...

 

I've installed Quote Line Items (Version 0.7) from Appexchange and want to edit the page "Quote PDF" so that it looks similar to our existing quote template as we're looking to run our quote process through Salesforce.com.  The application is great and I've been given the go ahead to roll it out to everyone as long as the quote PDF can look more like our original version.  This is where I'm falling down - I've managed to add our logo to the template instead of the standard Visualforce one but can't get my head around adding a table and some standard text to the template. I know it's only a simple template and if it was HTML I'd be able to do it but I just can't figure out Visualforce.

 

Can anybody help with this at all please?  E.g. does anyone have a standard table I can copy & paste and then edit?  If I identify which fields need to be included, could someone guide me through how to enter them in to the table?  Is there a way of adding a standard header & footer to the page?

 

Thanks,

Cherie

I've customized the standard controller save action with a controller extension. After saving the master record, I need to be able to create a couple new child records. In order to create the child records with a reference back to the master, I need the ID of the master after it was saved.

 

The only way I was able to figure out a way to do that was to parse the URL from the PageReference returned after the stdController.save() method completes:

 

view_io = stdController.save(); ... String ioId = view_io.getUrl().substring(1);

 

this is pretty lame though... Is there a better way?

 

 

  • April 06, 2009
  • Like
  • 0

In a custom save() method for a VisualForce page controller extension, I'm creating a number of records/objects, and then I need to make a simple GET request to an external site with the Id of one of the records I created.

 

I'm running into a CalloutException with the message, "Please commit or rollback before calling out".

 

The other solutions I've seen posted here (such as calling out first, then doing your DML stuff) won't work for me since I need to include the Id with the call.

 

How do I get by this?

  • April 02, 2009
  • Like
  • 0
I'm adding a related list to custom VF page, but I want to remove the "New xyz" button from the list. I removed the button from the list on the standard page layout, but that had no impact.
  • April 02, 2009
  • Like
  • 0
Anyone know how to filter out the meta data xml files from the file list? I see a "*-meta.xml" file for each tigger, class, page, etc I've imported to the IDE... kinda annoying.
  • March 26, 2009
  • Like
  • 0

I don't understand why I'm getting this error... I have the following code:

 

System.debug('BillingStreet = \'' + account.BillingStreet + '\'\n');

System.debug('BillingState = \'' + account.BillingState + '\'\n');

 

if (account.BillingStreet == '' || account.BillingStreet == null) ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR, 'The account must have a billing address.') );

 

If I remove the OR condition in the if statement, debug outputs the following:

BillingStreet = 'null'

BillingState = 'CA'

 

If I leave that in, I get the error: "Attempt to de-reference a null object"; the error refers to the "account.BillingStreet" test for null...

 

If I only test for null -- instead of empty string -- then I get the following error: 

 

Data Not Available
The data you were trying to access could not be found. It may be due to another user deleting the data or a system error. [...]

 

'account' is not null BillingState is getting outputted (sp?) just fine.

 

 

WTF?

 

Message Edited by Ryanh on 03-19-2009 02:04 PM
  • March 19, 2009
  • Like
  • 0

If you create a Product (Product2), enable scheduling and define a default revenue schedule, when you add that product to an Opportunity, a schedule will be created.

 

For instance, if my default revenue schedule is defined as:

  • Revenue schedule type = Repeat Amount for each installment
  • Revenue Installment Period = monthly
  • Number Of Revenue Installments = 12

And then I add this product to an opportunity with a quantity of 1 and a price of $500, I'll see 12 schedule entries (OpportunityLineItemSchedule records), $500 each, and occurring every month.

If I add this same product to an opportunity through Apex and specify quantity=1 and price=500, the product (OpportunityLineItem) will be added, but no schedule entries will be created.

 

Here's my code:

 

Product2 search_product = [select Id from Product2 where ProductCode='Budget_T1_LP_Call_Proxy']; Pricebook2 pricebook = [SELECT Id, Name FROM Pricebook2 WHERE isStandard=true AND isDeleted=false AND isActive=true]; PricebookEntry pbentry=null; try { pbentry = [select Id from PricebookEntry where Pricebook2Id=:pricebook.Id and Product2Id=:search_product.Id and isActive=true and UnitPrice=0 and UseStandardPrice=false]; } catch (System.Queryexception e) { pbentry = new PricebookEntry(Pricebook2Id=pricebook.Id,Product2Id=search_product.Id,isActive=true,UnitPrice=0,UseStandardPrice=false); insert pbentry; } OpportunityLineItem opp_product = new OpportunityLineItem(OpportunityId=io.Opportunity__c,PriceBookEntryId=pbentry.Id,Quantity=1, UnitPrice=io.monthly_budget__c, ServiceDate=io.Monthly_budget_bill_date__c ); insert opp_product;

 

My guess is that Salesforce wrote code to create the schedule outside of the standard controller and it is not executed when you simply add the product through Apex.

 

Thoughts? Can anyone confirm this?

 

 

For some background, see these posts:

  1. Revenue scheduling unit test not working
  2. Can't test product scheduling
  • March 16, 2009
  • Like
  • 0

I have a controller extension class for a VisualForce page using a custom object as the standard controller.

 

The custom object, an "Insertion Order" has a master-detail relationship to the Opportunity it belongs to. The constructor instantiates an object "io" with the "stdController.getRecord()" call.

 

In a method in the extension class (IOHelper) I'm trying to get the Account that the Opportunity belongs to, but I'm just not getting the relationships concept apparently.

 

Here are the results of a series of debug statements:

 

 

System.debug(io.Opportunity__c); // output=006R0000003JrLn (expected)System.debug(io.Opportunity__c.Name); // won't compile; "Invalid foreign key relationship"System.debug(io.Opportunity__r.Account); // nullSystem.debug(io.Opportunity__r.AccountId); // nullSystem.debug(io.Opportunity__r.Account.Id); // null

 

 what gives? what am I doing wrong?

 

I don't really understand where the "__r" syntax fits in, but it doesn't compile with "__c" 

  • March 12, 2009
  • Like
  • 0

I'm trying to test a trigger that sets a value in a custom field on the OpportunityLineItem object after it's inserted based on details in the OpportunityLineItemSchedule records added. The trigger's working fine, but for some reason, my unit test isn't.

 

The unit test code is below, but it's failing on the second assertion (at the very bottom). "Contract_duration__c" is set by the trigger to "schedule.size()" where schedule is:

 

List<OpportunityLineItemSchedule> schedule = [select ScheduleDate from OpportunityLineItemSchedule where OpportunityLineItemId = :LI.Id];

 

I expect that the number of OpportunityLineItemSchedule records will be 12 because that's what I've defined on the instantiated Product2 object (NumberofRevenueInstallments=12). But it's actually coming out with zero records. I'm sure the problem is with my assumptions -- any help?

 

Test Method

 

static testMethod void testScheduledProduct() {
Account account = new Account(name='Unit Test Account',BillingState='CA');
insert account;

Opportunity opportunity = new Opportunity(
AccountId=account.Id,
name='Unit Test Opportunity',
CloseDate=date.today(),
StageName='Decision Maker Interested'
);
insert opportunity;

Product2 product = new Product2(
Name='Unit Test Product',
isActive=true,
CanUseRevenueSchedule=true,
// default scheduling settings
RevenueScheduleType='Repeat',
NumberofRevenueInstallments=12,
RevenueInstallmentPeriod='Monthly'
);
insert product;

Pricebook2 pricebook = [SELECT Id, Name FROM Pricebook2 WHERE isStandard=true AND isDeleted=false AND isActive=true];

PricebookEntry pbentry = new PricebookEntry(
Pricebook2Id=pricebook.Id,
Product2Id=product.Id,
isActive=true,
UnitPrice=0,
UseStandardPrice=false
);
insert pbentry;

OpportunityLineItem opp_product = new OpportunityLineItem(
OpportunityId=opportunity.Id,
PriceBookEntryId=pbentry.Id,
Quantity=1,
UnitPrice=200
);
insert opp_product;

// Setup complete
// Test that the Monthly amount and Contract duration were set correctly
opp_product = [SELECT Monthly_amount__c, Contract_duration__c FROM OpportunityLineItem WHERE Id = :opp_product.Id];

System.assert(opp_product.Monthly_amount__c==200);
System.assert(opp_product.Contract_duration__c==12);
}

 

Trigger

 

trigger setMonthlyAmountAndDuration on OpportunityLineItem (after insert, after update) {
if(!SetMonthlyAmountHelper.hasAlreadySetMonthlyAmount()) {
for (OpportunityLineItem LI : trigger.new) {
PricebookEntry pbentry = [select Product2Id from PricebookEntry where Id = :LI.PriceBookEntryId];
Product2 prod = [select CanUseRevenueSchedule, NumberOfRevenueInstallments from Product2 where Id = :pbentry.Product2Id];

if (prod.CanUseRevenueSchedule==true && prod.NumberofRevenueInstallments>0) {
OpportunityLineItem opp_prod = [select Monthly_amount__c, Contract_duration__c from OpportunityLineItem where Id = :LI.Id];
List<OpportunityLineItemSchedule> schedule = [select ScheduleDate from OpportunityLineItemSchedule where OpportunityLineItemId = :LI.Id];

if (schedule.size()==0)
opp_prod.Monthly_amount__c = LI.UnitPrice;
else
opp_prod.Monthly_amount__c = LI.UnitPrice / schedule.size();

opp_prod.Contract_duration__c = schedule.size();

SetMonthlyAmountHelper.setAlreadySetMonthlyAmount();
Update opp_prod;
}
}
}
}

 

 

 

  • March 11, 2009
  • Like
  • 0

Given that unit test methods are required to be static and void, I find that I have a lot of duplicated code for the test setup. If I write 3 unit tests for one method because there are different branches in the logic of that method, I'm copying and pasting the data setup portion of the test case into each of the three unit tests.

 

There's gotta be a better way! Help? Ideas?

 

Thanks 

  • February 27, 2009
  • Like
  • 0

We've enabled product scheduling on opportunities and defined specific products to have a default scheduling/recurrance profile of monthly for 12 recurrances.

 

I've created a trigger that fires after the OpportunityLineItem object is inserted -- it updates the same OpportunityLineItem record to include the monthly unit price and the number of schedule entries. It works fine.

 

I'm now trying to create a test case for this trigger, but running into problems. My test sets up the following objects, in this order:

 

  1. Account
  2. Opportunity (related to the account)
  3. Product2
    1. CanUseRevenueSchedule=true
    2. RevenueScheduleType='Repeat'
    3. NumberofRevenueInstallments=12
    4. RevenueInstallmentPeriod='Monthly'
  4.  Pricebook2 (a SOQL query to get the Standard Price Book)
  5. PriceBookEntry 
    1. Related to the price book above
    2. Related to the product above
    1. Unit price=0
    2. UseStandardPrice=false
  6. OpportunityLineItem
    1. Related to the opportunity above
    2. Related to the PB entry above
    3. Quantity=1
    4. UnitPrice=200
In the SFDC interface, when you add the Opportunity Product (OpportunityLineItem) and specify the quantity and price, it immediately creates the product schedule and the trigger uses the total price / the number of recurrances to arrive at the unit price per month.
 
However, in the test case, when I insert the OpportunityLineItem record, I get a [Divide by 0] exception because (presumably) the schedule is not getting built automatically before the trigger fires, so the list I've built with the schedule entries returns 0 from the list.size() method.
 
 
I'm new to SFDC and test case writing in general so I fully acknowledge that there may be a flaw in how I've written this test. Whatever the case, if you can spot the problem, I'd appreciate it.
 
Thanks! 

 

  • February 27, 2009
  • Like
  • 0

I need to display the Opportunity Products related list on a VF page with a custom controller. I don't know the exact name of the list though, and I can't find a reference for each of the standard object's valid related lists. Here's the code I'm using on the page:

 

<apex:relatedList subject="{!opportunity}" list="OpportunityProducts" title="Products"/>

 

And I get an error saying:

'OpportunityProducts' is not a valid child relationship name for entity Opportunity

 

I've tried "Products", "OpportunityProducts", and "Opportunity Products". Again, if someone could point me to the list of all available related lists -- or how to find it through debugging -- I would appreciate it.

  • February 26, 2009
  • Like
  • 0
Can anybody please tell me wether we can capture signature in visualforce page.
  • April 02, 2009
  • Like
  • 0
Anyone know how to filter out the meta data xml files from the file list? I see a "*-meta.xml" file for each tigger, class, page, etc I've imported to the IDE... kinda annoying.
  • March 26, 2009
  • Like
  • 0

I know I'm missing something but why can't I create a custom controller?

 

<apex:page controller="MyController" > 
<apex:pageBlock title="Contacts">
</apex:pageBlock>
</apex:page>

 

In the tutorial is says if I put that code in a Page and hit save, I'll have a Controller option available but I don't.  I get an error message "Error: Apex class 'MyController' does not exist."  What am I missing here?

 

I'm on SalesForce Pro if that makes a difference.

 

Thanks

Hi,

 

I've been advised this is the best place to post this...

 

I've installed Quote Line Items (Version 0.7) from Appexchange and want to edit the page "Quote PDF" so that it looks similar to our existing quote template as we're looking to run our quote process through Salesforce.com.  The application is great and I've been given the go ahead to roll it out to everyone as long as the quote PDF can look more like our original version.  This is where I'm falling down - I've managed to add our logo to the template instead of the standard Visualforce one but can't get my head around adding a table and some standard text to the template. I know it's only a simple template and if it was HTML I'd be able to do it but I just can't figure out Visualforce.

 

Can anybody help with this at all please?  E.g. does anyone have a standard table I can copy & paste and then edit?  If I identify which fields need to be included, could someone guide me through how to enter them in to the table?  Is there a way of adding a standard header & footer to the page?

 

Thanks,

Cherie

If I want a method in Apex controller to return to the prior page, what should I return for the page reference?

 

I would assume I can return a URL with the id that was passed in but that would open a new instance of a page.  I'd rather just go back.

 

Hi All

 

I have a before update trigger on a object. I am getting a list of all records matching a particular id (trigger.old) and looping through the list .

 

The problem is while looping thorugh if a particualr check box is checked I want to uncheck it. So I do that add it to another list and do a update and run into the recursive update issue .

 

 I am stuck. This is the offending code in the class which is called by the before update trigger

 

 

public static void beforeUpdate(List<Contact__c> ContactList){ i Set<Id> accountIds = new Set<Id> (); for (Contact__c con: ContactList){ if (con.account__c!=null) accountIds.add(con. account__c); } List< Contact__c > updateContacts = new List< Contact__c >(); List< Contact__c > ExistingContactList = ([Select Id, e.Name,active__c from Contact__c e where e.account__c.Id in : accountIds order by name desc]); for(Contact__c contactcounter : ExistingContactList ){ if (contactcounter .active__c == true){ contactcounter .active__c = false; updateContacts.add(contactcounter ); } }//for loop //update updateContacts; }

 

 

 

 When I execute this I get the recursive error as I am callin the update updateocntacts inside a before update trigger. But I want to change the value of all contact records active value if its true to false . How to achieve that?

 

Thankss 


 

  • March 17, 2009
  • Like
  • 0

I'm trying to test a trigger that sets a value in a custom field on the OpportunityLineItem object after it's inserted based on details in the OpportunityLineItemSchedule records added. The trigger's working fine, but for some reason, my unit test isn't.

 

The unit test code is below, but it's failing on the second assertion (at the very bottom). "Contract_duration__c" is set by the trigger to "schedule.size()" where schedule is:

 

List<OpportunityLineItemSchedule> schedule = [select ScheduleDate from OpportunityLineItemSchedule where OpportunityLineItemId = :LI.Id];

 

I expect that the number of OpportunityLineItemSchedule records will be 12 because that's what I've defined on the instantiated Product2 object (NumberofRevenueInstallments=12). But it's actually coming out with zero records. I'm sure the problem is with my assumptions -- any help?

 

Test Method

 

static testMethod void testScheduledProduct() {
Account account = new Account(name='Unit Test Account',BillingState='CA');
insert account;

Opportunity opportunity = new Opportunity(
AccountId=account.Id,
name='Unit Test Opportunity',
CloseDate=date.today(),
StageName='Decision Maker Interested'
);
insert opportunity;

Product2 product = new Product2(
Name='Unit Test Product',
isActive=true,
CanUseRevenueSchedule=true,
// default scheduling settings
RevenueScheduleType='Repeat',
NumberofRevenueInstallments=12,
RevenueInstallmentPeriod='Monthly'
);
insert product;

Pricebook2 pricebook = [SELECT Id, Name FROM Pricebook2 WHERE isStandard=true AND isDeleted=false AND isActive=true];

PricebookEntry pbentry = new PricebookEntry(
Pricebook2Id=pricebook.Id,
Product2Id=product.Id,
isActive=true,
UnitPrice=0,
UseStandardPrice=false
);
insert pbentry;

OpportunityLineItem opp_product = new OpportunityLineItem(
OpportunityId=opportunity.Id,
PriceBookEntryId=pbentry.Id,
Quantity=1,
UnitPrice=200
);
insert opp_product;

// Setup complete
// Test that the Monthly amount and Contract duration were set correctly
opp_product = [SELECT Monthly_amount__c, Contract_duration__c FROM OpportunityLineItem WHERE Id = :opp_product.Id];

System.assert(opp_product.Monthly_amount__c==200);
System.assert(opp_product.Contract_duration__c==12);
}

 

Trigger

 

trigger setMonthlyAmountAndDuration on OpportunityLineItem (after insert, after update) {
if(!SetMonthlyAmountHelper.hasAlreadySetMonthlyAmount()) {
for (OpportunityLineItem LI : trigger.new) {
PricebookEntry pbentry = [select Product2Id from PricebookEntry where Id = :LI.PriceBookEntryId];
Product2 prod = [select CanUseRevenueSchedule, NumberOfRevenueInstallments from Product2 where Id = :pbentry.Product2Id];

if (prod.CanUseRevenueSchedule==true && prod.NumberofRevenueInstallments>0) {
OpportunityLineItem opp_prod = [select Monthly_amount__c, Contract_duration__c from OpportunityLineItem where Id = :LI.Id];
List<OpportunityLineItemSchedule> schedule = [select ScheduleDate from OpportunityLineItemSchedule where OpportunityLineItemId = :LI.Id];

if (schedule.size()==0)
opp_prod.Monthly_amount__c = LI.UnitPrice;
else
opp_prod.Monthly_amount__c = LI.UnitPrice / schedule.size();

opp_prod.Contract_duration__c = schedule.size();

SetMonthlyAmountHelper.setAlreadySetMonthlyAmount();
Update opp_prod;
}
}
}
}

 

 

 

  • March 11, 2009
  • Like
  • 0

Given that unit test methods are required to be static and void, I find that I have a lot of duplicated code for the test setup. If I write 3 unit tests for one method because there are different branches in the logic of that method, I'm copying and pasting the data setup portion of the test case into each of the three unit tests.

 

There's gotta be a better way! Help? Ideas?

 

Thanks 

  • February 27, 2009
  • Like
  • 0

I need to display the Opportunity Products related list on a VF page with a custom controller. I don't know the exact name of the list though, and I can't find a reference for each of the standard object's valid related lists. Here's the code I'm using on the page:

 

<apex:relatedList subject="{!opportunity}" list="OpportunityProducts" title="Products"/>

 

And I get an error saying:

'OpportunityProducts' is not a valid child relationship name for entity Opportunity

 

I've tried "Products", "OpportunityProducts", and "Opportunity Products". Again, if someone could point me to the list of all available related lists -- or how to find it through debugging -- I would appreciate it.

  • February 26, 2009
  • Like
  • 0