function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jg@hhsjg@hhs 

Attach pdf to email using record id

I'm writing a apex class that uses the Messaging.EmailFileAttachment class. Is there a reason that the 18-character record id does not work when used to attach a pdf of a visualforce page?  I've tried truncating to 15-characters (which does work, as I hard-coded, and also assigned a system.debug variable to watch it fail with 18).  But assigning a truncated string variable back to id automatically attaches those 3 characters again.  Is there another way to go about this?

 

Sorry - realized that the length of the Id was not the problem.  It only works if I hardcode an Id.  anytime I try and place an Id variable that contains either a 15 or 18 character Id it fails..

My Class:

 

 

get {
      if (newrecord == null)
        newrecord = new Admin_Compliance__c();
      return newrecord;
      }
  set;
  }

 

insert newrecord; 
      
      Id nrid = newrecord.id;
      
   System.debug(nrid);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

  PageReference pdf = Page.admincomp_thankyou;
  pdf.getParameters().put('id', nrid);
Jeremy.NottinghJeremy.Nottingh

This is a shot in the dark, but what if you define nrid as a String instead of an Id? I've run into situations where one of these works and the other doesn't.

 

Jeremy