• chikku
  • NEWBIE
  • 80 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 43
    Questions
  • 34
    Replies
I'm new to Apex. I have JSON data I need to convert to JSON Generator.
Can you please help me out?
Contact app = [select Id, Name from Contact ];
{
  "CustomerID": 0,
  "CustomerType": 1,
  "Name": "callum, john",  (app.Name,app.LastName) like this i need in JSON Generator.
  "BranchID": 1,
  "CustomerAddress": [
    {
      "CustomerAddressID": 0,
      "CustomerID": 0,
      "Address": {
        "Address1": "Test",
        "TownCityID": 41037,
        "CountyID": null,
        "StateID": 41036,
        "CountryID": 4,
        "Country": "Australia"
      },
      "AddressTypeID": 1,
      "DateMovedIn": "11/09/2019",
      "IsPrimary": false
    }
  ],
  "Persons": [
    {
      "PersonID": 0,
      "Title": 1,
      "Gender": 0,
      "ForenamePartOne": "callum",
      "ForenamePartTwo": null,
      "ForenamePartThree": null,
      "Surname": "john",
      "DateOfBirth": "11/09/1970",
      "SocialSecurityNumber": "35",
      "telephone1": "",
      "telephone2": "",
      "telephone3": "6598307315"
    }
  ],
  "CorrespondenceName": "callum, john",
  "DateJoined": "11/09/2019"
}


 
Have JSON body with the external server I need to map that JSON body into contact fields.it is possible?
 I have shown the below example, like this, it is possible as dynamic, no need to hardcode, it should automatically insert the contact into the external server.

it is possible?
List<Contact> con = [Select Id, Name From Contact]; 

'{'+
 ' "CustomerID": 0,'+
  '"CustomerType": 1,'+
  '"Name":  "con.Name , con.Name",'+ 
 ' "BranchID": 1,'+
 '"CustomerAddress": ['+
   ' {'+ 
     ' "CustomerAddressID": 0,'+
     ' "CustomerID": 0,'+
      '"Address": {'+
       ' "Address1": "con.Name",'+
       ' "TownCityID": con.billinAddress,'+
       ' "CountyID": null,'+
        '"StateID": 41036,'+
        '"CountryID": 4,'+

 
I have got a response from API I need to store particular data into a variable and to use.
I need to store token values in a variable with is JSON.
User-added image
public class QueueAbacusAPI {
    private static String accessToken;

 @InvocableMethod(label='Abacus' description='Getting customer info from Abacus' )
    
     public static void abacuStagingsapi( )
    {
        abacuStagingsapiFuture1( );
    }
    
 
    public static void  abacuStagingsapiFuture1( )
    { 
      
         string body= '{'+
   ' "username": "administrator  ",'+
   ' "password": "whatever",'+
'    "deviceId": "a12bc"'+
'}';
               
             
    
Http http = new Http();
HttpRequest request = new HttpRequest();
HttpResponse res = new HttpResponse();

request.setEndpoint(endpointurl);// update endpoint url
            
request.setMethod('POST');
request.setHeader('Accept','application/json');
request.setHeader('Content-Type', 'application/json; charset=utf-8');   

request.setBody(body);
 
     
HttpResponse response= http.send(request);
    

           
// Parse the JSON response
try {
    res = http.send(request);

    if (res.getStatusCode() == 200) {
      
    
           
        System.debug('Success!');
    } else {
        
        System.debug('HTTP : ' + res.getStatusCode());
    }
    System.debug(res.getBody());
} catch(System.CalloutException e) {
    System.debug('Callout error: '+ e);
}
          
 
}
}

 
Hi,
 I have an object called log__c in that fields have Description__c, Action__c
and Lookup with Contact object, when I change phone field of contact object then in  log__c object of  Description__c field  should be inserted that old phone is 123 and new phone  456 like that I need

I have used the below code but is updating multiple times and the description empty like below

User-added image
trigger oldvalue on Contact (after insert,after update) {   
    Set<Id> lstLogId = new Set<Id>();
    String OlpPhone;
    String NewPhone;
 	list<Log__c> logtimeUpdate = new list<Log__c>();
   if(trigger.IsAfter && (trigger.IsUpdate || trigger.IsInsert)){
       for(Contact Con : trigger.new ){
           if(con.Phone != Trigger.oldMap.get(con.Id).Phone){
               OlpPhone = Trigger.oldMap.get(con.Id).Phone;
               NewPhone = con.Phone;
               lstLogId.Add(Con.Id); 
           }
       }
   }
      list<Log__c> logtime =   [Select id,Name,Contact ,Description__c,Action__c FROM Log__c Where Contact In:lstLogId ];
    For(Log__c l : logtime){
        l.Action__c ='check';       
     l.Description__c ='\n phone number old value ='+OlpPhone+  '   New Phone = ' + NewPhone;
        logtimeUpdate.Add(l);
   
    }
    update logtimeUpdate;
}

 
Hi,
 I have an object called log__c in that fields have Description__c, Action__c
with Lookup with Contact object, when I change phone field of contact object then in  log__c object of  Description__c field  should be inserted that old phone is 123 and new phone  456 like that I need
trigger oldvalue on Contact (after insert,after update,  before insert) {   

 Log__c  logtime =new Log__c();
        logtime=[Select id,Name,Contact ,Description__c,Action__c FROM Log__c ];
   if(trigger.isbefore && trigger.isUpdate ){
     for(integer i=0; i<trigger.new.size();i++){
     if(Trigger.New[i].Phone!=Trigger.Old[i].Phone){
        
     logtime.Action__c ='check';       
     logtime.Description__c +='\n phone number old value='+Trigger.Old[i].phone+  '   New  phone ' + Trigger.New[i].phone;
   
              insert logtime;         
     }   }
     }
}

Please help
 
When I track the old value and new value in the trigger, the first value showing has null, I don't know how to void it .. 
I have used if ( Trigger.isbefore  &&  Trigger.isUpdate) also I condition it doesn't work.
 
if ( Trigger.isbefore )
         for(integer i=0; i<trigger.new.size();i++){
        
            if(Trigger.New[i].Decision_Determined__c!=Trigger.Old[i].Decision_Determined__c){
                
                if(Trigger.Old[i].Plaid_Report_JSON__c==null){
                    Trigger.New[i].Plaid_Report_JSON__c='';
                }
              
                Trigger.New[i].Plaid_Report_JSON__c +='\n Decision old value='+Trigger.Old[i].Decision_Determined__c+  ' Decision New value ' + Trigger.New[i].Decision_Determined__c;
                  }
}
    system.debug('-----old value'+Trigger.Old);
    system.debug('-----new value'+Trigger.New);

User-added image
I have created the data table and the last trow should be empty the only the total should display but automatically it assuming like undefined. URL.
I need to set an empty value, any help

User-added image

 
getTransactionWithSummery(dataValues) {
            var totalAmount = 0.00;
            if (dataValues.length > 0) {
                for (var i = 0; i < dataValues.length; i++) {
                    totalAmount += dataValues[i].Amount__c;
                }
              
           dataValues.push({Amount__c: totalAmount.toFixed(2),GuarantorName:'Total'} );
            
           }
            return dataValues;
            
        }



any help ?

it Causing errors while debugging..there any solutions guys.
 
private static  Application__c app{get; private set;}
       public static void   MyController() {
           
           Id id = ApexPages.currentPage().getParameters().get('id');
                  system.debug('--check--'+id);
           try{
                app = (id == null) ? new Application__c() : 
            [SELECT id,Name FROM Application__c WHERE Id = :id];
                
                }catch(System.QueryException e){
            }}
            public static Application__c getapp() {
             return app; 
   }  
 }

 
When I do the process it throws an error on it like this and unable to show merge fields too in pdf.

Error Occurred: An Apex error occurred: System.NullPointerException: Attempt to de-reference a null object

User-added image

 
public class sendAnEmail
{
     
      @InvocableMethod( label='Test' description='sends an email')
       
    public static void sendEmailWithAttachment(List<id> listofQuoteHeader)
    {   
      
        // Application__c applink = [SELECT Id,Name FROM Application__c  ];
        Map<Id, Application__c> quotesMap =  new Map<Id, Application__c>([SELECT id,Contact__r.Email,Contact__r.Name FROM Application__c WHERE Id IN :listofQuoteHeader]);
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
                system.debug('--appID-'+QuoteHeaderid);
               Attachment attachment = new Attachment();      
               Blob b=pref.getContentAsPDF();
               attachment.Body = b;
               attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf';
               attachment.IsPrivate = false;
               attachment.ParentId = QuoteHeaderid;
               attachment.Name='Sign.png';
               insert attachment;
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment();
               attach.setFileName('AttachmentEmailFile.pdf');
               attach.setBody(b);
               semail.setSubject('Quote Issued');
            //  String[] emailIds= new String[]{'abc@gmail.com'}; 
                String[] emailIds= new String[]{quotesMap.get(QuoteHeaderid)?.Contact__r.Email};
               semail.setToAddresses(emailIds);
               semail.setPlainTextBody('Please find the attached quote details');
 semail.setHtmlBody('Hello ' +  + '<br/><br/>Summary report' + contact.Name+'.<br/><br/><a href="'+ URL.getSalesforceBaseUrl().toExternalForm() + '/' + QuoteHeaderid+'">Click Here</a> Please check your Summary report');

               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
                Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
                  system.debug('----'+listofQuoteHeader);
           } 
        
 SendAnEmail.sendAnEmail();// I have call the constructor method in invocable method
    }
    // this method for merge fields
       private static  Application__c app{get; private set;}
       public static void sendAnEmail() {
          
               Id id = ApexPages.currentPage().getParameters().get('id');
                app = (id == null) ? new Application__c() : 
            [SELECT id,Name FROM Application__c WHERE Id = :id];
           }
           
}
<apex:page  controller="sendAnEmail" renderAs="advanced_pdf" applyHtmlTag="false" applyBodyTag="false" standardStylesheets="false"
showHeader="false" sidebar="false">>
   <apex:form >
             You belong to app Name:{!app.Name}
          </apex:form> 
    
     <h1>
    
      hello
    </h1>
  
</apex:page>
please help me out

 
My requirement is I need to add the hyperlink in the pdf attachment in an email.
when they click the links in the email, there should navigate to the current record id. (For example, if I click that link in the email which  I received then that should navigate to contact record page with respective contact id)

It possible guys?
 
I don't know where I made mistake in the apex with process builder help me out
While debugging the error shown in 48 lines of the apex

Error:Error Occurred: An Apex error occurred: System.NullPointerException: Attempt to de-reference a null object
 
public class sendAnEmail
{
    

    @InvocableMethod(label='Test' description='sends an email')
       
    public static void sendEmailWithAttachment(List<id> listofQuoteHeader)
    {   
        
     
        Map<Id, Application__c> quotesMap =  new Map<Id, Application__c>([SELECT id,Contact__r.Email,Contact__r.Name FROM Application__c WHERE Id IN :listofQuoteHeader]);
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
                system.debug('--appID-'+QuoteHeaderid);
               Attachment attachment = new Attachment();      
               Blob b=pref.getContentAsPDF();
               attachment.Body = b;
               attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf';
               attachment.IsPrivate = false;
               attachment.ParentId = QuoteHeaderid;
               attachment.Name='Sign.png';
               insert attachment;
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment();
               attach.setFileName('AttachmentEmailFile.pdf');
               attach.setBody(b);
               semail.setSubject('Quote Issued');
            //    String[] emailIds= new String[]{'abc@gmail.com'}; 
            String[] emailIds= new String[]{quotesMap.get(QuoteHeaderid)?.Contact__r.Email};
               semail.setToAddresses(emailIds);
               
               semail.setPlainTextBody('Please find the attached quote details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
        Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
                  system.debug('----'+listofQuoteHeader);
           } 
        
     SendAnEmail.test();
    }
       public Application__c account{get;set;} 
      
    private static  Application__c account;
     public static void test() {
            system.debug('--check-'+ApexPages.currentPage().getParameters().get('QuoteHeaderid') );
            try{
                 if (account != null) 

        account = [SELECT Id, Name  FROM Application__c 
                  Where Id=:ApexPages.currentPage().getParameters().get('Id')];// i think this part shwoing error while debug
               
    }
            catch (Exception e) {
   
    account = new Application__c();
}
        }
        public static Application__c getAccount() {
        return account;
    }

}

User-added image
  • April 30, 2021
  • Like
  • 0
 I have created apex with process builder while doing process it throws error any help me out.

 Error Occurred: An Apex error occurred: System.NullPointerException: Attempt to de-reference a null object
 
public class sendAnEmail
{
    

    @InvocableMethod(label='Test' description='sends an email')
       
    public static void sendEmailWithAttachment(List<id> listofQuoteHeader)
    {   
        
     
        Map<Id, Application__c> quotesMap =  new Map<Id, Application__c>([SELECT id,Contact__r.Email,Contact__r.Name FROM Application__c WHERE Id IN :listofQuoteHeader]);
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
                system.debug('--appID-'+QuoteHeaderid);
               Attachment attachment = new Attachment();      
               Blob b=pref.getContentAsPDF();
               attachment.Body = b;
               attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf';
               attachment.IsPrivate = false;
               attachment.ParentId = QuoteHeaderid;
               attachment.Name='Sign.png';
               insert attachment;
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment();
               attach.setFileName('AttachmentEmailFile.pdf');
               attach.setBody(b);
               semail.setSubject('Quote Issued');
            //    String[] emailIds= new String[]{'abc@gmail.com'}; 
            String[] emailIds= new String[]{quotesMap.get(QuoteHeaderid)?.Contact__r.Email};
               semail.setToAddresses(emailIds);
               
               semail.setPlainTextBody('Please find the attached quote details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
        Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
                  system.debug('----'+listofQuoteHeader);
           } 
        
     SendAnEmail.sendAnEmail();
    }
      
    private static  Application__c account;
     public static void sendAnEmail() {
            system.debug('--check-'+ApexPages.currentPage().getParameters().get('QuoteHeaderid') );
            try{
        account = [SELECT Id, Name  FROM Application__c 
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
               
    }
            catch (Exception e) {
   
    account = new Application__c();
}
        }
        public static Application__c getAccount() {
        return account;
    }

}

User-added image
  • April 30, 2021
  • Like
  • 0
I have used the constructor method but it throws an error

Error :  Method does not exist or incorrect signature: void sendAnEmail() from the type sendAnEmail
public class sendAnEmail
{
    

    @InvocableMethod(label='Test' description='sends an email')
       
    public static void sendEmailWithAttachment(List<id> listofQuoteHeader)
    {   
        
     
        Map<Id, Application__c> quotesMap =  new Map<Id, Application__c>([SELECT id,Contact__r.Email,Contact__r.Name FROM Application__c WHERE Id IN :listofQuoteHeader]);
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
                system.debug('--appID-'+QuoteHeaderid);
               Attachment attachment = new Attachment();      
               Blob b=pref.getContentAsPDF();
               attachment.Body = b;
               attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf';
               attachment.IsPrivate = false;
               attachment.ParentId = QuoteHeaderid;
               attachment.Name='Sign.png';
               insert attachment;
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment();
               attach.setFileName('AttachmentEmailFile.pdf');
               attach.setBody(b);
               semail.setSubject('Quote Issued');
            //    String[] emailIds= new String[]{'abc@gmail.com'}; 
            String[] emailIds= new String[]{quotesMap.get(QuoteHeaderid)?.Contact__r.Email};
               semail.setToAddresses(emailIds);
               
               semail.setPlainTextBody('Please find the attached quote details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
                  system.debug('----'+listofQuoteHeader);
           } 
        
     SendAnEmail.sendAnEmail();
    }
      
      private final Application__c account;
        public sendAnEmail() {
            system.debug('--check-'+ApexPages.currentPage().getParameters().get('QuoteHeaderid') );
            try{
        account = [SELECT Id, Name  FROM Application__c 
                   WHERE Id = :ApexPages.currentPage().getParameters().get('QuoteHeaderid')];
               
    }
            catch (Exception e) {
    // add your message to the user or
    account = new Application__c();
}
        }
        public Application__c getAccount() {
        return account;
    }

}

User-added image

 
  • April 30, 2021
  • Like
  • 0
  1. I have the Application__c object with the lookup contact object.
  2. I need to show the Contact name and application Name in pdf which I have created
  3. I have used the Invocable method for sending emails with pdf...
  4. when I do the process it throws an error Like this below:
Error Occurred: common.apex.runtime.impl.ExecutionException: List has no rows for assignment to SObject

But now I unable to show any merged field on my pdf page. There is any resolved solution?
<apex:page controller="sendAnEmail" renderAs="pdf">
   <apex:form >
           You belong to Contact Name:{!account.name} 
             
    </apex:form> 
  <h1>
      hello
    </h1>
</apex:page>
 
public class sendAnEmail
{
    

    @InvocableMethod(label='Test' description='sends an email')
       
    public static void sendEmailWithAttachment(List<id> listofQuoteHeader)
    {   
        
     
        Map<Id, Application__c> quotesMap =  new Map<Id, Application__c>([SELECT id,Contact__r.Email FROM Application__c WHERE Id IN :listofQuoteHeader]);
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
               
               Attachment attachment = new Attachment();      
               Blob b=pref.getContentAsPDF();
               attachment.Body = b;
               attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf';
               attachment.IsPrivate = false;
               attachment.ParentId = QuoteHeaderid;
               attachment.Name='Sign.png';
               insert attachment;
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment();
               attach.setFileName('AttachmentEmailFile.pdf');
               attach.setBody(b);
               semail.setSubject('Quote Issued');
            //    String[] emailIds= new String[]{'abc@gmail.com'}; 
            String[] emailIds= new String[]{quotesMap.get(QuoteHeaderid)?.Contact__r.Email};
               semail.setToAddresses(emailIds);
               
               semail.setPlainTextBody('Please find the attached quote details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
              // Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
                  system.debug('----'+listofQuoteHeader);
           } }
      
      private final Application__c account;
        public sendAnEmail() {
            system.debug('---'+ApexPages.currentPage().getParameters().get('id') );
        account = [SELECT Id, Name  FROM Application__c 
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }
        public Application__c getAccount() {
        return account;
    }

}

User-added image
  • April 30, 2021
  • Like
  • 0
I Am stuck with an error I have created an apex with process bulder.
If I run the process it throws an error.

Error Occurred: common.apex.runtime.impl.ExecutionException: List has no rows for assignment to SObject
 
public class sendAnEmail
{
    

    @InvocableMethod(label='Test' description='sends an email')
       
    public static void sendEmailWithAttachment(List<id> listofQuoteHeader)
    {   
        Map<Id, Application__c> quotesMap =  new Map<Id, Application__c>([SELECT id,Contact__r.Email FROM Application__c WHERE Id IN :listofQuoteHeader]);
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
               
               Attachment attachment = new Attachment();      
               Blob b=pref.getContentAsPDF();
               attachment.Body = b;
               attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf';
               attachment.IsPrivate = false;
               attachment.ParentId = QuoteHeaderid;
               attachment.Name='Sign.png';
               insert attachment;
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment();
               attach.setFileName('AttachmentEmailFile.pdf');
               attach.setBody(b);
               semail.setSubject('Quote Issued');
            //    String[] emailIds= new String[]{'abc@gmail.com'}; 
            String[] emailIds= new String[]{quotesMap.get(QuoteHeaderid)?.Contact__r.Email};
               semail.setToAddresses(emailIds);
               
               semail.setPlainTextBody('Please find the attached quote details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
               Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
               
           } }
      
      private final Application__c account;
        public sendAnEmail() {
        account = [SELECT Id, Name  FROM Application__c 
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }
        public Application__c getAccount() {
        return account;
    }

}

There is any resolved answer
 
  • April 30, 2021
  • Like
  • 0
  1. I have the Application__c object with the lookup contact object.
  2. I need to show the Contact name and application Name in pdf which I have created
  3. I have used apex controller for merged class it doesn't work
But now I unable to show any merged field on my pdf page. There is any resolved solution? it may help others too.
 
<apex:page renderAs="PDF" >
    <h1 >Congratulations </h1 >
Name:Application__c.Contact__r.Nam
 
 </apex:page>
 
public class sendAnEmail
{
    @InvocableMethod(label='Test' description='sends an email')
    public static void sendEmailWithAttachment(List<id> listofQuoteHeader)
    {   
        Map<Id, Application__c> quotesMap =  new Map<Id, Application__c>([SELECT id,Contact__r.Email FROM Application__c WHERE Id IN :listofQuoteHeader]);
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
               
               Attachment attachment = new Attachment();      
               Blob b=pref.getContentAsPDF();
               attachment.Body = b;
               attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf';
               attachment.IsPrivate = false;
               attachment.ParentId = QuoteHeaderid;
               attachment.Name='Sign.png';
               insert attachment;
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment();
               attach.setFileName('AttachmentEmailFile.pdf');
               attach.setBody(b);
               semail.setSubject('Quote Issued');
            //    String[] emailIds= new String[]{'abc@gmail.com'}; 
            String[] emailIds= new String[]{quotesMap.get(QuoteHeaderid)?.Contact__r.Email};
               semail.setToAddresses(emailIds);
               
               semail.setPlainTextBody('Please find the attached quote details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
               Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
           }
       
            }
  }

 
  • April 29, 2021
  • Like
  • 0
I have Application__c with Look Contact, I need to show Contact name and Application Name in Pdf attachment as dynamic.
public class sendAnEmail
{
    @InvocableMethod(label='Test' description='sends an email')
    public static void sendEmailWithAttachment(List<id> listofQuoteHeader)
    {   
        Map<Id, Application__c> quotesMap =  new Map<Id, Application__c>([SELECT id,Contact__r.Email FROM Application__c WHERE Id IN :listofQuoteHeader]);
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
               
               Attachment attachment = new Attachment();      
               Blob b=pref.getContentAsPDF();
               attachment.Body = b;
               attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf';
               attachment.IsPrivate = false;
               attachment.ParentId = QuoteHeaderid;
               attachment.Name='Sign.png';
               insert attachment;
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment();
               attach.setFileName('AttachmentEmailFile.pdf');
               attach.setBody(b);
               semail.setSubject('Quote Issued');
            //    String[] emailIds= new String[]{'abc@gmail.com'}; 
            String[] emailIds= new String[]{quotesMap.get(QuoteHeaderid)?.Contact__r.Email};
               semail.setToAddresses(emailIds);
               
               semail.setPlainTextBody('Please find the attached quote details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
               Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
           }
       
            }
  }
 
<apex:page renderAs="PDF" >
	<h1 >Congratulations </h1 >
Name:Application__c.Contact__r.Name
 
 </apex:page>

 
  • April 29, 2021
  • Like
  • 0
I need to show the Contact name with Lookup with Application in pdf attachment..
public class sendAnEmail
{
    @InvocableMethod(label='Test' description='sends an email')
    public static void sendEmailWithAttachment(List<id> listofQuoteHeader)
    {   
        Map<Id, Application__c> quotesMap =  new Map<Id, Application__c>([SELECT id,Contact__r.Email FROM Application__c WHERE Id IN :listofQuoteHeader]);
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
               
               Attachment attachment = new Attachment();      
               Blob b=pref.getContentAsPDF();
               attachment.Body = b;
               attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf';
               attachment.IsPrivate = false;
               attachment.ParentId = QuoteHeaderid;
               attachment.Name='Sign.png';
               insert attachment;
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment();
               attach.setFileName('AttachmentEmailFile.pdf');
               attach.setBody(b);
               semail.setSubject('Quote Issued');
            //    String[] emailIds= new String[]{'abc@gmail.com'}; 
            String[] emailIds= new String[]{quotesMap.get(QuoteHeaderid)?.Contact__r.Email};
               semail.setToAddresses(emailIds);
               
               semail.setPlainTextBody('Please find the attached quote details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
               Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
           }
       
            }
  }

VF page
 
<apex:page standardController="Application__c" renderAs="pdf">
 <h1>
     Application__c.Contact__r.Name
    </h1>
</apex:page>

 
  • April 29, 2021
  • Like
  • 0
I need to send a dynamic setToAddresses email id with the contact I choose
public class sendAnEmail
{
    
    @InvocableMethod(label='Test' description='sends an email')
    public static void sendEmailWithAttachment(List<id> listofQuoteHeader)
    {
     List<Contact> Con = [SELECT Id, Email FROM Contact ];
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
               
               Attachment attachment = new Attachment();      
               Blob b=pref.getContentAsPDF();
               attachment.Body = b;
               attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf';
               attachment.IsPrivate = false;
               attachment.ParentId = QuoteHeaderid;
               insert attachment;
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment();
               attach.setBody(pref.getContentAsPDF());
               semail.setSubject('Quote Issued');
       String[] emailIds= new String[]{'abc@gmail.com'}; // I need this part has  dynamic based on contact email id
               semail.setToAddresses(emailIds);
               
               semail.setPlainTextBody('Please find the attached quote details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
               Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
           }
    }
 
}

 
  • April 28, 2021
  • Like
  • 0
  1. I have created a Vf page and apex to send PDF attachments in email.
  2. I have object Apple__c with Lookup Contact
  3. When I create a new Apple record and Particular contact with Email, then email should send to the contact which I have selected.
 
Now I have developed static, I need in dynamic.
public class sendAnEmail
{
    
    @InvocableMethod(label='Test' description='sends an email')
    public static void sendEmailWithAttachment(List<id> listofQuoteHeader)
    {
     List<Contact> Con = [SELECT Id, Email FROM Contact ];
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
               
               Attachment attachment = new Attachment();      
               Blob b=pref.getContentAsPDF();
               attachment.Body = b;
               attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf';
               attachment.IsPrivate = false;
               attachment.ParentId = QuoteHeaderid;
               insert attachment;
               
               Messaging.SingleEmailMessage semail= new 
                Messaging.SingleEmailMessage();
               Messaging.EmailFileAttachment attach= new 
                   Messaging.EmailFileAttachment();
               attach.setBody(pref.getContentAsPDF());
               semail.setSubject('Quote Issued');
              String[] emailIds= new String[]{'abc@gmail.com'}; // I need this part has  
                 dynamic based on contact email id i choosed
               semail.setToAddresses(emailIds);
               
               semail.setPlainTextBody('Please find the attached quote details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
               Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
           }
    }
 
}


 
  • April 28, 2021
  • Like
  • 0
Have JSON body with the external server I need to map that JSON body into contact fields.it is possible?
 I have shown the below example, like this, it is possible as dynamic, no need to hardcode, it should automatically insert the contact into the external server.

it is possible?
List<Contact> con = [Select Id, Name From Contact]; 

'{'+
 ' "CustomerID": 0,'+
  '"CustomerType": 1,'+
  '"Name":  "con.Name , con.Name",'+ 
 ' "BranchID": 1,'+
 '"CustomerAddress": ['+
   ' {'+ 
     ' "CustomerAddressID": 0,'+
     ' "CustomerID": 0,'+
      '"Address": {'+
       ' "Address1": "con.Name",'+
       ' "TownCityID": con.billinAddress,'+
       ' "CountyID": null,'+
        '"StateID": 41036,'+
        '"CountryID": 4,'+

 
Hi,
 I have an object called log__c in that fields have Description__c, Action__c
with Lookup with Contact object, when I change phone field of contact object then in  log__c object of  Description__c field  should be inserted that old phone is 123 and new phone  456 like that I need
trigger oldvalue on Contact (after insert,after update,  before insert) {   

 Log__c  logtime =new Log__c();
        logtime=[Select id,Name,Contact ,Description__c,Action__c FROM Log__c ];
   if(trigger.isbefore && trigger.isUpdate ){
     for(integer i=0; i<trigger.new.size();i++){
     if(Trigger.New[i].Phone!=Trigger.Old[i].Phone){
        
     logtime.Action__c ='check';       
     logtime.Description__c +='\n phone number old value='+Trigger.Old[i].phone+  '   New  phone ' + Trigger.New[i].phone;
   
              insert logtime;         
     }   }
     }
}

Please help
 
When I track the old value and new value in the trigger, the first value showing has null, I don't know how to void it .. 
I have used if ( Trigger.isbefore  &&  Trigger.isUpdate) also I condition it doesn't work.
 
if ( Trigger.isbefore )
         for(integer i=0; i<trigger.new.size();i++){
        
            if(Trigger.New[i].Decision_Determined__c!=Trigger.Old[i].Decision_Determined__c){
                
                if(Trigger.Old[i].Plaid_Report_JSON__c==null){
                    Trigger.New[i].Plaid_Report_JSON__c='';
                }
              
                Trigger.New[i].Plaid_Report_JSON__c +='\n Decision old value='+Trigger.Old[i].Decision_Determined__c+  ' Decision New value ' + Trigger.New[i].Decision_Determined__c;
                  }
}
    system.debug('-----old value'+Trigger.Old);
    system.debug('-----new value'+Trigger.New);

User-added image
I have created the data table and the last trow should be empty the only the total should display but automatically it assuming like undefined. URL.
I need to set an empty value, any help

User-added image

 
getTransactionWithSummery(dataValues) {
            var totalAmount = 0.00;
            if (dataValues.length > 0) {
                for (var i = 0; i < dataValues.length; i++) {
                    totalAmount += dataValues[i].Amount__c;
                }
              
           dataValues.push({Amount__c: totalAmount.toFixed(2),GuarantorName:'Total'} );
            
           }
            return dataValues;
            
        }



any help ?
My requirement is I need to add the hyperlink in the pdf attachment in an email.
when they click the links in the email, there should navigate to the current record id. (For example, if I click that link in the email which  I received then that should navigate to contact record page with respective contact id)

It possible guys?
 
I Am stuck with an error I have created an apex with process bulder.
If I run the process it throws an error.

Error Occurred: common.apex.runtime.impl.ExecutionException: List has no rows for assignment to SObject
 
public class sendAnEmail
{
    

    @InvocableMethod(label='Test' description='sends an email')
       
    public static void sendEmailWithAttachment(List<id> listofQuoteHeader)
    {   
        Map<Id, Application__c> quotesMap =  new Map<Id, Application__c>([SELECT id,Contact__r.Email FROM Application__c WHERE Id IN :listofQuoteHeader]);
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
               
               Attachment attachment = new Attachment();      
               Blob b=pref.getContentAsPDF();
               attachment.Body = b;
               attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf';
               attachment.IsPrivate = false;
               attachment.ParentId = QuoteHeaderid;
               attachment.Name='Sign.png';
               insert attachment;
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment();
               attach.setFileName('AttachmentEmailFile.pdf');
               attach.setBody(b);
               semail.setSubject('Quote Issued');
            //    String[] emailIds= new String[]{'abc@gmail.com'}; 
            String[] emailIds= new String[]{quotesMap.get(QuoteHeaderid)?.Contact__r.Email};
               semail.setToAddresses(emailIds);
               
               semail.setPlainTextBody('Please find the attached quote details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
               Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
               
           } }
      
      private final Application__c account;
        public sendAnEmail() {
        account = [SELECT Id, Name  FROM Application__c 
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }
        public Application__c getAccount() {
        return account;
    }

}

There is any resolved answer
 
  • April 30, 2021
  • Like
  • 0
I need to show the Contact name with Lookup with Application in pdf attachment..
public class sendAnEmail
{
    @InvocableMethod(label='Test' description='sends an email')
    public static void sendEmailWithAttachment(List<id> listofQuoteHeader)
    {   
        Map<Id, Application__c> quotesMap =  new Map<Id, Application__c>([SELECT id,Contact__r.Email FROM Application__c WHERE Id IN :listofQuoteHeader]);
           for(Id QuoteHeaderid :listofQuoteHeader)
           {
               PageReference pref= page.PDFGEN;
               pref.getParameters().put('id',(Id)QuoteHeaderid);
               pref.setRedirect(true);
               
               Attachment attachment = new Attachment();      
               Blob b=pref.getContentAsPDF();
               attachment.Body = b;
               attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf';
               attachment.IsPrivate = false;
               attachment.ParentId = QuoteHeaderid;
               attachment.Name='Sign.png';
               insert attachment;
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment();
               attach.setFileName('AttachmentEmailFile.pdf');
               attach.setBody(b);
               semail.setSubject('Quote Issued');
            //    String[] emailIds= new String[]{'abc@gmail.com'}; 
            String[] emailIds= new String[]{quotesMap.get(QuoteHeaderid)?.Contact__r.Email};
               semail.setToAddresses(emailIds);
               
               semail.setPlainTextBody('Please find the attached quote details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
               Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
           }
       
            }
  }

VF page
 
<apex:page standardController="Application__c" renderAs="pdf">
 <h1>
     Application__c.Contact__r.Name
    </h1>
</apex:page>

 
  • April 29, 2021
  • Like
  • 0
1.I am trying to come up with a Pdf Attachment in Email with the process builder.
2.In the Contact object, I have a Picklist field called Status__c values YES and No.
3.If Status__c is changed to Yes the email with pdf attachment to the particular contact.

 have Pdf coding, I need a PDF attachment in apex with process builder coding needed. Can help me out:(

PDF coding
 
<apex:page standardController="Account" renderAs="pdf">
 
Hey, the Account name is {!account.Name}
 
</apex:page>

 
  • April 28, 2021
  • Like
  • 0
My requirement is I need send dynamic Pdf Attachment-based the Contact Name and Email, in Contact object I have a field called Status__c(picklist)values are new and signed when status__c is changed to new the email should send automatically to the user with email id with Pdf Attachment.IN process builder can we achieve?

Can you please help me out am new to salesforce? This code i have tried but unable to work... I need pfd with contact name,mail,and contact information on PDF ,when status__c changed to new automatic email should send with PDF Attachment, can you please help.i don't know how to set the condition and send pdf attachments in email

 
Vfpage

  <apex:page renderAs="PDF" > 

<h1 >Congratulations </h1 >
  This is your new Page 
 </apex:page>
 
public class SendVF_Email_InvocableMethod {
@InvocableMethod
public static void sendEmail(List<Id> lstId){
    List<String> EmailIds = 'ilovenagpur@gmail.com'.split(',');

    PageReference ref = Page.PDF_DEMO;
    Blob b = ref.getContentAsPDF();

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

    Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
    efa1.setFileName('attachment_WORK.pdf');
    efa1.setBody(b);

    String addresses;
    email.setSubject( 'Check VF From PB' +String.valueOf(DateTime.now()));
    email.setToAddresses( EmailIds  );
    email.setPlainTextBody('Hey there, I am an email Body');
    email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1});
    Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
}}

 
  • April 27, 2021
  • Like
  • 0
I want to update attachment name as opportunity name... Please share the code