• Doolk star220
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello Developers and Community Leaders, 
                                  I have got a scenario but not getting any path how may i could proceed on this and suggestion or thought would be apprechiable.
trigger ddi_Account_Trigger on Account (before insert) {
    switch on Trigger.operationType {
        when  Before_Insert{
             //List<Account> accountList =[SELECT Id, Name, MultiSelect_State__c,Account_Email__c, createddate FROM Account Order By createddate Desc Limit 1];
            ddiAccountTriggerHandler.getDDIAccount( trigger.new );
        }
    }
}



===========================================================================


public class ddiAccountTriggerHandler {
    
    public static void getDDIAccount(List<Account> accountList){
        //List<Account> accountList =[SELECT Id, Name, MultiSelect_State__c,Account_Email__c, createddate FROM Account Order By createddate Desc Limit 1];
        if (accountList != Null && accountList.size()>0){
            System.debug('@@@' +accountList);
            for(Account ac : accountList){
                System.debug('@@@'+ac.MultiSelect_State__c);
                List<String> States = ac.MultiSelect_State__c.split(';');
                System.debug('@@@' +States);
                System.debug('@@@'+States.size());
                for(integer i = 0; i < states.size(); i++){
                    String state = states[i];
                    String email = ac.Account_Email__c;
                    //Url u = https://iaaicsr--parvathy.my.salesforce.com/sfc/p/2i0000000rP7/a/2i0000009JVE/vIRIVQqXM1Ib31jKcU6kFD1qWryC2jPP7yNTfYwErYs;
                    
                    switch on state{
                        when 'Maharashtra'{
                           // Blob b = https://iaaicsr--sahil.my.salesforce.com/one/one.app#/alohaRedirect/08123000000BN09?isdtp=p1;
                           
                            System.debug('@@@Hurray Maharashtra' );
                            ddiAccountEmailSend.sendEmail(state, email);
                            
                        }
                        when 'Gujarat'{
                            System.debug('@@@Hurray Gujarat');
                            ddiAccountEmailSend.sendEmail(state, email);
                            
                        }
                        when 'Tamil Nadu'{
                            System.debug('@@@Hurray Tamil Nadu');
                            ddiAccountEmailSend.sendEmail(state, email);
                            
                        }
                        when 'Himachal'{
                            System.debug('@@@Hurray Himachal');
                            ddiAccountEmailSend.sendEmail(state, email);
                            
                        }
                        
                    }
                    
                }
                
                
            }
            
        }
        
    }
}


=================================================================


public class ddiAccountEmailSend {
    public static void sendEmail(String state, String email, String u){
        // creating an instance of SingleEmailMessage
        Messaging.SingleEmailMessage objEmail = new Messaging.SingleEmailMessage();
        
        // Setting the body for the email
        objEmail.setPlainTextBody('This is a Plain Text');
        
        // Setting the Subject for the email
        objEmail.setSubject('Interested States Related Pdf');
        //
        // Setting up the Address to whom we needed to send an Email
        objEmail.setToAddresses(new String[] {email});
        
        Messaging.EmailFileAttachment[] attachments  = new Messaging.EmailFileAttachment[1];
        
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        
        //Getting an Attachments from the Static Resource
        List<StaticResource> objPDF = [Select body, name from StaticResource where Name =: state];
        
        // setting the body of an attachment
        attachment.setBody(objPDF[0].body); 
        
        // setting up the file name of an attachment
        attachment.setFileName(objPDF[0].name +'.pdf');
        
        //Assinging the single attachment to a list  
        attachments[0] = attachment;
        
        objEmail.setFileAttachments( attachments);
        
        
        // Finally Send the Email
        
        List<Messaging.Sendemailresult> objER = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {objEmail});
        
        if (!objER[0].isSuccess()){
            // Error handling;
        }
        
        
        
        
    }
    
    
}

So this code basically sending the sending the email in which some respective pdf is been get attached depending on the state multiselect picklist value selected while creating an account .. 
Any suggestion on how could we place the url for thr document and that url only must be sent to that account email