• Cyclebiff
  • NEWBIE
  • 50 Points
  • Member since 2009

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 7
    Replies

I am completely new to this, so I'm sure I'm missing something simple.  I get the following error:

 

 Error: Compile Error: unexpected token: 'Trigger.new' at line 2 column 138

 

when I try to save the following code:

 

 

trigger updateAccountName on Account (before Insert){
  List<Lead> convertedLeads=[Select ID,ConvertedAccountId, Firstname__c, MiddleName__c, LastName__c FROM Lead WHERE ConvertedAccountId IN Trigger.new];
  For (Account a: Trigger.new){
    For (Lead l: convertedLeads){
      if (l.ConvertedAccountId=a.ID){
         a.Name=l.FirstName__c+l.MiddleName__c+l.LastName__c;
      }
    }
  }
}

 

 

Thank you!!

 

 
When attempting to update the Case Owner ID via Field updates (Workflow & Approvals > Field Updates), salesforce.com will only let me lookup exact values. Is there a way to put in the value of another lookup field into this field update?

I have a custom multi-select picklist that I'd like to concatenate into a string, delimited by commas.
I'd like to do this through APEX -- any quick and dirty suggestions?

 

Or at least how is the data stored?

When adding a new "Public Comment" to a case, the client is notified to login to their self-service portal to view the comment. Is there an email field to place into template that lists the actual comment made to the client? I do not see a field like "Last Public Case Comment", etc.

We'd like this email to look much like the email notfications that are sent directly to the case owner if someone internal places a comment on the case.

This functionality is desired so clients do not need to log in to their self service portal to view a simple update to one case.

 

Any thoughts?

Hello!

 

I have this basic query example that I'm using with Crystal (this issue is not crystal-specific, only SOQL):

 

 

SELECT Name, (SELECT Name, Title, Phone, Email from Contacts) from Account Where ????????? ORDER BY Name

 

 

It currently returns all records from our entire database. I want this query limit where "a case exists on the account by a specific user" (we use CRM/Cases). The purpose of the report is to see which Agencies an employee has worked with (via Case.Owner.Name).

 

A simple example will suffice!!!! :) And thanks in advance!!!!

Salesforce gurus,

 

I am attempting to query all open cases and including case comments that have been "made public" that the users get to see via self service portal. As you can see i originally thought the "ispublished" was the bool flag, but apparantly I was wrong -- all comments are displayed. How do I include Public Case Comments to my query below?

 

 

SELECT CaseNumber, Subject, Status, CreatedDate, (SELECT CommentBody, IsPublished, CreatedDate from CaseComments where IsPublished = false ORDER By LastModifiedDate DESC LIMIT 1) FROM Case where Case.Account.Name like 'SomeAccountName%' and IsClosed = false ORDER BY Status ASC

APEX Gurus,

 

I'm trying to pass a query using APEX/SOQL, how do I perform a "break" for a date formula? I've tried using double colons, etc, nothing works.. HELP!!

 

Query:

  integer numOfDays = 7;

  Attachment[] lastAttachment = [select Body, Id, Name, ContentType from Attachment where Parentid=:a.Id and CreatedDate = LAST_N_DAYS:numOfDays and CreatedByID !=:a.OwnerID order by CreatedDate DESC]; 

 

Error: Compile Error: expecting a number, found ':' at line 20 column 141

 

 

I've recently took it upon myself to start developing APEX classes for our CRM.

 

While I'm an o-k coder, I am not familiar with the standards for documenting the classes, changes, and deployment.


Any pointers? Should I use UML for the APEX classes? Is there a format or documentation method that is a standard for deployment?

 

These notes assume you know how to work with the Messaging.SingleEmailMessage class. If anybody has a better way of doing this, let me know.

While building an APEX class that emails Case Owner, boss wanted to add the last few attachments of a Case to the email being generated.

 

1.) Instantiate SingleEmailMessage object:

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

 

2.) Query Attachments of whatever object type you want attachments on. I return the results to an Attachment[] array. Note - this is a good place to limit the number of attachments you want to return.

Attachment[] queryAttachment = [select Body, Id, Name, ContentType from Attachment where Parentid=:someCaseObject.Id order by CreatedDate DESC];

 

3.) Create an EmailFileAttachment[] array to hold each file, loop through the query and populate the array.

        Messaging.EmailFileAttachment[] allAttachments = new
        for(integer i=0;i<queryAttachment.size();i++)
        {
            Messaging.EmailFileAttachment fileAttachment = new Messaging.EmailFileAttachment();
            fileAttachment.setBody(queryAttachment[i].Body);
            fileAttachment.setFileName(queryAttachment[i].Name);
            allAttachments[i] =  fileAttachment;
        }
Messaging.EmailFileAttachment[queryAttachment.size()];
 

4.) Now that our allAttachments array is populated, pass allAttachments to your mail object's setFileAttachments method:

        mail.setFileAttachments(allAttachments);
 

5.) Do the rest of your mail.methods to generate and send your email.

 

http://blog.psychopup.net/post/2009/10/15/Adding-Attachments-to-emails-via-APEX-in-Salesforce.aspx

 

Help!!

 

Issue: I have an APEX script that reassigns to a specific owner based on certain criteria (effectively bypassing Auto Assignment rules). This works fine, however I'm trying to code an emailCaseOwner(Case) function that emails the case owner after it's assigned. The trigger I'm passing is Case update before.  The email that is ultimately sent to the case.OwnerID is not populating the merge fields.

 

The email template is used as the "Case Assigned Template" (Setup -> Customize -> Case -> Support Settings). I'm basically mimicing the checkbox when manually assigning a case owner "Send Notification Email".

 

End result of email being sent to assigned user:

Force.com Sandbox

Case Number:  -

Client:  -  

Created by: 

Subject:

Description:

 

APEX Code:

    public static void emailCaseOwner(Case a)
    {
        EmailTemplate template = [select Id from EmailTemplate where Name = 'NewCase4CRC' limit 1];
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setTargetObjectId(tempContact.Id);
        mail.setTemplateId(template.Id);
        mail.saveAsActivity = false;
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } );
    }

Template Snippet:

Case Number: {!Case.CaseNumber} - {!Case.Product__c}
Client: {!Case.Contact} - {!Case.Account} {!Contact.Phone} {!Contact.Email}
Created by: {!Case.CreatedBy} {!Case.CreatedDate}

{!Case.Link}

Subject: {!Case.Subject}

Description: {!Case.Description}

When escalating from status "Tier1" to "Engineering", Auto Assign rules work well by assigning to an Engineering Queue.

 

Currently, when changing status from "Engineering" to "Tier1", Auto Assign rules assign the case OwnerID to the Tier1 Queue.

 

Question: Is there a way, using Auto-Assignment rules or APEX, I can escalate back to the original OwnerID who changed the status initially?

 

I've created a field, "Escalated_By" which is currently populated manually (I think I've gotten APEX class working that populates this field in my dev environment). I'm unsure how to update the case's OwnerID automatically if Escalated_By is not null.

 

Any suggestions?

Hello! I'm new to Salesforce Administration and have had success with using APEX Triggers and Classes.

 

Issue: After escalating (changing Status and Owner using assignment rules), I auto-populate a custom field, "Escalated By". This works great. I would like to be able to escalate back to the person who is populated in the "Escalated By" field automatically when changing the status back to Tier-1 (from Engineering status).

 

Question 1: Is there a way using Assignment Rules to do:

 If "Escalated By" <> NULL THEN (Step3) Assign to Escalated_By__c (my custom field).

 

Question 2 (if Question 1 is no): Is APEX the only way to go?

When attempting to update the Case Owner ID via Field updates (Workflow & Approvals > Field Updates), salesforce.com will only let me lookup exact values. Is there a way to put in the value of another lookup field into this field update?

I have a custom multi-select picklist that I'd like to concatenate into a string, delimited by commas.
I'd like to do this through APEX -- any quick and dirty suggestions?

 

Or at least how is the data stored?

When adding a new "Public Comment" to a case, the client is notified to login to their self-service portal to view the comment. Is there an email field to place into template that lists the actual comment made to the client? I do not see a field like "Last Public Case Comment", etc.

We'd like this email to look much like the email notfications that are sent directly to the case owner if someone internal places a comment on the case.

This functionality is desired so clients do not need to log in to their self service portal to view a simple update to one case.

 

Any thoughts?

Couldn't find any doc /api reference that explicitly describes how to convert a given GMT Datetime to a desired TimeZone Datetime.  All of the docs talk about GMT and "Local" TimeZone, unless I've missed something obvious.

 

I have start and end dates in the database, which are in GMT TimeZone.  I need to convert them to a different TimeZone (BusinessHours TimeZone) so that I can use "BusinessHours.diff" API to determine elapsed time.

 

Thanks

 

 

 

 

 

 

 

 

Message Edited by jps on 10-29-2009 09:22 PM
  • October 30, 2009
  • Like
  • 0

These notes assume you know how to work with the Messaging.SingleEmailMessage class. If anybody has a better way of doing this, let me know.

While building an APEX class that emails Case Owner, boss wanted to add the last few attachments of a Case to the email being generated.

 

1.) Instantiate SingleEmailMessage object:

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

 

2.) Query Attachments of whatever object type you want attachments on. I return the results to an Attachment[] array. Note - this is a good place to limit the number of attachments you want to return.

Attachment[] queryAttachment = [select Body, Id, Name, ContentType from Attachment where Parentid=:someCaseObject.Id order by CreatedDate DESC];

 

3.) Create an EmailFileAttachment[] array to hold each file, loop through the query and populate the array.

        Messaging.EmailFileAttachment[] allAttachments = new
        for(integer i=0;i<queryAttachment.size();i++)
        {
            Messaging.EmailFileAttachment fileAttachment = new Messaging.EmailFileAttachment();
            fileAttachment.setBody(queryAttachment[i].Body);
            fileAttachment.setFileName(queryAttachment[i].Name);
            allAttachments[i] =  fileAttachment;
        }
Messaging.EmailFileAttachment[queryAttachment.size()];
 

4.) Now that our allAttachments array is populated, pass allAttachments to your mail object's setFileAttachments method:

        mail.setFileAttachments(allAttachments);
 

5.) Do the rest of your mail.methods to generate and send your email.

 

http://blog.psychopup.net/post/2009/10/15/Adding-Attachments-to-emails-via-APEX-in-Salesforce.aspx

 

I am completely new to this, so I'm sure I'm missing something simple.  I get the following error:

 

 Error: Compile Error: unexpected token: 'Trigger.new' at line 2 column 138

 

when I try to save the following code:

 

 

trigger updateAccountName on Account (before Insert){
  List<Lead> convertedLeads=[Select ID,ConvertedAccountId, Firstname__c, MiddleName__c, LastName__c FROM Lead WHERE ConvertedAccountId IN Trigger.new];
  For (Account a: Trigger.new){
    For (Lead l: convertedLeads){
      if (l.ConvertedAccountId=a.ID){
         a.Name=l.FirstName__c+l.MiddleName__c+l.LastName__c;
      }
    }
  }
}

 

 

Thank you!!

 

 

Help!!

 

Issue: I have an APEX script that reassigns to a specific owner based on certain criteria (effectively bypassing Auto Assignment rules). This works fine, however I'm trying to code an emailCaseOwner(Case) function that emails the case owner after it's assigned. The trigger I'm passing is Case update before.  The email that is ultimately sent to the case.OwnerID is not populating the merge fields.

 

The email template is used as the "Case Assigned Template" (Setup -> Customize -> Case -> Support Settings). I'm basically mimicing the checkbox when manually assigning a case owner "Send Notification Email".

 

End result of email being sent to assigned user:

Force.com Sandbox

Case Number:  -

Client:  -  

Created by: 

Subject:

Description:

 

APEX Code:

    public static void emailCaseOwner(Case a)
    {
        EmailTemplate template = [select Id from EmailTemplate where Name = 'NewCase4CRC' limit 1];
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setTargetObjectId(tempContact.Id);
        mail.setTemplateId(template.Id);
        mail.saveAsActivity = false;
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } );
    }

Template Snippet:

Case Number: {!Case.CaseNumber} - {!Case.Product__c}
Client: {!Case.Contact} - {!Case.Account} {!Contact.Phone} {!Contact.Email}
Created by: {!Case.CreatedBy} {!Case.CreatedDate}

{!Case.Link}

Subject: {!Case.Subject}

Description: {!Case.Description}