You need to sign in to do that
Don't have an account?
ApexPages.currentPage().getParameters().get('id') Issue in Production (Email)
I've got a visualforce email template that has a vf component in it that runs off a class as it's controller. The class gets the current records ID via ApexPages.currentPage().getParameters().get('id'). The issue is that the email sends out perfect in Sandbox but sends as a NULL subject/body in production. When I change the WHERE clause in the queries that picks the ID to a real record ID instead of getting it from the page it works however. Is there a better way to get the ID, any idea why this isn't working? Also the component/class work if I call them from a button to a VF page on the record.
This email works in Sandbox - but not Production
public class TerritoryDailyReport{ //Territory record data public Territory__c t {get;set;} //public id tid {get;set;} //Lists public static list<territory_rank__c> bd; public static list<Contact> reps; public static list<Contact> repopps; public static list<Contact> repep; // method public TerritoryDailyReport(){ t = [SELECT id, name, best_mo_sales__c, best_mo__c, current_mo_sales__c, current_mo_pace__c FROM territory__c WHERE id =: ApexPages.currentPage().getParameters().get('id')]; bd = [SELECT id, name, firm__r.name, firm__c, best_mo__c, best_mo_sales__c, current_mo_sales__c, producers_this_mo__c, producers__c, territory_name__c, total_sales__c FROM territory_rank__c WHERE territory__c =: ApexPages.currentPage().getParameters().get('id') ORDER BY current_mo_sales__c desc]; reps = [SELECT id, name, account.name, opps_this_month__c, best_month__c, best_month_amount__c, current_month__c, next_trade_amount__c, next_trade_date__c, total_reit_sales__c, accountid, mailingstate FROM contact WHERE xterritory__c =: ApexPages.currentPage().getParameters().get('id') AND current_month__c != null AND current_month__c != 0 ORDER BY current_month__c desc]; repopps = [SELECT id, name, account.name, opps_this_month__c, best_month__c, best_month_amount__c, current_month__c, next_trade_amount__c, next_trade_date__c, total_reit_sales__c, accountid, mailingstate FROM contact WHERE xterritory__c =: ApexPages.currentPage().getParameters().get('id') AND (current_month__c = null OR current_month__c = 0) AND opps_this_month__c != null AND opps_this_month__c != 0 ORDER BY opps_this_month__c desc]; repep = [SELECT id, name, account.name, opps_this_month__c, best_month__c, best_month_amount__c, current_month__c, next_trade_amount__c, next_trade_date__c, total_reit_sales__c, accountid, mailingstate FROM contact WHERE xterritory__c =: ApexPages.currentPage().getParameters().get('id') AND (current_month__c = null OR current_month__c = 0) AND (opps_this_month__c = null OR opps_this_month__c = 0) AND next_trade_amount__c != null AND next_trade_amount__c != 0 AND (next_trade_date__c = THIS_MONTH OR next_trade_date__c = NEXT_n_DAYS:15) AND total_reit_sales__c > 0 ORDER BY next_trade_date__c asc]; } public static List<territory_rank__c> getbd() { return bd; } public static List<contact> getreps() { return reps; } public static List<contact> getrepopps() { return repopps; } public static List<contact> getrepep() { return repep; } }
Ideally you should be using attributes to pass the values
have a look here http://www.infallibletechie.com/2013/05/visualforce-email-template-with-custom.html
All Answers
your current page may not have id as parameter...
ApexPages.currentPage().getParameters().get('id') this statements fecthes id from URl, just check in the current context URL if you have id in it. if there isnt an id, then it will not return any value.... *****it depends on where are you calling the controller....
There is an ID in the url, I don't understand why this works in sandbox and not production?
Ideally you should be using attributes to pass the values
have a look here http://www.infallibletechie.com/2013/05/visualforce-email-template-with-custom.html
Thanks Avidev, that blog was a great help. But I'm still wondering why getting the id from the url works in sandbox but not in production?