• Scott Russo
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 21
    Replies
We are looking for a way to forward the initial email related to a case, to our shared mailbox, outside of Salesforce.  Is there a way to forward that email, it's contents(including attachments) using a workflow trigger or some other automated process in Salesforce?
The email being forwarded needs to include the Case Ref ID in the subject, and have any attachments which existed in the incoming email.

GhanshyamChoudhari provided the following code, but it's not working as expected. It's generating an email, but not forwading the original email, and it's generating on every save of the case.  Is it possible to accomplish this requirement?
 
trigger emauilwithatt on Case (before insert,before update) {
for (case ca : Trigger.New){
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'XXXXX@gmail.com'};
String[] ccAddresses = new String[] {'XXXXX@gmail.com'};
mail.setToAddresses(toAddresses);
 mail.setCcAddresses(ccAddresses);
mail.setSenderDisplayName('Name');
mail.setSubject('your case number is'+ca.CaseNumber);
mail.setPlainTextBody('This is case  email body.');
   
 List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
	for (Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :ca.Id]){
	Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
	efa.setFileName(a.Name);
	efa.setBody(a.Body);
	fileAttachments.add(efa);
       }
        mail.setFileAttachments(fileAttachments);
         
       Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
 }


 
We are looking for a way to forward the initial email related to a case, to our shared mailbox, outside of Salesforce.  Is there a way to forward that email, it's contents(including attachments) using a workflow trigger or some other automated process in Salesforce?
The email being forwarded needs to include the Case Ref ID in the subject, and have any attachments which existed in the incoming email.
We have a working customization in place. No issues in Classic mode, but we receive this error in Lightning mode, when we add a case comment.
Our customization is to add the comment to a new field located on the case object. This Text Area field has a 255 character limit. The way it works in classic mode, you add a very long comment to the case, there is a workflow which takes the contents of the last comment, and performs a field update workflow action.  Since this text area field has a limit of 255 characters, Salesforce automatically truncates the text from the CommentsBody to fit in this field.  When I switch to Lightning mode, the same action throws the following error

New Case Comment
Review the errors on this page.
  • A workflow or approval field update caused an error when saving this record. Contact your administrator to resolve it. Last Case Comment Internal: data value too large: 
  • (max length=255)

All,
Our developer is no longer with us, and I need to modify this Case, Field formula.  I want the field to be set to a Y if it was created Monday - Friday, between the hours of 6:00 PM EST and 11:59 PM EST.  I can't figure out which part of this formula needs to be updated.
I believe this code was originally set for Sunday to Friday.
I appreciate your assistance.
IF(
AND(
VALUE(LEFT(RIGHT(TEXT( CreatedDate ),9),2))>= 0,VALUE(LEFT(RIGHT(TEXT( CreatedDate ),9),2))<=11,CASE(MOD(DateValue(CreatedDate)-DATE(1900, 1, 7 ), 7 ), 1, 1, 2, 1, 3, 1, 4, 1, 0)=1), "Y",
IF(
AND(VALUE(LEFT(RIGHT(TEXT( CreatedDate ),9),2))<=4,VALUE(LEFT(RIGHT(TEXT( CreatedDate ),9),2))>=1,CASE(MOD(DateValue(CreatedDate)-DATE(1900, 1, 7 ), 7 ), 0, 1, 0)=1),"Y",
IF(
AND(VALUE(LEFT(RIGHT(TEXT( CreatedDate ),9),2))>=5,VALUE(LEFT(RIGHT(TEXT( CreatedDate ),9),2))<=12,CASE(MOD(DateValue(CreatedDate)-DATE(1900, 1, 7 ), 7 ), 5, 1, 0)=1),
"Y","N")
)
)

 
Good morning,

One of our company requirements is to include automatically enter the case # in the subject line and include our corporate signature in all Support Case email replies.  This requires a few extra clicks for our support agents, and they forget to use the template when they are extremely busy, trying to rush a reply.  We want the ability to click the 'Reply' or 'Reply all' link to reply to the customer, and have a default email template inserted, or have a something similar.

I see the ability to do this within the Support Settings: "Enable Default Email Templates or the Default Handler for Email Action"
But I have not clue what is required with regard to selecting an "Apex Class Name"  We do not have a developer on staff, and I'm puzzled as to why I would need to write code to make this functionality work.
Can someone help fill in the blanks?  Thank you, and have a great day
 

I have a formula, number field that I would want to use fieldA or fieldB based on the following.

If the case is closed, and a time stamp field is blank, use fieldA, else use fieldB.  I thought the following code would do the trick, but I receive the following syntax error

 Error: Incorect parameter type for function 'AND()'. Expected Boolean, received Number

 

IF(
  AND(
   IsClosed,
  IsBlank(vrfctnStsHstryStmp__c),
   calcClsd__c ,
  calcCustVrfctn__c
 )
)

 

------------------------

This code works fine.

IF(
   IsClosed, ,
     calcClsd__c ,
  calcCustVrfctn__c
 )

What am I missing?

All,

 

We do not have an Sales Force developer on staff.  We found sample code that does exactly what we need it to do, but we do not know how to get it tested, and implimented into our production environment.  Is there sample test class for the following code?

 

trigger SupportPlanEntitlement on Case (Before Insert, Before Update) {
   /*
   When a case is created, auto-populate with the active support plan
   If the Entitlement Name is not set then, check to see if the Contact on the Case has an active Entitlement
    and select the first one.  If not then check to see if the Account on the Case has an active Entitlement.
   */
   List<Id> contactIds = new List<Id>();
   List<Id> acctIds = new List<Id>();
   for (Case c: Trigger.new){
      if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){
         contactIds.add(c.ContactId);
         acctIds.add(c.AccountId);
      }
   }
   if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){
      /* Added check for active entitlement */
      List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e
                                                Where e.ContactId in:contactIds
                                                And e.Entitlement.Type = 'Support Plan' And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today];
      if(entlContacts.isEmpty()==false){
         for(Case c: Trigger.new){
            if(c.EntitlementId == null && c.ContactId!= null){
               for(EntitlementContact ec:entlContacts){
                  if(ec.ContactId==c.ContactId){
                     c.EntitlementId = ec.EntitlementId;
                     if(c.AssetId==null && ec.Entitlement.AssetId!=null)
                        c.AssetId=ec.Entitlement.AssetId;
                     break;
                  }
               } // end for
            }
         } // end for
      } else{
         List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
                                     From Entitlement e
                                     Where e.AccountId in:acctIds And e.Type = 'Support Plan' And e.EndDate >= Today And e.StartDate <= Today];
         if(entls.isEmpty()==false){
            for(Case c: Trigger.new){
               if(c.EntitlementId == null && c.AccountId!= null){
                  for(Entitlement e:entls){
                     if(e.AccountId==c.AccountId){
                        c.EntitlementId = e.Id;
                        if(c.AssetId==null && e.AssetId!=null)
                           c.AssetId=e.AssetId;
                        break;
                     }
                  } // end for
               }
            } // end for
         }
      }
   } // end if(contactIds.isEmpty()==false)
}

 

This is test test code I have so far.  I don't even know if this code is correct.  I read the examples out on the boards, and I can't seem to make the connection between what is explained, and what I need to do accomplish my goal.  Since all I want to do is relate an Entitlement to a case, I'm not sure what needs to be tested.  .

 

I do not seem my trigger listed when I run the test class.  Does that mean my test code doesn't have any referense to the Apex trigger?

I am not a developer, I do not understand what is missing, or what to add to create a valid test.

I had compile errors on a few lines, so I commented them out to see what would happen.  I was able to save and run a test.  This test didn't run on my Apex Trigger.  Frankly I dont understand how Sales Force would know this test was for my Trigger.  Since the code I am using was listed on these board, I was hoping someone created the test code.  This is so frustrating.

 

Can someone provide me with the information I need to get this code to test my Apex trigger.  Does my trigger need to have a class created?

What does my test code need to have 100% code coverage?

 

@isTest

private class SupportPlanEntitlement_test{

    static testmethod void SupportPlanEntitlement_test(){

    Account acc = new Account(); 
    acc.name='test'; 
// insert required fields like this 
    insert acc; 
    Contact con= new Contact(); 
    con.Lastname='test5'; 
//like this insert required fields 
    insert con; 
  
    Asset a = new Asset();
    a.Name = 'AssetNameTest';

    insert a; 
  
    Case cs = new Case(); 
 //   cs.contactIds = con.ContactId;  Compiler error on this line
 //   cs.acctIds=acc.AccontId;        Compiler error on this line
    Entitlement en = new Entitlement();
    en.Name = 'TestEntitlement';
    en.AccountId = acc.Id;
 //   en.AssetId = a;                 Compiler error on this line
    insert en;

    cs.EntitlementId = en.Id;
    insert cs; 

    } 
}

 

All,

 

We do not have an Sales Force developer on staff.  We found sample code that does exactly what we need it to do, but we do not know how to get it tested, and implimented into our production environment.  Is there sample test class for the following code?

 

trigger SupportPlanEntitlement on Case (Before Insert, Before Update) {
   /*
   When a case is created, auto-populate with the active support plan
   If the Entitlement Name is not set then, check to see if the Contact on the Case has an active Entitlement
    and select the first one.  If not then check to see if the Account on the Case has an active Entitlement.
   */
   List<Id> contactIds = new List<Id>();
   List<Id> acctIds = new List<Id>();
   for (Case c: Trigger.new){
      if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){
         contactIds.add(c.ContactId);
         acctIds.add(c.AccountId);
      }
   }
   if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){
      /* Added check for active entitlement */
      List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e
                                                Where e.ContactId in:contactIds
                                                And e.Entitlement.Type = 'Support Plan' And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today];
      if(entlContacts.isEmpty()==false){
         for(Case c: Trigger.new){
            if(c.EntitlementId == null && c.ContactId!= null){
               for(EntitlementContact ec:entlContacts){
                  if(ec.ContactId==c.ContactId){
                     c.EntitlementId = ec.EntitlementId;
                     if(c.AssetId==null && ec.Entitlement.AssetId!=null)
                        c.AssetId=ec.Entitlement.AssetId;
                     break;
                  }
               } // end for
            }
         } // end for
      } else{
         List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
                                     From Entitlement e
                                     Where e.AccountId in:acctIds And e.Type = 'Support Plan' And e.EndDate >= Today And e.StartDate <= Today];
         if(entls.isEmpty()==false){
            for(Case c: Trigger.new){
               if(c.EntitlementId == null && c.AccountId!= null){
                  for(Entitlement e:entls){
                     if(e.AccountId==c.AccountId){
                        c.EntitlementId = e.Id;
                        if(c.AssetId==null && e.AssetId!=null)
                           c.AssetId=e.AssetId;
                        break;
                     }
                  } // end for
               }
            } // end for
         }
      }
   } // end if(contactIds.isEmpty()==false)
}

 

Good day all,

We are looking for sample APEX that would, upon Case creation or changing the existing Account on a case to perform the following:

 

Perform a lookup to the related Account and find the Entitlement Associated to the Account with a 'Type' field value of "Support Contract"

There can be from zero to many Entitlements associated to an Account, but there would only be one Entitlement with a the 'Type' field set to "Support Contract", so the results would return one record. 

We need this entitlement to be automatically associated to the Case.  There are no Milestones to worry about. 

Essentially, when a Case is created or the Case Account field is modified.  Then we can create lookup fields to display (Status, Contract Start and End Date) on the case.

 

Does anyone have any sample APEX I can look at that might point me in the right direction.

 

Currently 99% of cases are created through the "email to case" functionality, not manually.

 

Thank you in advance for your assistance.

We are looking for a way to forward the initial email related to a case, to our shared mailbox, outside of Salesforce.  Is there a way to forward that email, it's contents(including attachments) using a workflow trigger or some other automated process in Salesforce?
The email being forwarded needs to include the Case Ref ID in the subject, and have any attachments which existed in the incoming email.
We have a working customization in place. No issues in Classic mode, but we receive this error in Lightning mode, when we add a case comment.
Our customization is to add the comment to a new field located on the case object. This Text Area field has a 255 character limit. The way it works in classic mode, you add a very long comment to the case, there is a workflow which takes the contents of the last comment, and performs a field update workflow action.  Since this text area field has a limit of 255 characters, Salesforce automatically truncates the text from the CommentsBody to fit in this field.  When I switch to Lightning mode, the same action throws the following error

New Case Comment
Review the errors on this page.
  • A workflow or approval field update caused an error when saving this record. Contact your administrator to resolve it. Last Case Comment Internal: data value too large: 
  • (max length=255)

All,
Our developer is no longer with us, and I need to modify this Case, Field formula.  I want the field to be set to a Y if it was created Monday - Friday, between the hours of 6:00 PM EST and 11:59 PM EST.  I can't figure out which part of this formula needs to be updated.
I believe this code was originally set for Sunday to Friday.
I appreciate your assistance.
IF(
AND(
VALUE(LEFT(RIGHT(TEXT( CreatedDate ),9),2))>= 0,VALUE(LEFT(RIGHT(TEXT( CreatedDate ),9),2))<=11,CASE(MOD(DateValue(CreatedDate)-DATE(1900, 1, 7 ), 7 ), 1, 1, 2, 1, 3, 1, 4, 1, 0)=1), "Y",
IF(
AND(VALUE(LEFT(RIGHT(TEXT( CreatedDate ),9),2))<=4,VALUE(LEFT(RIGHT(TEXT( CreatedDate ),9),2))>=1,CASE(MOD(DateValue(CreatedDate)-DATE(1900, 1, 7 ), 7 ), 0, 1, 0)=1),"Y",
IF(
AND(VALUE(LEFT(RIGHT(TEXT( CreatedDate ),9),2))>=5,VALUE(LEFT(RIGHT(TEXT( CreatedDate ),9),2))<=12,CASE(MOD(DateValue(CreatedDate)-DATE(1900, 1, 7 ), 7 ), 5, 1, 0)=1),
"Y","N")
)
)

 
Good morning,

One of our company requirements is to include automatically enter the case # in the subject line and include our corporate signature in all Support Case email replies.  This requires a few extra clicks for our support agents, and they forget to use the template when they are extremely busy, trying to rush a reply.  We want the ability to click the 'Reply' or 'Reply all' link to reply to the customer, and have a default email template inserted, or have a something similar.

I see the ability to do this within the Support Settings: "Enable Default Email Templates or the Default Handler for Email Action"
But I have not clue what is required with regard to selecting an "Apex Class Name"  We do not have a developer on staff, and I'm puzzled as to why I would need to write code to make this functionality work.
Can someone help fill in the blanks?  Thank you, and have a great day
 

I have a formula, number field that I would want to use fieldA or fieldB based on the following.

If the case is closed, and a time stamp field is blank, use fieldA, else use fieldB.  I thought the following code would do the trick, but I receive the following syntax error

 Error: Incorect parameter type for function 'AND()'. Expected Boolean, received Number

 

IF(
  AND(
   IsClosed,
  IsBlank(vrfctnStsHstryStmp__c),
   calcClsd__c ,
  calcCustVrfctn__c
 )
)

 

------------------------

This code works fine.

IF(
   IsClosed, ,
     calcClsd__c ,
  calcCustVrfctn__c
 )

What am I missing?

All,

 

We do not have an Sales Force developer on staff.  We found sample code that does exactly what we need it to do, but we do not know how to get it tested, and implimented into our production environment.  Is there sample test class for the following code?

 

trigger SupportPlanEntitlement on Case (Before Insert, Before Update) {
   /*
   When a case is created, auto-populate with the active support plan
   If the Entitlement Name is not set then, check to see if the Contact on the Case has an active Entitlement
    and select the first one.  If not then check to see if the Account on the Case has an active Entitlement.
   */
   List<Id> contactIds = new List<Id>();
   List<Id> acctIds = new List<Id>();
   for (Case c: Trigger.new){
      if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){
         contactIds.add(c.ContactId);
         acctIds.add(c.AccountId);
      }
   }
   if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){
      /* Added check for active entitlement */
      List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e
                                                Where e.ContactId in:contactIds
                                                And e.Entitlement.Type = 'Support Plan' And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today];
      if(entlContacts.isEmpty()==false){
         for(Case c: Trigger.new){
            if(c.EntitlementId == null && c.ContactId!= null){
               for(EntitlementContact ec:entlContacts){
                  if(ec.ContactId==c.ContactId){
                     c.EntitlementId = ec.EntitlementId;
                     if(c.AssetId==null && ec.Entitlement.AssetId!=null)
                        c.AssetId=ec.Entitlement.AssetId;
                     break;
                  }
               } // end for
            }
         } // end for
      } else{
         List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
                                     From Entitlement e
                                     Where e.AccountId in:acctIds And e.Type = 'Support Plan' And e.EndDate >= Today And e.StartDate <= Today];
         if(entls.isEmpty()==false){
            for(Case c: Trigger.new){
               if(c.EntitlementId == null && c.AccountId!= null){
                  for(Entitlement e:entls){
                     if(e.AccountId==c.AccountId){
                        c.EntitlementId = e.Id;
                        if(c.AssetId==null && e.AssetId!=null)
                           c.AssetId=e.AssetId;
                        break;
                     }
                  } // end for
               }
            } // end for
         }
      }
   } // end if(contactIds.isEmpty()==false)
}

 

This is test test code I have so far.  I don't even know if this code is correct.  I read the examples out on the boards, and I can't seem to make the connection between what is explained, and what I need to do accomplish my goal.  Since all I want to do is relate an Entitlement to a case, I'm not sure what needs to be tested.  .

 

I do not seem my trigger listed when I run the test class.  Does that mean my test code doesn't have any referense to the Apex trigger?

I am not a developer, I do not understand what is missing, or what to add to create a valid test.

I had compile errors on a few lines, so I commented them out to see what would happen.  I was able to save and run a test.  This test didn't run on my Apex Trigger.  Frankly I dont understand how Sales Force would know this test was for my Trigger.  Since the code I am using was listed on these board, I was hoping someone created the test code.  This is so frustrating.

 

Can someone provide me with the information I need to get this code to test my Apex trigger.  Does my trigger need to have a class created?

What does my test code need to have 100% code coverage?

 

@isTest

private class SupportPlanEntitlement_test{

    static testmethod void SupportPlanEntitlement_test(){

    Account acc = new Account(); 
    acc.name='test'; 
// insert required fields like this 
    insert acc; 
    Contact con= new Contact(); 
    con.Lastname='test5'; 
//like this insert required fields 
    insert con; 
  
    Asset a = new Asset();
    a.Name = 'AssetNameTest';

    insert a; 
  
    Case cs = new Case(); 
 //   cs.contactIds = con.ContactId;  Compiler error on this line
 //   cs.acctIds=acc.AccontId;        Compiler error on this line
    Entitlement en = new Entitlement();
    en.Name = 'TestEntitlement';
    en.AccountId = acc.Id;
 //   en.AssetId = a;                 Compiler error on this line
    insert en;

    cs.EntitlementId = en.Id;
    insert cs; 

    } 
}

 

All,

 

We do not have an Sales Force developer on staff.  We found sample code that does exactly what we need it to do, but we do not know how to get it tested, and implimented into our production environment.  Is there sample test class for the following code?

 

trigger SupportPlanEntitlement on Case (Before Insert, Before Update) {
   /*
   When a case is created, auto-populate with the active support plan
   If the Entitlement Name is not set then, check to see if the Contact on the Case has an active Entitlement
    and select the first one.  If not then check to see if the Account on the Case has an active Entitlement.
   */
   List<Id> contactIds = new List<Id>();
   List<Id> acctIds = new List<Id>();
   for (Case c: Trigger.new){
      if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){
         contactIds.add(c.ContactId);
         acctIds.add(c.AccountId);
      }
   }
   if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){
      /* Added check for active entitlement */
      List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e
                                                Where e.ContactId in:contactIds
                                                And e.Entitlement.Type = 'Support Plan' And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today];
      if(entlContacts.isEmpty()==false){
         for(Case c: Trigger.new){
            if(c.EntitlementId == null && c.ContactId!= null){
               for(EntitlementContact ec:entlContacts){
                  if(ec.ContactId==c.ContactId){
                     c.EntitlementId = ec.EntitlementId;
                     if(c.AssetId==null && ec.Entitlement.AssetId!=null)
                        c.AssetId=ec.Entitlement.AssetId;
                     break;
                  }
               } // end for
            }
         } // end for
      } else{
         List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
                                     From Entitlement e
                                     Where e.AccountId in:acctIds And e.Type = 'Support Plan' And e.EndDate >= Today And e.StartDate <= Today];
         if(entls.isEmpty()==false){
            for(Case c: Trigger.new){
               if(c.EntitlementId == null && c.AccountId!= null){
                  for(Entitlement e:entls){
                     if(e.AccountId==c.AccountId){
                        c.EntitlementId = e.Id;
                        if(c.AssetId==null && e.AssetId!=null)
                           c.AssetId=e.AssetId;
                        break;
                     }
                  } // end for
               }
            } // end for
         }
      }
   } // end if(contactIds.isEmpty()==false)
}

 

Good day all,

We are looking for sample APEX that would, upon Case creation or changing the existing Account on a case to perform the following:

 

Perform a lookup to the related Account and find the Entitlement Associated to the Account with a 'Type' field value of "Support Contract"

There can be from zero to many Entitlements associated to an Account, but there would only be one Entitlement with a the 'Type' field set to "Support Contract", so the results would return one record. 

We need this entitlement to be automatically associated to the Case.  There are no Milestones to worry about. 

Essentially, when a Case is created or the Case Account field is modified.  Then we can create lookup fields to display (Status, Contract Start and End Date) on the case.

 

Does anyone have any sample APEX I can look at that might point me in the right direction.

 

Currently 99% of cases are created through the "email to case" functionality, not manually.

 

Thank you in advance for your assistance.

I'm looking for some Sample APEX that would, upon Case creation, do a lookup to the Contacts Account and find the Entitlement Associated to the Account.  In my case, there will only ever be one Entitlement associated to an Account so the results would return one record.  I need this entitlement to be automatically associated to the Case and automatically kick off.  Essentially, when a case is created, I need the entitlement to kick off immediately.  Does anyone have any sample APEX I can look at that might point me in the right direction.