• cedg
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 42
    Replies

Hi,

 

I want to generate a PDF and attach it to an email, based on the Opportunity object. So far, it shouldn't be difficult...

 

So i've a VF page with the content , rendered as pdf and its controller. If i launch the page in a browser, it's ok.

 

I've another class (containing the method launched by an action button on the Opportunity layout) to get the content of the PDF and attach it to the email.

Before attaching it, i want to check if there is no error in the PDF, so I call the body.toString() method to do that  (body is the blob). 

Then i get the error "System.StringException: BLOB is not a valid UTF-8 string", while  I used this method many times in the past without problem for other PDF generation.

 

        PageReference pdf;
        pdf = Page.QuoteTemplate;
        pdf.getParameters().put('id',opp.Id);
Blob body; try { body = pdf.getContent(); } catch (VisualforceException e) { body = Blob.valueOf('Some Text ... ERROR_COMPANYADDRESSNOTFOUND ... ERROR_COMPANYNOTFOUND'); } if (body.toString().contains('ERROR_')){ return 'warning'; }

 

I searched for information, i find that examples of this error when trying to read the content of a document which is not in UTF8, but in this case i'm starting from a VF page and when i try directly to look at the page, it's ok.

 

One solution often mentionned is to use the  EncodingUtil.base64Encode(body);

but then I cannot compare the content to find the "ERROR_..." (i think)

 

 

Anybody has an idea ?

 

Many thanks

Ced

 

  • September 13, 2013
  • Like
  • 0

Hi,

I have a order process for which I want to send the email via EmailVision.

 

What i want is:

- to keep the templates in Saleforce and send all the HTML content to EmailVision. that allows us to manage the whole thing in Salesforce and to be able to easily preview the result.

- to save the content of the sent email to the partner/customer as an activity (as it's possible with the messaging object)

- to fire the emails from triggers based on some status changes (a lot of template + multi language, so it's easier and not limited as for the # email alerts)

 

 

My problems are :)

- is it possible to use the messaging object to merge the fields between the template and the related record, without sending the mail ?

- i could use a visualforce page instead of a template to get the content (pagereference.getContent()) but i think it's not possible to use this method in a trigger.

- I could let the templates in EmailVision, but in that scenario how to save the content of the sent email as an activity ?

 

 

Has anybody experience with such an integration ? best practices ?

 

Thanks for your help.

Ced

  • March 13, 2013
  • Like
  • 0

Hello,

 

I've 2 applications/pages (LSC and LSS)  with the same controller, making the dispatching between both apps and an "action" calling a method "redirecOrLoad".

 

Both pages are defined like this:

<apex:page controller="HR01_HR08_Disp" action="{!redirectOrLoad}" sidebar="false" showheader="false" standardStylesheets="false" id="pagelss">

 

The dispatching is based on some properties of the user but can be forced as well to one or another app.

 

So the user can go to the page LSC and have the right to go to this page => load or he has to use the LSS and is redirected to it. Opposite as well => 4 possibilities.

 

For some reason, one of the 4 possibilities doesn't work properly. If i go to the page LSC while forcing the app LSS, it should then redirect it to the page LSS but doesn't do it (internal error, ...).

If i go the page LSS while forcing the app LSS, it's working fine, so it's not the page itself that causes the problem, it's the redirect.

 

Apparently it's the <apex:actionFunction ..> in the page LSS that are the cause of the problem. If i remove them the redirect works properly.

Any idea why the presence of actionFunction could provoke an error in the redirect of the page ?

Page LSS:

 

<apex:page controller="HR01_HR08_Disp" action="{!redirectOrLoad}" sidebar="false" showheader="false" standardStylesheets="false" id="pagelss">
<head>
    <apex:includeScript value="{!$Resource.JQuery}" />
    <apex:includeScript value="{!URLFOR($Resource.Bootstrap, 'bootstrap/js/bootstrap.min.js')}" />
    <apex:stylesheet value="{!URLFOR($Resource.Bootstrap, 'bootstrap/css/bootstrap.min.css')}" />
    <apex:stylesheet value="{!URLFOR($Resource.HorizonLayout, '_css/generic.css')}" />
	...
</head>
<body>
    
    <apex:messages />
    ...

        <div class="content">
            <div class="main">
                <apex:form id="formlss">
                <input type="hidden" id="selCombo" value="" />
                <input type="hidden" id="selCol" value="" />
                
                <apex:actionFunction action="{!hr08.changeLangEn}" name="changeLangEn"  ></apex:actionFunction>
                <apex:actionFunction action="{!hr08.changeLangFr}" name="changeLangFr"  ></apex:actionFunction>
                <apex:actionFunction action="{!hr08.changeLangNl}" name="changeLangNl"  ></apex:actionFunction>
                
                <apex:actionFunction action="{!hr08.saveCombo}" name="submitInput" reRender="panelConfirmation,errorMsg">
                    <apex:param name="firstParam" assignTo="{!hr08.chosenCombo}" value="" />
                </apex:actionFunction>
                
                <div>
                    <div class="title FL ">
                        <h2><span id="lang0">Let's Start</span></h2>
                    </div>
                    <div class="lang FR" id="boxlang">
                        <span id="lanEN" class="label actionElement" onclick="changeLangEn();">EN</span>
                        <span id="lanFR" class="label actionElement" onclick="changeLangFr();">FR</span>
                        <span id="lanNL" class="label actionElement" onclick="changeLangNl();">NL</span>
                    </div>
                    <div style="clear: both;"></div>
                </div>


                
                <div id="screenconfirmation" class="hide">
                    <apex:outputPanel id="panelConfirmation">
                        <apex:outputText rendered="{!hr08.saveOk}">
                            <div class="alert alert-success">
                                {!hr08.finalMsg}
                            </div>
                        </apex:outputText>
                        <apex:outputText rendered="{!NOT(hr08.saveOk)}">
                            
                            {!hr08.trans.labels.PageConfirm_Intro__c}<br /> 
                            
                            <div id="rowComboConf" class="MB PL PT PB">
                                <div id="rowComboConfIntro"></div>
                                <div id="rowComboConfCustomInput"></div>
                                <div id="rowComboConfXInput"></div>
                            </div>

                            <div class="pull-right" >

                                <button class="btn" type="button" onclick="$('#screenconfirmation').hide();$('#screenchoice').show();">Back</button>
                                <button class="btn btn-primary" type="button" onclick="submitInput(document.getElementById('selCombo').value);">Submit</button>
                                
                            </div>
                            <div class="clearfix"></div>
                        </apex:outputText>
                    </apex:outputPanel>
                </div>


                

                </apex:form>

            </div>
            
        </div>
       
    

    <script type="text/javascript">
        
        function selectRow(rowId){
          ...
        }
        function selectCol(colId){
            ...
        }

        function validateInput(){
            ..
        }

        function loadConfirmationScreen(selectedCol, selectedRow){
           ...
        }
        
    </script>
</body>
</apex:page>

 

 

Controller:

public with sharing class HR01_HR08_Disp{
	...

    public HR01_HR08_Disp(){
       ...
        HR01_HR08_Dispatcher_Init();
    }
    
    public void HR01_HR08_Dispatcher_Init(){
        ... 
		try{
			...
			status = defRightApp[0];
			rightApp = defRightApp[1];
		}catch (Exception e){
			...
		}
    }
  
  public PageReference redirectOrLoad(){
    system.debug('----ced redirectOrLoad | rightApp = ' + rightApp + ' | status = ' + status + ' | insideApp = ' + insideApp);
    if (insideApp) return null;
    
    try{
      if (status == 'END'){
        ...
        return null;
      }
      else if (status == 'OK'){
        
        if (!confs.get(rightApp).Is_On__c){
          ...
          return null;
        }
        else{
          
          if (curPageApp == rightApp){
            system.debug('----ced redirectOrLoad | curPageApp = rightApp = ' + rightApp);
            ...
            return null;
          }
          else {
            system.debug('----ced redirectOrLoad | curPageApp <> rightApp = ' + rightApp);
            PageReference pref;
            if (rightApp == 'LSC'){
              pref = Page.HR01_LSCTEST;
            }
            else if (rightApp == 'LSS'){
              pref = Page.HR08_LSSTEST;
            }
            pref.setRedirect(false);
            curPageApp = rightApp;
            ...
            return pref; 
          }
          
        }
      }
      else {
        ...
        return null;
      }
        

    
    }catch(Exception e){
      
    }
    return null;
    
  }


  

    
    
}

 

I could use a javascript remote call instead, but i don't understand why it's doesn't work like this.

 

Thanks for your help

Ced

  • February 11, 2013
  • Like
  • 0

Hi,

I've an app in 3 languages for which I've a translation apex class.

In my VF page, i use some javascript to display a modal (bootstrap) to let the user confirming his choice without calling the apex, so as to limit the number of calls.

My issue is i want to display the confirm screen in the language of the  user.

 

I've tried to generate the javascript with some <apex:outputText > in it or simply {!mylabel} but it doesn't work.

<script type="text/javascript">
	var arrChoices = new Array();
	var arrNames = new Array();
	alert('<apex:outputText>{!labels.Title_Col1_Conf__c}</apex:outputText>');
	alert('{!labels.Title_Col1_Conf__c}');
	....
</script>

 the alerts are empty.

 

I could make a remote invokeAction to get the labels in the correct language, but it seems a little overpowered for that.

 

Is there a simple way to do that ?

 

Thanks for the help

Ced

  • December 04, 2012
  • Like
  • 0

Hi,

 

I've overwritten the "New" page of a child object. the page uses the standard controller of my object.

I would like to have default value in the Name and another inputField, based on fields of the parent record, but it doesn't work.

 

When not overwriting the "New" page, i use a custom button with the values in parameters. But in this case, when overwriting the page, the parameters don't seem to be taken into account by the VF page.

 

Have I to create an extension controller and set the default values there or is there something "more simple" ?

 

Thanks

Ced

  • July 13, 2012
  • Like
  • 0

Hi,

 

I try to have a table in a visualforce page, but not a repeating table, so i cannot use <apex:dataTable>.

First column with label (big width) and then 2 columns with input fields (smaller width).

 

Have i to use the <apex:inputfield> for the fields ? 

If yes, how can i make them appear on the same line ? They appear always on separate line.

If no, how can i make the <input> related to the SFDC fields so as to save the value in the correct field ?

 

I tried this : 

<table border="1">
<tr><td colspan="2"></td><td  colspan="2">Total</td><td  colspan="2">Part</td></tr>
<apex:outputText >Label bla bla</apex:outputText>
<apex:inputField value="{!Building_Cost__c.CA1a_Real_Rent_Total__c}" label=""/>
<apex:inputField value="{!Building_Cost__c.CA1a_Real_Rent_Part__c}" label=""/>
</table>

 

Thanks for your help

Ced

 

 

  • July 10, 2012
  • Like
  • 0

Hi,

in a test class I need to test some trigger when the user changes his Chatter status (What are you working on ?) but i don't know which field i have to use.

If i export the User fields, i find the status in the CurrentStatus field, but apparently i can't set the value of the field in my test class.

 

I simply do :

usr.currentstatus = 'bla bla bla';
update usr;
        

 but i get the error "Invalid field currentstatus for SObject User".

 

Anyone an idea ?

 

Thanks for the help

Ced

  • June 29, 2012
  • Like
  • 0

Hi,

 

i've Registration object from which i want to send an email template to the Contact related to the Registration.

My email needs to be in the language of the Contact (French, Dutch, English) so i use this

 

<messaging:emailTemplate subject="Confirmation Registration" recipientType="Contact" relatedToType="Registration__c" language="{!recipient.language_email__c}">

<messaging:htmlEmailBody >
<html>
<body height="100%" width="100%">
{!$Label.Dear}<br /><br />

...

 

My $Labels are translated in the 3 needed languages.

 

The email is sent based on a change of status of the Registration.

If i use the "Send Test and Verify Merge Fields" button of the EmailTemplate with the corresponding Registration and Contact, it works fine.

However if change this status in Apex or on the Registration record itself, the mail is always sent in English. 

 

Any idea why it doesn't work otherwise ?

 

Thanks for your help

  • February 22, 2012
  • Like
  • 0

Hi,

 

i've an object Registration for events, with lookup field to itself (one parent registration and some children registrations) and a field Contact__c to the Contacts.

 

When inserting the registrations, i have a trigger (before insert) checking if i can link them to existing Contacts or if i have to create new Contacts (based on email in the Registration form).

 

After inserting the parent and children registrations, the controller of my page sets the Status__c to a new value so as to fire a workflow rule and to generate the membercards with EmailTemplate. I do the update after all inserts (parent and children) so as to send one single mail with all the membership cards of these registrations. Problem is when updating  the Status__c of my registration, the Contact__c doesn't contain the value set by the trigger and so erase the Contact__c of the registration.

 

I can of course reload my Registration before updating the status, but it means one more SOQL statement.

 

Is there a way to avoid this SOQL statement without having the value of Contact erased ?

 

Thanks for your help

Ced

  • February 21, 2012
  • Like
  • 0

I'm becoming mad with this error. I checked the similar post . In those i see the error and in my code i don't see anything wrong.

 

Error is :  Error: Unknown property 'CO01_RegSport_Data.RegistrationChild.indexChild' 

 

The VF page is :

<apex:pageBlockTable value="{!data.regChildren}" var="child">
	<apex:column >
		<apex:facet name="header">number</apex:facet>
		<apex:outputText value="{!child.indexChild}" />
	</apex:column>
	<apex:column >
		<apex:facet name="header">{!labels.FirstName__c}</apex:facet>
		<apex:inputField value="{!child.reg.Firstname__c}" />
	</apex:column>
</apex:pageBlockTable>

 {!child.reg.Firstname__c} is working fine, but not {!child.indexChild}

 

and the controller is :

public class CO01_RegSport_Data{

    private Registration__c regMain;
    private List<RegistrationChild> regChildren;


    public CO01_RegSport_Data(String userId, CO01_RegSport mainclass){
        ...
    }
	

    public Registration__c getRegMain(){return regMain;}
    public List<RegistrationChild> getRegChildren(){return regChildren;}
   
    public PageReference addRegistrationChild(){
        if (regChildren == null) regChildren = new List<RegistrationChild>();
        regChildren.add(new RegistrationChild(regMain, 'Child', this, empl, regChildren.size()+1));
        return null;
    }

    public class RegistrationChild{
        private Registration__c reg;
        private Registration__c regParent;
        private CO01_RegSport_Data data;
        private Employee__c empl;
		private Integer indexChild;

        public RegistrationChild(Registration__c regParent, String relation, CO01_RegSport_Data data, Employee__c empl, Integer indexChild){
            
            reg = new Registration__c();
            ...
			this.indexChild = Integer.valueOf(indexChild);
        }

        public Integer getIndexChild(){return indexChild;}
        public Registration__c getReg(){return reg;}
    }

}

 

Please help me. Tnx in advance.

  • February 02, 2012
  • Like
  • 0

Hi,

is it possible to fire a trigger when an user install Chatter Mobile ? On which object - field should i fire it ?

Thanks for your help

Ced

  • January 31, 2012
  • Like
  • 0

Hi,

 

i try to insert a field including HTML in a HTML Email template. This field including HTML is filled in by a trigger based on the records of a related list (that's why i cannot write the HTML direcetly in the template), but of course the result is the <a> are written as so in the sent HTML and are not links.

 

Is there a way to do that ? I could send my email in the trigger itself but in this case, i've the problem with the limit of 10 SendEmail in one transaction.

 

Thanks for your help

  • January 18, 2012
  • Like
  • 0

Hi,

I've a site, in which users can select some choices.

The object behind has a child relationhip with the different items chosen by the user.

 

After inserting the record and the children items, i would like to send a PDF by email to the user to confirm him the selection he made.

 

The problem I've is the controller of the PDF page doesn't find the children of the object, as they were not there.

If i look in the object, everything is ok. If i add a commandlink on the last page to generate and send the pdf, it's ok too.

The problem appears only when i want to automate the PDF sending => insert and send in the same user interaction.

 

Has somebody an idea ? Is it a matter related  to the order of the actions, like insert is asynchronous and then when the call to the PDF generation is done, children are not really inserted yet ?

 

Thanks for your help

Ced

 

  • September 28, 2011
  • Like
  • 0

Hi,

in my VF page, i've the following code:

<apex:repeat value="{!ad.groupCafAdvList}" var="groupadv">
	
	<apex:outputPanel id="groupOptions" layout="block" rendered="true">
		<apex:inputCheckbox style="width:20px;" id="group_Chk" value="{!groupadv.selected}" >
			<apex:actionSupport event="onchange" rerender="{!$Component.groupOptions}" /></apex:inputCheckbox>
		<apex:outputText value="{!groupadv.name}" />
		
		<apex:outputPanel id="groupcontent" layout="block" rendered="{!groupadv.selected}">
			content<br />
			content<br />
			content<br />
			content<br />
		</apex:outputPanel>
	</apex:outputPanel>
</apex:repeat>

 and it works, but normally i would like to rerender only the outputPanel with id "groupcontent" (the embedded one).

 

I don't understand why I've to rerender the embedding outputPanel.

 

Can anybody explain it to me ?

 

Thanks

  • August 26, 2011
  • Like
  • 0

Hello,

I've a site with a wizard in it. When the user goes to the site, i check in the first page if this user is already came. If so, i load the saved state of his wizard and make a redirect to the correct page of the wizard.

To redirect him, i use the action attribute of the page. 

 

<apex:page sidebar="false" showheader="false" controller="Move_North" cache="false" action="{!ad.loadCafState}">

 ad is an object created in the controller of the page.

 

The function loadCafState is looking like:

pageRef = new PageReference('/apex/HR01_Confirm_And_Send');
pageRef.setRedirect(false);
return pageRef;

 (I don't use /apex/ in my real code, it's just to debug.

 

With the parameter of setRedirect = true, i move correctly to the page, but i lose all values preloaded. Normal if i refer to the documentation.

With setRedirect = false, the page seems not to be redirected, and doesn't display the css anymore ???

 

In the documentation, i find "If set to false, the redirect is a server-side forward that preserves the view state if and only if the target page uses the same controller and contains the proper subset of extensions used by the source page"

 

What is a proper subset of extensions ?

When is executed the method in the action attribute compared to the execution of the controller ?

 

Thanks for your help

Ced

  • August 19, 2011
  • Like
  • 0

Hi 

I've a page with some blocks repeated, as i don't know at the creation how many they are. First blocks have some dropdowns, following blocks contain a upload file. 

 
<apex:outputPanel rendered="true" layout="block" style="width:440px;margin-left:auto;margin-right:auto;">
  <apex:repeat value="{!ad.advantageCafOptionList}" var="ado">
    <apex:outputPanel id="OtherOption" rendered="{!ado.selected && ado.hasSizeColor}">
	  <apex:repeat value="{!ado.advOrderingInfosList}" var="advoi">
		<apex:outputPanel layout="block" styleClass="myFormBudgetFieldset" >
		  <div style="margin-top:5px;margin-bottom:5px;">
			<apex:outputText >{!ado.Option_Displayed_Name}</apex:outputText>
			<apex:outputLabel style="padding-left:3px;" for="sizeBikeSelected">Taille:</apex:outputLabel>
			<apex:selectList style="margin:0px 5px;" id="sizeBikeSelected" value="{!advoi.sizeBike}" size="1">
			  <apex:selectOptions value="{!ado.selectOptionSizeBike}"/>
			</apex:selectList>
		  </div>
		</apex:outputPanel>
	  </apex:repeat>
	</apex:outputPanel>
	<apex:outputPanel id="uploadOption" rendered="{!ado.selected && ado.hasNoFixedPrice}">
	  <apex:repeat value="{!ado.advNoFixedPriceOfferList}" var="advnfpo">
		<apex:actionRegion>
		  <apex:outputPanel layout="block" styleClass="myFormBudgetFieldset" >
			<div style="margin-top:5px;margin-bottom:5px;">
			  <apex:outputText >{!ado.Option_Displayed_Name}</apex:outputText>
			  <div style="padding-left:15px;padding-top:5px;">
				<apex:outputPanel id="uploadFile">
				  <apex:actionStatus id="refreshStatus" startText=" (Uploading...) " stopText=" "/>
				  <apex:outputText rendered="{!not(advnfpo.attachDone)}">
				    <apex:outputLabel value="File" for="file"/>
					<apex:inputFile value="{!advnfpo.attach.body}" filename="{!advnfpo.attach.name}" id="file" />
					<apex:commandButton action="{!advnfpo.upload}" value="Upload">
					  <apex:actionSupport event="onclick" rerender="{!$Component.uploadFile}" status="refreshStatus"/>
					</apex:commandButton>
				  </apex:outputText>
				  <apex:outputText rendered="{!advnfpo.attachDone}">
					Attachment already uploaded
				  </apex:outputText>
				</apex:outputPanel>
			  </div>
			</div>
		  </apex:outputPanel>
		</apex:actionRegion>
	  </apex:repeat>
	</apex:outputPanel>
  </apex:repeat>
</apex:outputPanel>

 

I've 2 problems:

1/ when uploading one attachment, i would like to refresh only the block where is the upload file, and not all the blocks. Currently, if I select the values in the dropdowns of the first blocks, and then upload a file, all the values of the dropdowns are lost after the refresh. I tried the <apex:actionRegion> as i saw on another topic, but it doesn't work. I used also the {!$Component.uploadFile} to determine which id of the loop should be rerendered, but without success.

 

2/ when uploading the file, i would like to display a message "uploading ..". I used the <apex:actionStatus> but it disappear almost instantly. At the end of the upload, i switch the <ouputText> to be displayed. This happens much later the actionStatus disappear. I don't understand why.

 

Thanks for your help.

Ced

  • August 18, 2011
  • Like
  • 0

Hi, 

I just created a new page in my app (by copying the structure of another page), and for some reason a datepicker without css appears at the end of the page.

When looking in the source, this datepicker is after the </apex:form>.

 

Does anybody know why this datepicker appears ?

 

Thanks for your help

  • August 16, 2011
  • Like
  • 0

Hi,

in one of my visualforce page, there is a picklist for which the record type that sets the options available doesn't seem to be taken into account .

I read some posts about that, and i understood correctly it should be fixed since Winter 11 release, but it's still not working in my VF page.

So is this issue still opened and do i have to manage the options dynamically, or is it fixed anyway.

Thanks for the feedback.

Ced

  • April 28, 2011
  • Like
  • 0

Hi,

for my project , i need to clone some records but with the possibility for the user to change some fields (reset the status, ...). So i don't use the standard Clone button.

In my Apex class, I use the clone() method and then insert :

 

 

request = [select Id, Circuit__c from MyObject where id = :request.id];
clonedRequest = request.clone(false);
insert clonedRequest;
return new PageReference('/'+clonedRequest.id+'/e?retURL=%2F'+clonedRequest.id);

 

The problem i have is in this case, this code has created a new record ID, even if the user cancels it (due to the insert).
Is it possible not to insert the new record, but to see a temporary version which is really created only when clicking on the Save button (as the standard Clone works) ?
Thanks for your help
Ced

 

  • March 11, 2011
  • Like
  • 0

Hi,

 

i'm new in Trigger and Apex methods, so it's probably a dummy question.

 

I have an object SGRequest with a custom button to send PDF. (code found on the site of Jeff Douglas)

So i have a controller extension 

 

public with sharing class SGRequestPDFEmail{
 
   public SGRequest__c request {get;set;}

   public SGRequestPDFEmail(Apexpages.Standardcontroller con) {
      request = (SGRequest__c)con.getRecord();
   }
     
   public PageReference sendPdf() {
     
      PageReference pdf = Page.SGRequestPDFTemplate;
      // add parent id to the parameters for standardcontroller
      pdf.getParameters().put('id',request.id);
      // the contents of the attachment from the pdf
      Blob body;

      try {
         // returns the output of the page as a PDF
         body = pdf.getContent();
         // need to pass unit test -- current bug  
      } catch (VisualforceException e) {
         body = Blob.valueOf('Some Text');
      }
 
      Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
      attach.setContentType('application/pdf');
      attach.setFileName(request.File_Name__c);
      attach.setInline(false);
      attach.Body = body;
      
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
      mail.setUseSignature(false);
      mail.setToAddresses(new String[] {request.email_author__c});
      mail.setSubject('PDF Email Demo');
      mail.setHtmlBody('Here is the email you requested! Check the attachment!');
      mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach }); 
 
      // Send the email
      Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Email with PDF sent to '+request.email_author__c));
 
      return null;
 
   }
 
}
This works fine, so when clicking on the button, the mail is correctly sent with the PDF in attachment.
Now i would like to trigger this after changing a field Status__c in my object SGRequest__c.
trigger SendPdfOnApproval on SGRequest__c (after update) {
    for (SGRequest__c sgr : Trigger.new){
        if ((sgr.Status__c != trigger.oldMap.get(sgr.id).Status__c) && (sgr.Status__c == 'Approved') ){
            sgr.sendPdf();
        }
    }
}
but of course, sgr doesn't know the method sendPdf ...
Can anybody help me ?
Thanks in advance

 

  • January 11, 2011
  • Like
  • 0

Hi,

 

I want to generate a PDF and attach it to an email, based on the Opportunity object. So far, it shouldn't be difficult...

 

So i've a VF page with the content , rendered as pdf and its controller. If i launch the page in a browser, it's ok.

 

I've another class (containing the method launched by an action button on the Opportunity layout) to get the content of the PDF and attach it to the email.

Before attaching it, i want to check if there is no error in the PDF, so I call the body.toString() method to do that  (body is the blob). 

Then i get the error "System.StringException: BLOB is not a valid UTF-8 string", while  I used this method many times in the past without problem for other PDF generation.

 

        PageReference pdf;
        pdf = Page.QuoteTemplate;
        pdf.getParameters().put('id',opp.Id);
Blob body; try { body = pdf.getContent(); } catch (VisualforceException e) { body = Blob.valueOf('Some Text ... ERROR_COMPANYADDRESSNOTFOUND ... ERROR_COMPANYNOTFOUND'); } if (body.toString().contains('ERROR_')){ return 'warning'; }

 

I searched for information, i find that examples of this error when trying to read the content of a document which is not in UTF8, but in this case i'm starting from a VF page and when i try directly to look at the page, it's ok.

 

One solution often mentionned is to use the  EncodingUtil.base64Encode(body);

but then I cannot compare the content to find the "ERROR_..." (i think)

 

 

Anybody has an idea ?

 

Many thanks

Ced

 

  • September 13, 2013
  • Like
  • 0

Hi,

I've an app in 3 languages for which I've a translation apex class.

In my VF page, i use some javascript to display a modal (bootstrap) to let the user confirming his choice without calling the apex, so as to limit the number of calls.

My issue is i want to display the confirm screen in the language of the  user.

 

I've tried to generate the javascript with some <apex:outputText > in it or simply {!mylabel} but it doesn't work.

<script type="text/javascript">
	var arrChoices = new Array();
	var arrNames = new Array();
	alert('<apex:outputText>{!labels.Title_Col1_Conf__c}</apex:outputText>');
	alert('{!labels.Title_Col1_Conf__c}');
	....
</script>

 the alerts are empty.

 

I could make a remote invokeAction to get the labels in the correct language, but it seems a little overpowered for that.

 

Is there a simple way to do that ?

 

Thanks for the help

Ced

  • December 04, 2012
  • Like
  • 0

Hi,

 

I've overwritten the "New" page of a child object. the page uses the standard controller of my object.

I would like to have default value in the Name and another inputField, based on fields of the parent record, but it doesn't work.

 

When not overwriting the "New" page, i use a custom button with the values in parameters. But in this case, when overwriting the page, the parameters don't seem to be taken into account by the VF page.

 

Have I to create an extension controller and set the default values there or is there something "more simple" ?

 

Thanks

Ced

  • July 13, 2012
  • Like
  • 0

Hi,

 

I try to have a table in a visualforce page, but not a repeating table, so i cannot use <apex:dataTable>.

First column with label (big width) and then 2 columns with input fields (smaller width).

 

Have i to use the <apex:inputfield> for the fields ? 

If yes, how can i make them appear on the same line ? They appear always on separate line.

If no, how can i make the <input> related to the SFDC fields so as to save the value in the correct field ?

 

I tried this : 

<table border="1">
<tr><td colspan="2"></td><td  colspan="2">Total</td><td  colspan="2">Part</td></tr>
<apex:outputText >Label bla bla</apex:outputText>
<apex:inputField value="{!Building_Cost__c.CA1a_Real_Rent_Total__c}" label=""/>
<apex:inputField value="{!Building_Cost__c.CA1a_Real_Rent_Part__c}" label=""/>
</table>

 

Thanks for your help

Ced

 

 

  • July 10, 2012
  • Like
  • 0

Hi,

in a test class I need to test some trigger when the user changes his Chatter status (What are you working on ?) but i don't know which field i have to use.

If i export the User fields, i find the status in the CurrentStatus field, but apparently i can't set the value of the field in my test class.

 

I simply do :

usr.currentstatus = 'bla bla bla';
update usr;
        

 but i get the error "Invalid field currentstatus for SObject User".

 

Anyone an idea ?

 

Thanks for the help

Ced

  • June 29, 2012
  • Like
  • 0

Hi,

 

i've Registration object from which i want to send an email template to the Contact related to the Registration.

My email needs to be in the language of the Contact (French, Dutch, English) so i use this

 

<messaging:emailTemplate subject="Confirmation Registration" recipientType="Contact" relatedToType="Registration__c" language="{!recipient.language_email__c}">

<messaging:htmlEmailBody >
<html>
<body height="100%" width="100%">
{!$Label.Dear}<br /><br />

...

 

My $Labels are translated in the 3 needed languages.

 

The email is sent based on a change of status of the Registration.

If i use the "Send Test and Verify Merge Fields" button of the EmailTemplate with the corresponding Registration and Contact, it works fine.

However if change this status in Apex or on the Registration record itself, the mail is always sent in English. 

 

Any idea why it doesn't work otherwise ?

 

Thanks for your help

  • February 22, 2012
  • Like
  • 0

Hi,

     Our app has a  hierarchy as Flex-->Apex-->External Web Service and When we call the Apex Web Service we get the fillowing error:

   

     System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: Exception occurred while trying t  invoke service method registerUserForm faultcode=soapenv:Server faultactor=External entry point

 

     In DE it is working fine,We installed the package in Test org and we got the above exception.

 

     can anyone give us a solution for solving this issue.

 

 

 

  • June 30, 2011
  • Like
  • 0

Hi,

 

I want to fire  Assignment rule when a case is created via Web Service in Salesforce.

I tried using DML Options but getting the following error:

 

"Execution of AfterInsert caused by: System.SObjectException: DML statment cannot operate on trigger.new or trigger.old:"

 

I am using an after insert trigger..

Please help me.. Its urgent

  • March 26, 2011
  • Like
  • 0

I have an ok understanding of apex and I am new to VPM (Flow Designer).

 

I am trying to get "Apex Callout" to work with a class i have but am not getting anywhere. After opening the flow designer pdf i came across the following statement:

 

"The visual Apex callout element allows you to call an Apex class with the Process.Plugin interface"

What is the process.plugin interface? because i am getting the following error when uploading the flow into Salesforce

"ErrorWe had trouble uploading the flow. Apex class does not exist or is not a plugin class: FlowDesignerISA.GetISAamount"

Can anyone help?
Thanks in-advance.

  • March 08, 2011
  • Like
  • 0