• sfdc G 9
  • NEWBIE
  • 40 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 16
    Questions
  • 2
    Replies
Description: When closing a case an email should trigger. need test class for this.

public class SendCasePrintableViewAsPDF extends AbstractTriggerHandler {
    public override void afterUpdate() {
        
        Set<Id> closedCaseIds = new Set<Id>();
        Map<Id, Case> oldCaseMap = (Map<Id, Case>)Trigger.oldMap;
        
        // Retrieve the custom label value containing the desired Record Type Developer Names.
    String customLabelValue = Label.CaseArchive_RecordType;
    List<String> desiredRecordTypes = customLabelValue.split(';');
        
        for (Case updatedCase : (List<Case>)Trigger.New) {
            system.debug('updatedCase.RecordType.DeveloperName===='+updatedCase.RecordTypeId);
            system.debug(updatedCase.RecordTypeid);
            Case oldCase = oldCaseMap.get(updatedCase.Id);
            if(updatedCase.IsClosed && !oldCase.IsClosed && desiredRecordTypes.contains(updatedCase.RecordTypeId)){
                system.debug('insideRT=======');
                closedCaseIds.add(updatedCase.Id);
            }
        }
        sendPDF(closedCaseIds);
    }

    @future(callout=true)
    private static void sendPDF(Set<Id> closedCaseIds) {
        // Define the email address where the PDF will be sent
        String recipientEmail = Label.CaseArchive_Email;
        
        // Query the necessary Case data and related records outside the loop
        List<Case> closedCases = [SELECT Id, Subject, Casenumber, origin, owner.name, ownerid, Description,Account.Name, Contact.Name
                                  FROM Case WHERE Id IN :closedCaseIds];

        // Generate the PDF for each closed case and send the email
        for (Case closedCase : closedCases) {
            // Generate the PDF content
            PageReference printablePage = Page.SendCasePrintableViewAsPDF; // Visualforce Page
            printablePage.getParameters().put('id', closedCase.Id);
            Blob pdfBlob;
            try {
                pdfBlob = printablePage.getContentAsPDF();
            } catch (VisualforceException e) {
                // Error handling for Vf page
                System.debug('Error generating PDF: ' + e.getMessage());
                continue;
            }

            // Create and send the email
            List<Messaging.SingleEmailMessage> emailMessagesList = new List<Messaging.SingleEmailMessage>(); 
            Messaging.SingleEmailMessage emailMessage = new Messaging.SingleEmailMessage();
            emailMessage.setToAddresses(new String[] { recipientEmail });
            emailMessage.setSubject(closedCase.CaseNumber + '-' + closedCase.Subject);
            String plainTextBody = '';
            plainTextBody += 'Case Number : '+ closedCase.CaseNumber +'\n';              
            plainTextBody += 'Case Origin : '+ closedCase.origin +'\n';
            plainTextBody += 'Case Owner : '+ closedCase.Owner.Name +'\n';
            plainTextBody += 'Subject : '+ closedCase.Subject +'\n';
            plainTextBody += 'Description : '+ closedCase.Description +'\n';
            plainTextBody += 'Contact Name : '+ closedCase.Contact.Name +'\n';
            plainTextBody += 'Account Name : '+ closedCase.Account.Name +'\n';
            emailMessage.setPlainTextBody(plainTextBody);
            emailMessage.setFileAttachments(new Messaging.EmailFileAttachment[] {
                new Messaging.EmailFileAttachment()
            });
            emailMessage.getFileAttachments()[0].setFileName('Case Number: ' + closedCase.CaseNumber + '.pdf');
            emailMessage.getFileAttachments()[0].setBody(pdfBlob);

            // Send the email
            emailMessagesList.add(emailMessage);
            Messaging.sendEmail(emailMessagesList, False);
            //Messaging.sendEmail(new Messaging.SingleEmailMessage[] { emailMessage });
        }
    }
}
Hi All, 
I have a requirement to implement 
Pre-Chat Form URL. They have provided me an URL, Any idea?

Regards,
Depak
I need to create a recurring task, but in task triggers I am updating activity date if it is null.

i am getting an error message Error: You cannot insert or update ActivityDate for a recurring task.

Is there any way to avoid this and create task??
Hi All,

I have a before update Trigger and it is sending two emails when changing a case owner. Kindly help me It should send only once.
 
trigger sendEmailOnOwnerChange on Case (before update)
{
    Map<Id, Case> map_OldCaseValues = new Map<Id, Case>();
    Map<Id, Case> map_NewCaseValues = new Map<Id, Case>();

    String currentUserId = UserInfo.getUserId();
    
    Boolean sendMail = false;
    
    Boolean emailToNewCaseOwner;
    Boolean isEmailToOldAndNewOwner = false;
    
    system.debug('outsideloop'+Trigger.New.Size());
    for(integer i =0; i<Trigger.New.Size(); i ++)
    {
        system.debug('insideloop'+Trigger.New.Size());
        if(Trigger.New[i].OwnerId != Trigger.oldMap.get(Trigger.new[i].id).OwnerId)
        {        
           /*Requirement 443*/
           Trigger.New[i].Number_of_times_Flash_Displayed__c = 0;
           if(Trigger.oldMap.get(Trigger.new[i].id).OwnerId!= currentUserId && Trigger.new[i].OwnerId == currentUserId )
           {
               map_NewCaseValues.put(Trigger.New[i].Id,Trigger.New[i]); 
               system.debug('====map1'+map_NewCaseValues);
               map_OldCaseValues.put(Trigger.oldMap.get(Trigger.new[i].id).Id,Trigger.oldMap.get(Trigger.new[i].id)); 
               emailToNewCaseOwner = false;
               system.debug('====boolean1'+emailToNewCaseOwner);
           }
           
        }
    }
    
    if(!map_NewCaseValues.isEmpty())
    {
        new sendEmailOnOwnerChangeController().notificationStatusForInsert(map_NewCaseValues,map_OldCaseValues,emailToNewCaseOwner,isEmailToOldAndNewOwner);                
    }
I put debuglog and verified it triggered two times
Thanks In Advance,
Deepak​
HI All,
I have two custom object custom1__c and custom2__c.
on custom1__c i have a field field1__c and
I need to update the value of field1__c to the custom__2's field field2__C.

Could anyone please help.

Thanks in Advance,
Deepak 
Hi All,
I have two case fields Request For and  GBO Type. currently after saving a field Request for is showing as request for but it should be mapped to GBO Type.

User-added image
This request for field should be changed to GBO Type.

Thanks in Advance please help me on this.

Regards,
Deepak
HI All,
I have Text area as below, I need to alling text to left, I can see some space in left, I want to remove that.
Kindly help.
User-added image

 
<table style="padding-left:180px;">
<tr>
<td>
<textarea readonly="readonly" style = "resize:none; max-height:100px; min-height:100px; resize:horizontal; max-width:845px; min-width:845px;">
                CST MUST include detailed notes to explain all SEV increases 
                
                What is the business Impact:

                Please describe the issue with as much detail as possible including specific error messages:

</textarea>
</td>
</tr>
</table>
Thanks in Advance,
Deepak
 
Is there any way to remove hyperlink for Frorm  Address?
User-added image
<apex:column value="{!email.FromAddress}" headerValue=" From Address"/>
Thanks in Advance,
Deepak
 
Hi All,
I need to remove hyperlink for the created by fields.
User-added image
Below is the code, I did not mention any command link for this
<apex:column value="{!email.CreatedById}" headerValue=" Created By"/>

Kindly help me on this.
Regards,
Deepak
Hi All,
why opporunity owner gets added two times in opportunity team while creating a new opportunity, 
Kindly help me on this.

Regards,
Deepak
HI All,
how we can move notes and attachments from one account to another account through code?
Kindly help me on this.

Regards,
Deepak
Hi All,
When a new User is being created and the Country = USA, the Currency field should default to USD.
we dont have a country field we have only address field.
Kindly help me to write the below trigger.
 
trigger Default_Currency_toUSD On User (before insert) 
{  
 public address add;
   for(User objUser: Trigger.new)
 add=objUser.Address;
    If(add.contains('USA'))
    {
    
    //User.DefaultCurrencyIsoCode='USD';
    
    }  

}
Thanks,
Deepak
 
Hi All,  
On User object whenever status is TRUE I need to display user information while updating lookup fields on opportunity objects using Trigger
 Eg: product1 ....lookup
     product@ ....lookup
 
trigger psr_update_createdby on Opportunity (before insert, before update) 
{
    List<Id> USR_id = new List<Id>(); 
    Map<Id, String> Usr_Role = new Map<Id, String>();
 
    for(Opportunity Opp: Trigger.new)
    {
    if(Opp.Qualified_By__c!=NULL)
      {
      
      }
      
    }        
  }

please help

Regards.
Deepak

Hi All,
when ever the field change the date field value will be update using workflow rule

Regards,

Viswa

Hi all,

global class batchprocessdesc implements Database.Batchable<sObject>
{

    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'select id from Account';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Account> accounts)
    {
        list<Entitlement> ents = [select AccountId, id, Product_Family__c, EndDate from Entitlement where AccountId IN :accounts ORDER BY AccountId,Product_Family__c,EndDate DESC];
        //Map<Id, Entitlement> pfmap= new Map<Id, Entitlement>(ents);
       
        map<Product_Family__c,EndDate> PFMAP = new map<Product_Family__c,EndDate>(ents); // Error: Compile Error: Invalid type: EndDate at line 15 column 74

        for (Entitlement objent: ents)
        {
          
           pfmap.put('Product_Family__c','EndDate');

        }
        
    } 
    global void finish(Database.BatchableContext BC)
    {
    }
}
Hi All,

i need dispaly this format using  batchapex.. Pd1 – End1; Pd2 – End2; Pd3 – End3; Pd4 – End4.
Any one can give me idea how to i can achive this one .kindly do the needfull.

Thanks!
Deep
Hi All,
I need to remove hyperlink for the created by fields.
User-added image
Below is the code, I did not mention any command link for this
<apex:column value="{!email.CreatedById}" headerValue=" Created By"/>

Kindly help me on this.
Regards,
Deepak
Hi all,

global class batchprocessdesc implements Database.Batchable<sObject>
{

    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'select id from Account';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Account> accounts)
    {
        list<Entitlement> ents = [select AccountId, id, Product_Family__c, EndDate from Entitlement where AccountId IN :accounts ORDER BY AccountId,Product_Family__c,EndDate DESC];
        //Map<Id, Entitlement> pfmap= new Map<Id, Entitlement>(ents);
       
        map<Product_Family__c,EndDate> PFMAP = new map<Product_Family__c,EndDate>(ents); // Error: Compile Error: Invalid type: EndDate at line 15 column 74

        for (Entitlement objent: ents)
        {
          
           pfmap.put('Product_Family__c','EndDate');

        }
        
    } 
    global void finish(Database.BatchableContext BC)
    {
    }
}