+ Start a Discussion
arasuarasu 

Why is my sendEmail with visualforce content sending a blank page when it is invoked from a class?

Hi,
 
When I invoke methodA from custom buttons and links as javascript at the object level, it correctly sends out email with the content from the referenced visualforce page(/apex/FixtureOrderInfoTempl). But when the same method is invoked from another Apex Class, it sends an empty content. I tried using try-catch, but there is no error.
 
   apexmethodA(){
               pageRef = new PageReference( '/apex/FixtureOrderInfoTempl' +'?id=' + pfixorderno );
     pageBody = pageRef.getContent().toString();
    //Set content to email body and sent email
   }
 
This is the difference that I see in the debug logs. The name of the visualforce page is FixtureOrderTempl
1. The debug log generated when the invokation is successful, when it is invoked directly from page layout:
Code:
<script  src="/js/ClientHash.js" type="text/javascript"></script><script  type="text/javascript">var hvch = ClientHash.prototype.needsClientHash('sid_Client', '0000000nHi300000005PpU', '65.208.210.99', '/servlet/servlet.ClientHashValidator—ResponseRequestedURL=%2Fapex%2FFixtureOrderTempl%3Fid%3Da0RR00000008eWc%26inline%3D1%26core.apexpages.devmode.url%3D1');
</script></head><body onLoad="if (this.bodyOnLoad) bodyOnLoad();" onBeforeUnload="if (this.bodyOnBeforeUnload) bodyOnBeforeUnload();" onUnload="if (this.bodyOnUnload) bodyOnUnload();" onFocus="if (this.bodyOnFocus) bodyOnFocus();" class="accountTab "><iframe title="blank - ignore" name="div_submit" id="div_submit" src="/s.gif" style="display:none;visibility:hidden;width:0px;height:0px" frameborder="0"></iframe>

 

2. The debug log from the failed invokation that generates a blank email body when the same method is invoked from an apex class:
Code:
<script>
if (window.location.replace){ 
window.location.replace('https://cs2.salesforce.com/—ec=302&startURL=%2Fapex%2FFixtureOrderTempl%3Finline%3D1%26core.apexpages.devmode.url%3D1%26id%3Da0RR00000008eWc');
} else {;
window.location.href ='https://cs2.salesforce.com/–ec=302&startURL=%2Fapex%2FFixtureOrderTempl%3Finline%3D1%26core.apexpages.devmode.url%3D1%26id%3Da0RR00000008eWc';
} 
</script>

 
      
 
Appreciate if anyone could highlight whats going strange here. Do we always need to call the above apexmethodA from a page-level and not from within a class?
Thanks


Message Edited by arasu on 08-06-2008 05:00 PM

Message Edited by arasu on 08-07-2008 06:09 PM