• michael32
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies

The Case object for has a standard field for 'Type' (in the code below, this is represented by 'Case.Type'). The Case object also has a 'Case Type' standard field, which identifies the case record.

 

Right now I my conditionals are based on the 'Type' field, but I want them to be based on the 'Case Type' record field (I want to populate the body based on the record type). My goal is to do this without hardcoding a record identifier, which to my understanding, is bad practice as it is not always consistent across Dev/Production environments.

 

My code is as follows:

 

public class myControllerExtention2 {
private Case cas;
private string EmailBody, Subject;
//Define default values
String defaultEmailBody = '';
String defaultSubject = '';

//Instantiate Visualforce standard controller 
public myControllerExtention2(ApexPages.StandardController stdController) {
//Instantiate case record
this.cas= (case)stdController.getRecord();
//SOQL query
cas = [SELECT Type FROM Case where Id =: cas.Id];
//Case record type conditionals
If (cas.Type=='AAA') {
emailBody = 'AAA body content';
subject = 'AAA subject';
}
If (cas.Type=='BBB') {
emailBody = 'BBB body content';
subject = 'BBB subject';
}
If (cas.Type=='CCC') {
emailBody = 'CCC Body';
subject = 'CCC subject';
}
}

//Accessor methods
public string GetEmailBody() {
If (emailBody == NULL) { 
return defaultEmailBody;
}
Else {
return emailBody;
}
}
public string GetSubject() {
If (subject == NULL) { 
return defaultSubject;
}
Else {
return subject;
}
}
}

How do you set the hours that the Live Agent chat will be available on the website? We do not provide support 24 hours.

 

I have an email publisher that populates based on the value in the case type field. However, I have only been able to get 40% coverage. Any idea what I am doing wrong?

 

Visualforce page with email publisher:

 

<apex:page standardController="Case" extensions="myControllerExtention2">
<apex:emailPublisher entityId="{!case.id}"
emailBody="{!EmailBody}"
subject="{!Subject}"
/>
</apex:page>

 

Extension that contains logic and content for the email publisher:

 

public class myControllerExtention2 {
private Case cas;
private string EmailBody, Subject;
//Define default values
String defaultEmailBody = '';
String defaultSubject = '';

//Instantiate Visualforce standard controller 
public myControllerExtention2(ApexPages.StandardController stdController) {
//Instantiate case record
this.cas= (case)stdController.getRecord();
//SOQL query
cas = [SELECT Type FROM Case where Id =: cas.Id];
//Case record type conditionals
If (cas.Type=='AAA') {
emailBody = 'AAA body content';
subject = 'AAA subject';
}
If (cas.Type=='BBB') {
emailBody = 'BBB body content';
subject = 'BBB subject';
}
If (cas.Type=='CCC') {
emailBody = 'CCC Body';
subject = 'CCC subject';
}
}

//Accessor methods
public string GetEmailBody() {
If (emailBody == NULL) { 
return defaultEmailBody;
}
Else {
return emailBody;
}
}
public string GetSubject() {
If (subject == NULL) { 
return defaultSubject;
}
Else {
return subject;
}
}
}

 


The test code (currently provides 40% coverage):

 

@isTest
public class testMyPage2 {
static testMethod void myPage_Test() {
PageReference pageRef = Page.CaseEmailPublisher;
Test.setCurrentPageReference(pageRef);
//Create new account
Account newAccount = new Account (name='XYZ Org');
insert newAccount;
//Create first contact
Contact myContact = new Contact (FirstName='Joe',
LastName='Miller',
AccountId=newAccount.id);
insert myContact;
//Create first case
Case myCase = new Case(
ContactId=myContact.id,
Type='AAA');
insert myCase;
ApexPages.StandardController sc = new ApexPages.standardController(myCase);
myControllerExtention2 e = new myControllerExtention2(sc);
myCase.type='BBB';
update myCase;
myCase.type='CCC';
update myCase;
}
}

 

Added a custom button on the Case Record that opens a new email. How do I get it to populate the email subject and body? This is the link that I added to the button:

 

https://na14.salesforce.com/_ui/core/email/author/EmailAuthor?htmlBody=hello+world&p2_lkid={!Contact.Id}&rtype=003&p3_lkid={!Case.Id}&retURL=%{!Case.Id}

 

Alternatively, is there any way to pass in a string variable from the URL that populates the subject & body value?  Not interested in using SFDC's email templates, since they cannot be modified before sending.

 

Thanks in advance for the help.

The Case object for has a standard field for 'Type' (in the code below, this is represented by 'Case.Type'). The Case object also has a 'Case Type' standard field, which identifies the case record.

 

Right now I my conditionals are based on the 'Type' field, but I want them to be based on the 'Case Type' record field (I want to populate the body based on the record type). My goal is to do this without hardcoding a record identifier, which to my understanding, is bad practice as it is not always consistent across Dev/Production environments.

 

My code is as follows:

 

public class myControllerExtention2 {
private Case cas;
private string EmailBody, Subject;
//Define default values
String defaultEmailBody = '';
String defaultSubject = '';

//Instantiate Visualforce standard controller 
public myControllerExtention2(ApexPages.StandardController stdController) {
//Instantiate case record
this.cas= (case)stdController.getRecord();
//SOQL query
cas = [SELECT Type FROM Case where Id =: cas.Id];
//Case record type conditionals
If (cas.Type=='AAA') {
emailBody = 'AAA body content';
subject = 'AAA subject';
}
If (cas.Type=='BBB') {
emailBody = 'BBB body content';
subject = 'BBB subject';
}
If (cas.Type=='CCC') {
emailBody = 'CCC Body';
subject = 'CCC subject';
}
}

//Accessor methods
public string GetEmailBody() {
If (emailBody == NULL) { 
return defaultEmailBody;
}
Else {
return emailBody;
}
}
public string GetSubject() {
If (subject == NULL) { 
return defaultSubject;
}
Else {
return subject;
}
}
}

 

I have an email publisher that populates based on the value in the case type field. However, I have only been able to get 40% coverage. Any idea what I am doing wrong?

 

Visualforce page with email publisher:

 

<apex:page standardController="Case" extensions="myControllerExtention2">
<apex:emailPublisher entityId="{!case.id}"
emailBody="{!EmailBody}"
subject="{!Subject}"
/>
</apex:page>

 

Extension that contains logic and content for the email publisher:

 

public class myControllerExtention2 {
private Case cas;
private string EmailBody, Subject;
//Define default values
String defaultEmailBody = '';
String defaultSubject = '';

//Instantiate Visualforce standard controller 
public myControllerExtention2(ApexPages.StandardController stdController) {
//Instantiate case record
this.cas= (case)stdController.getRecord();
//SOQL query
cas = [SELECT Type FROM Case where Id =: cas.Id];
//Case record type conditionals
If (cas.Type=='AAA') {
emailBody = 'AAA body content';
subject = 'AAA subject';
}
If (cas.Type=='BBB') {
emailBody = 'BBB body content';
subject = 'BBB subject';
}
If (cas.Type=='CCC') {
emailBody = 'CCC Body';
subject = 'CCC subject';
}
}

//Accessor methods
public string GetEmailBody() {
If (emailBody == NULL) { 
return defaultEmailBody;
}
Else {
return emailBody;
}
}
public string GetSubject() {
If (subject == NULL) { 
return defaultSubject;
}
Else {
return subject;
}
}
}

 


The test code (currently provides 40% coverage):

 

@isTest
public class testMyPage2 {
static testMethod void myPage_Test() {
PageReference pageRef = Page.CaseEmailPublisher;
Test.setCurrentPageReference(pageRef);
//Create new account
Account newAccount = new Account (name='XYZ Org');
insert newAccount;
//Create first contact
Contact myContact = new Contact (FirstName='Joe',
LastName='Miller',
AccountId=newAccount.id);
insert myContact;
//Create first case
Case myCase = new Case(
ContactId=myContact.id,
Type='AAA');
insert myCase;
ApexPages.StandardController sc = new ApexPages.standardController(myCase);
myControllerExtention2 e = new myControllerExtention2(sc);
myCase.type='BBB';
update myCase;
myCase.type='CCC';
update myCase;
}
}

 

Added a custom button on the Case Record that opens a new email. How do I get it to populate the email subject and body? This is the link that I added to the button:

 

https://na14.salesforce.com/_ui/core/email/author/EmailAuthor?htmlBody=hello+world&p2_lkid={!Contact.Id}&rtype=003&p3_lkid={!Case.Id}&retURL=%{!Case.Id}

 

Alternatively, is there any way to pass in a string variable from the URL that populates the subject & body value?  Not interested in using SFDC's email templates, since they cannot be modified before sending.

 

Thanks in advance for the help.