-
ChatterFeed
-
1Best Answers
-
0Likes Received
-
0Likes Given
-
11Questions
-
12Replies
Editing visualforce PDF to resemble existing company Quote template
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
-
- Cheriah200
- March 25, 2009
- Like
- 1
- Continue reading or reply
Best way to get the Id of a new record back after insert/upsert operation
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?
-
- Ryanh
- April 06, 2009
- Like
- 0
- Continue reading or reply
Making an HTTP request AFTER DML operations (CalloutException)
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?
-
- Ryanh
- April 02, 2009
- Like
- 0
- Continue reading or reply
How do I remove a button from a related list on a VF page
-
- Ryanh
- April 02, 2009
- Like
- 0
- Continue reading or reply
IDE Question -- How do I filter out the meta data xml files from the file list?
-
- Ryanh
- March 26, 2009
- Like
- 0
- Continue reading or reply
Attempt to de-reference a null object
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?
-
- Ryanh
- March 19, 2009
- Like
- 0
- Continue reading or reply
Revenue schedule not created by default through Apex
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:
-
- Ryanh
- March 16, 2009
- Like
- 0
- Continue reading or reply
Something about object relationships I don't get (newbie)
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"
-
- Ryanh
- March 12, 2009
- Like
- 0
- Continue reading or reply
Revenue scheduling unit test not working
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;
}
}
}
}
-
- Ryanh
- March 11, 2009
- Like
- 0
- Continue reading or reply
Testing Best Practices -- Reusable code in unit tests?
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
-
- Ryanh
- February 27, 2009
- Like
- 0
- Continue reading or reply
Can't test product scheduling?
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:
- Account
- Opportunity (related to the account)
- Product2
- CanUseRevenueSchedule=true
- RevenueScheduleType='Repeat'
- NumberofRevenueInstallments=12
- RevenueInstallmentPeriod='Monthly'
- Pricebook2 (a SOQL query to get the Standard Price Book)
- PriceBookEntry
- Related to the price book above
- Related to the product above
- Unit price=0
- UseStandardPrice=false
- OpportunityLineItem
- Related to the opportunity above
- Related to the PB entry above
- Quantity=1
- UnitPrice=200
-
- Ryanh
- February 27, 2009
- Like
- 0
- Continue reading or reply
Valid Opportunity Related Lists
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.
-
- Ryanh
- February 26, 2009
- Like
- 0
- Continue reading or reply
signature capturing in visualforce page
- rao
- April 02, 2009
- Like
- 0
- Continue reading or reply
IDE Question -- How do I filter out the meta data xml files from the file list?
- Ryanh
- March 26, 2009
- Like
- 0
- Continue reading or reply
Why Can't I Create Custom Controller?
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
- myfootsmells
- March 25, 2009
- Like
- 0
- Continue reading or reply
Editing visualforce PDF to resemble existing company Quote template
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
- Cheriah200
- March 25, 2009
- Like
- 1
- Continue reading or reply
How to return to prior page?
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.
- Ken_Koellner
- March 25, 2009
- Like
- 0
- Continue reading or reply
Recursive Update issue
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
- gv
- March 17, 2009
- Like
- 0
- Continue reading or reply
Revenue scheduling unit test not working
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;
}
}
}
}
- Ryanh
- March 11, 2009
- Like
- 0
- Continue reading or reply
Testing Best Practices -- Reusable code in unit tests?
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
- Ryanh
- February 27, 2009
- Like
- 0
- Continue reading or reply
Valid Opportunity Related Lists
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.
- Ryanh
- February 26, 2009
- Like
- 0
- Continue reading or reply