• kavshi
  • NEWBIE
  • 0 Points
  • Member since 2012

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

Hi,
I need 2 custom button in Event object 1) Lock 2) Audit ( Unlock)
whenever the Event is create for account record type  event will be coped in all child records attachments in the form of PDF and name with event.<AccountRecordType>

When same record is updated, previous record must be lock and <audit> button should be populated. Event should be copied in child record in the form of PDF with version like Event.<account record type>.v1.1

 

PDF:

PDF file code is working properly. But it;s showing every field in the given object. But I need only 6 field Event in the object. How to filter these 6 field and I need 3 more from the other object how to add these fields please sagest me I need to submit today

In Event object 6 fields: 1) Subject 2) Description 3) CreatedBy 4) StartDateTime 5) EndDateTime 6) What
in  Portfolio__c object 3 fields 1) Suitability 2) DMS_Folder__c 3) DMS_Sub_Folder__c

 

-----------

Trigger:

------------

trigger AfterUpdateEventTrigger on Event(after insert, after update) {

 

    if(Trigger.isInsert){        

Set<ID> accountIdSet = new Set<ID>();

        for(Event e : Trigger.New){

            accountIdSet.add(e.WhatId);  

          }         Map<Id,List<Portfolio__c>> portfolioMap = new Map<Id,List<Portfolio__c>>();    

     List<Account> orgList = [select Id, Name from Account where Id in :accountIdSet];

        if(orgList != null && orgList.size()>0){    

         for(Account org : orgList){       

          List<Portfolio__c> portfolioList = [Select ID, Mandate__r.Mandate_Owner__c from Portfolio__c where Mandate__r.Mandate_Owner__c=:org.Id];    

             if(portfolioList != null && portfolioList.size()>0)       

              portfolioMap.put(org.Id,portfolioList);             }         }   

      for(Event e : Trigger.New){          

   List<Portfolio__c> tempList = portfolioMap.get(e.WhatId);     

        List<ID> portfolioIdList = new List<ID>();        

     if(tempList != null && tempList.size()>0){           

      for(Portfolio__c temp : tempList){           

          portfolioIdList.add(temp.Id);               

  }          

       if(portfolioIdList != null && portfolioIdList.size()>0)         

            PDFGenerator.generatePDF(e,portfolioIdList);         

    }     }        }

 

    if(Trigger.isupdate){        

Set<ID> accountIdSet = new Set<ID>();      

   for(Event e : Trigger.old){    

         accountIdSet.add(e.WhatId);     

      }    

     Map<Id,List<Portfolio__c>> portfolioMap = new Map<Id,List<Portfolio__c>>();      

   List<Account> orgList = [select Id, Name from Account where Id in :accountIdSet];     

    if(orgList != null && orgList.size()>0){       

      for(Account org : orgList){         

        List<Portfolio__c> portfolioList = [Select ID, Mandate__r.Mandate_Owner__c from Portfolio__c where Mandate__r.Mandate_Owner__c=:org.Id];        

         if(portfolioList != null && portfolioList.size()>0)              

       portfolioMap.put(org.Id,portfolioList);             }         }

        for(Event e : Trigger.old){      

       List<Portfolio__c> tempList = portfolioMap.get(e.WhatId);     

        List<ID> portfolioIdList = new List<ID>();    

         if(tempList != null && tempList.size()>0){        

         for(Portfolio__c temp : tempList){                    

portfolioIdList.add(temp.Id);                 }         

        if(portfolioIdList != null && portfolioIdList.size()>0)        

             PDFGenerator.generatePDF(e,portfolioIdList);          

   }         }     }      

-------------------

pdf:

--------------------

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 generatePDF(Event orgEvent, List<Id> parentIdList)     {

String pdfContent = '' + FORM_HTML_START;         String pdfName = '';  

 try         {

pdfContent = '' + FORM_HTML_START;

pdfContent = pdfContent + '<CENTER><H2>Event Information</H2></CENTER>';

pdfContent = pdfContent + '<P>' + ' ' + '</P>';            

pdfContent = pdfContent + '<P>' + 'Hi ' + '</P>';                      

pdfContent = pdfContent + '<P>' + 'New event is created please note that the following details ' + '</P>';                         //Dynamically grab all the fields to store in the PDF     

Map<String, Schema.SObjectType> sobjectSchemaMap = Schema.getGlobalDescribe();             Schema.DescribeSObjectResult objDescribe = sobjectSchemaMap.get('Event').getDescribe();  

Map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();                        

            //Append each Field to the PDF            

for(Schema.SObjectField fieldDef : fieldMap.values()  )             {

Schema.Describefieldresult fieldDescResult = fieldDef.getDescribe();                

String name = fieldDescResult.getName();                

pdfContent = pdfContent + '<P>' + name + ': ' + orgEvent.get(name) + '</P>';                    

}

 pdfContent = pdfContent + FORM_HTML_END;            

pdfName = 'org_event';         }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(parentIdList,pdfName,pdfContent);    

}        

private static void attachPDF(List<ID> parentIdList, String pdfName, String pdfContent)     {         try         {             if(parentIdList != null && parentIdList.size()>0){            

List<Attachment> attachmentList = new List<Attachment>();                

for(ID parentId : parentIdList){                    

Attachment attachmentPDF = new Attachment();                    

attachmentPDF.parentId = parentId;                    

attachmentPDF.Name = pdfName+ '.pdf';                    

attachmentPDF.body = Blob.toPDF(pdfContent);

//This creates the PDF content                    

attachmentList.add(attachmentPDF);                

}                

if(attachmentList != null && attachmentList.size()>0)                    

insert attachmentList;            

}         }catch(Exception e)        

{             system.debug('--- got error while creating pdf ---'+e.getMessage());    

}     }     }

  • November 28, 2012
  • Like
  • 0