• Ryan D
  • NEWBIE
  • 45 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 3
    Questions
  • 16
    Replies

I have a scenario that I need some advice on. 

 

Here is the user experience:

 

1. user clicks on a custom field("generate pdf") on the Opportunity page layout. 

2. clicking the field takes them to my "Landing page" where they are given a list of choices for which type of pdf report the want to create.

3. once they click their choice, which is an apex:outputLink to the renderAs pdf page, it opens the pdf page in an iFrame within my "Landing page".  From there they can use the browser-native print, save whatever.

 

I have this part working great.  The only thing I have to do now is, once they click on the outputLink and the page is generated, I want that pdf page to automatically get inserted into the Opportunity record as well as appear in the iFrame.

 

A little more background: the pdf page has it's own controller and a ton of classes behind it.  The landing page currently uses the Opportunity standardController so I can reference some fields from Opportunity.  

 

I was thinking I could use a controller extension to handle the insertion because I already found some code to insert a PDF page to a record.  The problem is that I think this will generate a second copy of the pdf page, which is quite heavy if the custom object being reported on has lots of data in it.

 

Another theory: could I somehow reference the page that is in the iFrame once it's rendered and then insert that page into the opportunity?

 

Any thoughts or help on this would be greatly appreciated.

 

Here is the basic code that I found already to insert the record:

//Call your VF page
        // WIth out any parameters to the vfpage.
        pageReference pdf = Page.YOURVFPAGE;
       //With paramters
        PageReference pdf = new PageReference('/apex/SamplePdfDoc?Id='+theParameter);
        Attachment attach = new Attachment();
        Blob body;
        //the getContent()method cannot used in Trigger, but there is a workaround which is a little tricky.
        body = pdf.getContent();
        attach.Body = body;
        attach.Name = 'pdfName.pdf';
        attach.IsPrivate = false;
        attach.ParentId = 'opprtunityID';
        insert attach;

 

 

Hi there.  I have been working with the VisualForce "renderAs="pdf"" with my page.  The client has some requirements I need to meet.  I need to add the pdf to the Opportunity record in the notes and attachments related list.

I have found the following code:

 

Apexpages.currentPage().getHeaders().put('content-disposition', 'attachment; filename='+pdfName);

 This code is great because as soon as the user clicks on the link to my pdf rendered page it just opens the save dialog.  However, in addition to this I would like to insert the pdf as an attachment to the record it is related to. 

I found some code and got some help from the forum already about inserting the page as a new attachment but when the file attaches to the record I get an error from Adobe reader when I try to open it: 

ERROR: Adobe Reader could not open 'FILENAME.pdf' because it is either not a supported file type or because the file has been damaged (for, example, it was sent as an email attachment and wasn't correctly decoded).

My question is this: does the line of code above create an attachment, and if so, can't I just insert that into my related record instead of making a new attachment and using getContent() etc.?

 

Thanks!

 

  • April 25, 2013
  • Like
  • 0

I have a bit of a tricky scenario.

 

I have a custom VF page to display information about a custom object.  The page uses a custom controller.  The custom object is the child of Opportunity.  The VF page is rendered as PDF.  What I want to accomplish is this: Insert the PDF page as an Attachment on the Opportunity that the custom object is related to.  Does anybody know the best/easiest way to do this?  I'm a bit of a Salesforce/VisualForce noob so any help is greatly appreciated.

 

Thanks!

  • April 25, 2013
  • Like
  • 0
This is for the "Subscribe to Platform Events" unit in the "Platform Event Basics" module.  I have: ​
- Created the trigger
- Created a test class
- Verified that the trigger is active
- Set up debug logging on my user ID and on Automated Process
- set up tracing on the trigger
- added system.debug messages in the trigger

When I run the apex test, I see no evidence of the trigger getting fired.   Debug Logs also don't show any evidence of trigger firing.  

The ApexTrigger Event Type log in the Salesforce Event Log File Browser does not show the trigger being fired.

What am I missing?  Code for trigger and test is below.
trigger OrderEventTrigger on Order_Event__e (after insert) {
	System.debug('OrderEventTrigger firing');
    List<Task> allTasks = new List<Task>();
    Task newTask = null;
    System.debug('Order count: ' + Trigger.New.size());
    for( Order_Event__e nextOrder : Trigger.New ){
        System.debug('Shipped: ' + nextOrder.Has_Shipped__c);
        if( nextOrder.Has_Shipped__c == true ){
			System.debug( 'Creating task');
            newTask = (new Task(Subject='Follow up on shipped order' + nextOrder.Order_Number__c,
                                 Priority='Medium', Status='New', OwnerId=Userinfo.getUserId()));
            AllTasks.add(newTask);
            System.debug(newTask);
        }//if
    }//for
    
    insert allTasks;
}
 
@isTest
public class OrderEventTriggerTest {
    @isTest static void test1(){
        Order_Event__e orderEvent = new Order_Event__e(Has_Shipped__c=true, 
                                                       Order_Number__c='333');
        
        Test.startTest();
        System.debug('Sending event:' + orderEvent);
        Database.SaveResult sr = EventBus.publish( orderEvent );
        Test.stopTest();
        List<Task> tasks = [SELECT Id from Task];
        System.assertEquals(1, tasks.size());
    }
}

 
I did exactly what was told in the trail yet i am unable to find the custom link( not a member?) in the login page .....check the images and help me ..stuck here for last two days User-added imageUser-added image
The "Apex Web Services" trailhead unit/module says to get the session id form the Workbench -> Session Information menu option in the connection  folder.  But I don't know if I'm doing something wrong but I don't see any session id value listed there.

So I found another simple way to get the session id to pass into cURL command line as instructed by the trailhead.

Simply copy and paste the following line into the Execute Annoymous Window of the developer console and view the log file:

System.debug('Sessionid='+UserInfo.getSessionId());

 

 

Hi,

The issue is that I deployed a Trigger and Test class in Production from one of our sandbox.
In sandbox code coverage for that trigger is 62% (107/170) and the same in production is showing as only 42% (107/249).

Version in sandbox and prod is 20.0 for both the Trigger and Test class.
If you could observe there is a difference in the total number of lines in both the environments.
I have checked in production to know the difference so I found that its because in production its showing even commented lines and flower braces as not covered.

Any help will be much appreciated!

  • April 25, 2013
  • Like
  • 0

I have a bit of a tricky scenario.

 

I have a custom VF page to display information about a custom object.  The page uses a custom controller.  The custom object is the child of Opportunity.  The VF page is rendered as PDF.  What I want to accomplish is this: Insert the PDF page as an Attachment on the Opportunity that the custom object is related to.  Does anybody know the best/easiest way to do this?  I'm a bit of a Salesforce/VisualForce noob so any help is greatly appreciated.

 

Thanks!

  • April 25, 2013
  • Like
  • 0

I'm a newbie just learning to write Apex Code.  I wrote an Apex Trigger to set Type_Of_Activity__c  to equal Type.  This works great:

 

trigger SyncType on Task (before insert, before update){
  Task myTask = trigger.new[0];
        if(myTask.Type != null){
            myTask.Type_of_Activity__c = myTask.Type;
        }
}

 

How do you do this same thing when doing an Event?  I want to set Type_of_Activity__c equal to Event Type.

 

Thanks!

  • April 24, 2013
  • Like
  • 0

Hi,

I don't understand about wildcards:

 

Please can you explain me ( with example of words) which user'srole name return this:

 

1 Select id from user where UserRole.Name LIKE ' %Dir%'

 

2 Select id from user where UserRole.Name LIKE ' Dir%'

 

3 Select id from user where UserRole.Name LIKE ' Dir_%'

 

 

Thanks in advance.

 

King regard

i have created an object with name PS_Detail__c .in this custom object i created a custom field of picklist type.in this picklist i defined two values Dollar ,Unit. when i go to P/S Detail Tab for creating a new PS_Detail__c object then i get None also as a value in picklist field .i want only Dollar and Unit as Picklist values .some one please help how to remove this None from Picklist

Hello, this is my doubt, how to get the current visualforce page id? I try with {!$Currentpage.Id} or $Page.Id but dont exists this variables.

 

Thanks.

  • November 03, 2011
  • Like
  • 0

Hi in absence of select distinct can somebody please send me the alternative logic for select distinct in sfdc please?

 

I tried the following link but this logic is not working

 

http://developinthecloud.wordpress.com/2009/06/28/soql-distinct-keyword/

  • March 31, 2010
  • Like
  • 0
I've added all these line of code in the Save() method to try to satisfy the "Modify the save() function to implement CRUD/FLS check on the Name field of the Encrypt_Decrypt__c object." requirement but nothing seems to pass it's check.  Anyone else run into this or have any ideas?

        if (!Schema.sObjectType.EnCrypt_Decrypt__c.fields.Name.isCreateable()) { 
            return NULL; 
        }
        if (!Schema.sObjectType.EnCrypt_Decrypt__c.fields.Name.isUpdateable()) { 
            return NULL; 
        }        
        if (!Schema.sObjectType.EnCrypt_Decrypt__c.fields.Name.isAccessible()) { 
            return NULL; 
        }        

Thanks,
Deb