• Willem Mulder
  • NEWBIE
  • 25 Points
  • Member since 2015
  • Entrepreneur, Presenter, Developer
  • KT-Vision


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
Its early and my espresso has not yet kicked in, so forgive me this rudimentary question. What is the maximum number of records that a trigger will process at once? Assuming some sort of bulk update, what is the most I can expect to see in the Trigger.new list? Trying to code around some potential governor limit issues.

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

My email template (below) works fine when using the "preview" function to populate the Recipient (WhoID) and RelatedTo (WhatID)  - but when a workflow rule triggers the emai lto be sent, it comes back blank as if it's not resolving the who or what correctly. .

Code:
<messaging:emailTemplate recipientType="Contact"
    relatedToType="Account"
    subject="Your website Access"
    replyTo="anaddress@us.com" >

    <messaging:htmlEmailBody >        
    <html>
        <body>
        <p>Hello {!recipient.name}--</p>
        <p>Here is a list of the website access you users currently have for account {!relatedTo.name}:</p>
    <apex:datatable cellpadding="5" var="cts" value="{!relatedTo.Contacts}">
        <apex:column value="{!cts.Name}" headerValue="Name"/>
        <apex:column value="{!cts.Seat_Holder__c}" headerValue="Website Program Access"/>
        <apex:column value="{!cts.Email}" headerValue="Email" />
        <apex:column value="{!cts.Phone}" headerValue="Phone" />
    </apex:datatable>
        </body>
    </html>
    </messaging:htmlEmailBody> 
</messaging:emailTemplate>



I created a simple workflow rule that's called whenever a contact is edited. The workflow rule uses an email alert. The email Alert uses this template. I've checked to make sure the email template is for Contact objects, and that the Recipient is specified as Email Field: Email.

I must be missing something obvious..... any ideas?




Message Edited by icemft1976 on 10-24-2008 09:28 AM