-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
16Questions
-
2Replies
Please help me to write test class for this.
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 });
}
}
}
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 });
}
}
}
- sfdc G 9
- August 07, 2023
- Like
- 0
- Continue reading or reply
how to implement Pre-chat form URL in chat button
Hi All,
I have a requirement to implement
Pre-Chat Form URL. They have provided me an URL, Any idea?
Regards,
Depak
I have a requirement to implement
Pre-Chat Form URL. They have provided me an URL, Any idea?
Regards,
Depak
- sfdc G 9
- April 20, 2020
- Like
- 0
- Continue reading or reply
How to update activity date in a recurring task
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??
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??
- sfdc G 9
- February 20, 2020
- Like
- 0
- Continue reading or reply
I am getting two emails from a trigger
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.
Thanks In Advance,
Deepak
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
- sfdc G 9
- May 10, 2018
- Like
- 0
- Continue reading or reply
how to update a custom object custom field with another custom object custom field using trigger in salesforce
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
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
- sfdc G 9
- March 27, 2018
- Like
- 0
- Continue reading or reply
I want field mapping after saving a case in Apex class
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.
This request for field should be changed to GBO Type.
Thanks in Advance please help me on this.
Regards,
Deepak
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.
This request for field should be changed to GBO Type.
Thanks in Advance please help me on this.
Regards,
Deepak
- sfdc G 9
- December 01, 2017
- Like
- 0
- Continue reading or reply
How to allign text in text area left in visualforce page?
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.
Deepak
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.
<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
- sfdc G 9
- November 21, 2017
- Like
- 0
- Continue reading or reply
How to remove hyperlink for From Address standard object user fields??
Is there any way to remove hyperlink for Frorm Address?
Deepak
<apex:column value="{!email.FromAddress}" headerValue=" From Address"/>Thanks in Advance,
Deepak
- sfdc G 9
- November 16, 2017
- Like
- 0
- Continue reading or reply
how to remove hyperlink from standard object user fields?
Hi All,
I need to remove hyperlink for the created by fields.
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
I need to remove hyperlink for the created by fields.
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
- sfdc G 9
- November 16, 2017
- Like
- 0
- Continue reading or reply
why opporunity owner gets added two times in opportunity team while creating a new opportunity
Hi All,
why opporunity owner gets added two times in opportunity team while creating a new opportunity,
Kindly help me on this.
Regards,
Deepak
why opporunity owner gets added two times in opportunity team while creating a new opportunity,
Kindly help me on this.
Regards,
Deepak
- sfdc G 9
- May 15, 2017
- Like
- 0
- Continue reading or reply
how we can move notes and attachments from one account to another account
HI All,
how we can move notes and attachments from one account to another account through code?
Kindly help me on this.
Regards,
Deepak
how we can move notes and attachments from one account to another account through code?
Kindly help me on this.
Regards,
Deepak
- sfdc G 9
- May 08, 2017
- Like
- 0
- Continue reading or reply
if country is japan i need currency as japanese yen
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.
Deepak
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
- sfdc G 9
- April 26, 2017
- Like
- 0
- Continue reading or reply
On User object whenever status is TRUE I need to display user information while updating lookup fields on opportunity objects using Trigger
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
please help
Regards.
Deepak
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
- sfdc G 9
- February 21, 2017
- Like
- 0
- Continue reading or reply
when ever the field change the date field value will be update using workflow rule
Hi All,
when ever the field change the date field value will be update using workflow rule
Regards,
Viswa
- sfdc G 9
- May 27, 2016
- Like
- 0
- Continue reading or reply
Below class is batch apex i have stuck on this error ? can any one can help me .
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)
{
}
}
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)
{
}
}
- sfdc G 9
- May 27, 2016
- Like
- 0
- Continue reading or reply
i want dispaly this format using batchapex.. Pd1 – End1; Pd1 – End1; Pd1 – End1; Pd1 – End1;
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
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
- sfdc G 9
- May 26, 2016
- Like
- 0
- Continue reading or reply
how to remove hyperlink from standard object user fields?
Hi All,
I need to remove hyperlink for the created by fields.
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
I need to remove hyperlink for the created by fields.
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
- sfdc G 9
- November 16, 2017
- Like
- 0
- Continue reading or reply
Below class is batch apex i have stuck on this error ? can any one can help me .
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)
{
}
}
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)
{
}
}
- sfdc G 9
- May 27, 2016
- Like
- 0
- Continue reading or reply