• arti rathod
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
This is my below code  on insertion of lead record community guest user unable to open pdf attchment although from backend when i am passing lead id its working fine --
public static void sendEmail(Id leadId,String leadStatus){
        List<Messaging.SingleEmailMessage> emailList = new List<Messaging.SingleEmailMessage>();
        EmailTemplate emailTemp = new EmailTemplate();
        String emailTempDevName;
        if(leadStatus == System.Label.PartExp_LeadStatusOpen){
            emailTempDevName= System.Label.PartExp_EmailTempName;
        }else if(leadStatus == System.Label.PartExp_LeadStatusRejected){
            emailTempDevName= System.Label.PartExp_RejectedEmailTempName;
        }
        emailTemp =[Select id, Subject, Body From EmailTemplate Where DeveloperName =:emailTempDevName];
       OrgWideEmailAddress orgWideEmailAddress = [SELECT Id,DisplayName FROM OrgWideEmailAddress WHERE DisplayName =: System.Label.PartExp_OWDForPartnerEmail Limit 1];
       
    Lead leadRecord = [SELECT Id, FirstName, LastName, Email FROM Lead WHERE Id = :leadId  Limit 1];
       // PageReference customPage = Page.PartExp_PrintViewRegistrationForm;
        PageReference customPage = new pagereference('/apex/PartExp_PrintViewRegistrationForm?id='+leadId);
        
        customPage.getParameters().put('id', leadRecord.Id);
        System.debug('leadId:'+leadId);
        
        Blob pdfBlob;
       
        try {
            pdfBlob = customPage.getContentAsPDF();
             System.debug('pdfBlob'+pdfBlob);
        } catch (VisualforceException e) {
             pdfBlob = Blob.valueOf('data');
             System.debug('error dedatil' + e.getStackTraceString());
           System.debug('Error generating PDF: ' + e.getMessage());
          // return;
           }
        
      
         Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
         attach.setFileName('LeadDetails.pdf');
         attach.setBody(pdfBlob);
         attach.Body = pdfBlob;
         System.debug('attach#'+attach);
         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
         mail.setTemplateId(emailTemp.Id);
         mail.setTargetObjectId(leadId);
       mail.setOrgWideEmailAddressId(orgWideEmailAddress.Id);
         mail.setFileAttachments(new List<Messaging.EmailFileAttachment>{ attach });
         emailList.add(mail);
        
        if(!emailList.isEmpty()){
            Messaging.sendEmail(emailList);
        }
For example, data from the Account record should be copied to the specified record of contact. 

Admin should have a screen where he should be able to map the fields to be copied from one object to another. Admin can select any object as the source object and target object available from the Salesforce Org.  The mapping will be saved in the backend and used in the code to copy the data.



How to impliment this?





 
I have written a lightning component to display the picklist values.But i want to display data in tables based on object selected in the picklist.
User-added image
This is the reference image.Please help me how to achieve this?
Hi friends,

I have a custom object 'MyFixOrder' which has 2 Record Types 'AccountMyOrder' and 'ContactMyOrder'.
I have another custom object 'MyPartOrder' which also has 2 Record Types 'AccountMyOrder' and 'ContactMyOrder'.

Fields for both Objects are Same.
- Name(Text)
- Date of Start(Date)
- Date of End(Date)
- Active(Checkbox)
- OrderType(Text)
Suppose I have two 2 records in 'MyFixOrder' object of 'AccountMyOrder' and 'ContactMyOrder' RecordType
then i have to copy those records in 'MyPartOrder' object with their record types.

Any help would be greatly appreciated.
Hi,
Below is my code for the trigger for  duplicate prevention on the account . It works well, but if I have 50k records this impacts scalability and not feasible.
So please any one can help to code in better way.
thanks in advance.
trigger AccountDuplicate on Account (before insert) {
 List<Account> dup = new List<Account>();
 dup = [Select id, Name from Account];
 for(Account a:Trigger.New){
 for(Account a1:dup){
 if(a.Name==a1.Name){
 a.Name.addError('Name already Exist ');
 }
 }
 }   
 }