• Mayank_Sharma
  • NEWBIE
  • 10 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 4
    Replies

Below is my class which is generating PDF for insert or update, BUT FOR A SINGLE RECORD ONLY

public with sharing class PDFGenerator
{
    
    public static final String FORM_HTML_START = '<HTML><BODY>';
    public static final String FORM_HTML_END = '</BODY></HTML>';

    public static void generateAccountPDF(Payment__c payment)
    {
        
        for(Payment__c p:[select id, name,TransactionStatus__c from payment__c where id=:payment.id]){
                String pdfContent = '' + FORM_HTML_START;
        try
        {
            pdfContent = '' + FORM_HTML_START;
            pdfContent = pdfContent + '<H2>Account Information in PDF</H2>';
            pdfContent = pdfContent + '<P>' + 'Mayank' + ': ' + p.name + '</P>';
            pdfContent = pdfContent + '<P>' + 'Sharma' + ': ' + p.TransactionStatus__c + '</P>';
            pdfContent = pdfContent + FORM_HTML_END;
        }catch(Exception e)
        {
            pdfContent = '' + FORM_HTML_START;
            pdfContent = pdfContent + '<P>THERE WAS AN ERROR GENERATING PDF: ' + e.getMessage() + '</P>';
            pdfContent = pdfContent + FORM_HTML_END;
        }
        attachPDF(payment,pdfContent);
            
        }
        
        
    }
    
    public static void attachPDF(Payment__c payment, String pdfContent)
    {
        try
        {
            Attachment attachmentPDF = new Attachment();
            attachmentPDF.parentId = payment.Id;
            attachmentPDF.Name = payment.Name + '.pdf';
            attachmentPDF.body = Blob.toPDF(pdfContent); //This creates the PDF content
            insert attachmentPDF;
        }catch(Exception e)
        {
            payment.addError(e.getMessage());
        }
    }
    
}

Can anyone suggest me how to make this code work for bulk insert or update

 

<ui:button label="Export to PDF" 
                       class="slds-button slds-button--neutral"
                       press="{!c.navigate}"
                       labelClass="label"/>

on click calling below navigate and trying to open random youtube link. However I need to open VF page. Any suggestions what is wrong 

 navigate : function (component, event, helper) {
    var urlEvent = $A.get("e.force:navigateToURL");
    console.log('urlEvent is '+urlEvent);
         var myUrl = 'https://www.youtube.com/watch?v=gOmL6ysIZrE';
    urlEvent.setParams({
        "url": myUrl
    });    
    urlEvent.fire();
    /*window.location('/006/o');*/
    }

Hi All,

Need a thought, how to revoke Managed Packaged License from the User, once the User is deactivated(Automatically)


Regards,
Mayank

Hi All,

 

 I need a report  based on Case. I need to calculate the time duration when the case is in "R&D" and "in Progress" status.

 However this report should show the time duration according to the representative.

 

e.g.  there is a case 1 

 

1. User1 change the status from NEW to IN PROGRESS. say at 9am

2. User 2 change the satus from IN PROGRESS to HOLD Say at 10am

3. User3 change the status from HOLD to R&D say at 12 pm

4. USer4 change the status from R&D to closed say at 15 pm

 

Hence i need report as

User 1 ::  Working hours 1(10am-9am) IN PROGRESS

User2  :: Working hours  3 (15pm -12pm) R&D

 

Any help and suggestion is highly appreciable.

 

Thanks,

Mayank

Hi All,

 

 I need a report  based on Case. I need to calculate the time duration when the case is in "R&D" and "in Progress" status.

 However this report should show the time duration according to the representative.

 

e.g.  there is a case 1 

 

1. User1 change the status from NEW to IN PROGRESS. say at 9am

2. User 2 change the satus from IN PROGRESS to HOLD Say at 10am

3. User3 change the status from HOLD to R&D say at 12 pm

4. USer4 change the status from R&D to closed say at 15 pm

 

Hence i need report as

User 1 ::  Working hours 1(10am-9am) IN PROGRESS

User2  :: Working hours  3 (15pm -12pm) R&D

 

Any help and suggestion is highly appreciable.

 

Thanks,

Mayank

 

 

 

 

Below is my class which is generating PDF for insert or update, BUT FOR A SINGLE RECORD ONLY

public with sharing class PDFGenerator
{
    
    public static final String FORM_HTML_START = '<HTML><BODY>';
    public static final String FORM_HTML_END = '</BODY></HTML>';

    public static void generateAccountPDF(Payment__c payment)
    {
        
        for(Payment__c p:[select id, name,TransactionStatus__c from payment__c where id=:payment.id]){
                String pdfContent = '' + FORM_HTML_START;
        try
        {
            pdfContent = '' + FORM_HTML_START;
            pdfContent = pdfContent + '<H2>Account Information in PDF</H2>';
            pdfContent = pdfContent + '<P>' + 'Mayank' + ': ' + p.name + '</P>';
            pdfContent = pdfContent + '<P>' + 'Sharma' + ': ' + p.TransactionStatus__c + '</P>';
            pdfContent = pdfContent + FORM_HTML_END;
        }catch(Exception e)
        {
            pdfContent = '' + FORM_HTML_START;
            pdfContent = pdfContent + '<P>THERE WAS AN ERROR GENERATING PDF: ' + e.getMessage() + '</P>';
            pdfContent = pdfContent + FORM_HTML_END;
        }
        attachPDF(payment,pdfContent);
            
        }
        
        
    }
    
    public static void attachPDF(Payment__c payment, String pdfContent)
    {
        try
        {
            Attachment attachmentPDF = new Attachment();
            attachmentPDF.parentId = payment.Id;
            attachmentPDF.Name = payment.Name + '.pdf';
            attachmentPDF.body = Blob.toPDF(pdfContent); //This creates the PDF content
            insert attachmentPDF;
        }catch(Exception e)
        {
            payment.addError(e.getMessage());
        }
    }
    
}

Can anyone suggest me how to make this code work for bulk insert or update

 

Hi Guys,

I am trying to develop a trigger(not sure if it is possible through Apex Triggers) to save a custom object record as a pdf document and then attach the same document to that record. we have a custom object called Research, what we want to achieve is when a certain date field is entered and saved then the data in that research record must be saved as a PDF document and get attached to the same record. 

I am not sure if this is achievable through triggers only. can anyone give any suggestions for how this can be achieved?

Thanks,
  • April 08, 2015
  • Like
  • 0
Hi All,

Need a thought, how to revoke Managed Packaged License from the User, once the User is deactivated(Automatically)


Regards,
Mayank