• SBgoo
  • NEWBIE
  • 14 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 2
    Likes Given
  • 3
    Questions
  • 18
    Replies
in an apex future method launched by a trigger I am using SingleEmailMessage to send email messages to specific email addresses, using a Lightning EmailTemplate, following almost the same approach mentioned here: Trigger to send email with related attachments
All works great if the EmailTemplate has no attachment. Instead, if the same EmailTemplate has an attachment, then the SendEmail() command generates the following error:
SendEmail failed. First exception on row 0; first error:INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []
It seems that SingleEmailMessage does not support EmailTemplates with attachments. Anyone had the same experience?
Please note that my org is with Summer '18 and that email settings related to EMAIL ATTACHMENTS are "Include as attachment up to 3 MB or as links if more". I noticed that if settings are "Always as links" then the error does not happen (but links added to the sent email will not work).
The same template sent manually via Lightning Email Composer will work, either with "Include as Attachment" or "Always as links settings."
My current conclusions are: * the Lighting composer does not just use the SingleEmailMessage.sendEmail command: it will do a lot of pre processing before, in order to manage attachments properly. This means for example create a proper public link for the attachment. * in order to send emails via apex, we'll need to re-implement the same logic.
Anyone has any idea about this / did it already?
Best
Sebastiano
  • June 21, 2018
  • Like
  • 0
Hello, I am trying to solve the issue of Smart Links not supported in the Community Template.
The best workaround I found is to create a redirect rule at the Site level that does something very simple:

- if a web visitor requires to access:
https://success.mydomain.com/articles/en_US/Documentation/How-to-add-an-Access-point
- the visitor is instead redirected (permanent redirection) to:
https://success.mydomain.com/s/article/How-to-add-an-Access-point

I cannot afford doing this manually (creating one redirect rule) for each article/page.

Basically I'll need something as simple as an expression that replaces:
https://success.mydomain.com/articles/en_US/*
with
https://success.mydomain.com/s/article/*

Which is the simplest way to do it? Is it some sort of redirect regex rule? Or there is a way using an APEX class that does some redirection based on parameters (e.g. the article number and the language code)?

Thanks for any suggestion.
 
  • October 20, 2015
  • Like
  • 0
Hello, I wrote my 3rd trigger in order to update the first contact of an account anytime there is a change on the account.

It seems to work properly but... not with bulk changes on accounts. Could anyone kindly have a look and give me some hints?

Thanks!


trigger UpdateFirstContactOfAccount on Account (after update) {

  System.debug('UpdateFirstContactOfAccount BEGIN');

if(limitrecursion.runtwice()){

  System.debug('UpdateFirstContactOfAccount RECURSIONLIMIT PASSED');

  //aa
  Set<Id> AccIDs = new Set<Id>();
  //for(Contact con: Trigger.new) AccIDs.add(con.AccountId);
  for(Account acc: Trigger.new) {
      System.debug('added id to AccIDs: ' + acc.id);
      AccIDs.add(acc.Id);
  }

 

    // Fetch all the Contacts for these Accounts, selecting only the oldest one of each Account
    List<Contact> Cons = new List<Contact>([
        select
             Id, AccountId
             from Contact
             where AccountId = : AccIDs ORDER BY CreatedDate ASC NULLS LAST LIMIT 1
    //         where AccountId in : AccIDs

     ]);

    // Build a Map, keyed by AccID, of Lists of the related Cons
    Map<Id, List<Contact>> acMap = new Map<Id, List<Contact>>();
    for (Contact c: Cons) {
       if (acMap.containsKey(c.AccountId)) {
            List<Contact> clist2;
            clist2 = acMap.get(c.AccountId);
            clist2.add(c);
            acMap.put(c.AccountId, clist2);
       } else {

            System.debug('added id to acMap: acc ' + c.AccountId + ' contact ' + c.Id);

            List<Contact> clist1 = new List<Contact>();
            clist1.add(c);
            acMap.put(c.AccountId, clist1);
       }
    }



List<Account> ACCS = new List<Account>();

for(Id aid: AccIDs)
{
  if (acMap.containsKey(aid)) {

           for (Contact cc: acMap.get(aid)) {
             System.debug('Account ID' + aid + ' included');
                ACCS.add(
                     New Account(
                        First_Contact__c = cc.Id ,
                        id=aid)
                );
           }
  }
  else
  {
  //remove first contact
  System.debug('Account ID' + aid + ' not included');
  ACCS.add(
                     New Account(
                        First_Contact__c = Null ,
                        Id=aid)
                );
 
  }
}
      
       update ACCS; 










}
else
{
System.debug('UpdateFirstContactOfAccount STOPPED BECAUSE OF REC LIMIT');
}


}
  • October 17, 2014
  • Like
  • 0
Hey everyone,

We were quick to buy into Salesforce Inbox; Perhaps too quick, as now it turns out, after 10 days of correspondence with Salesforce's support team, that emails captured by Einstein Activity Capture are not registered in neither the EmailMessage or Task database, by default.

So, in the existing situation, solely because we have Einstein Activity Capture enabled, even emails we send from within lead records in Salesforce do not get registered at all as EmailMessage or Task objects; This means we cannot set triggers, Apex or Workflow, on incoming or outgoing emails.

Has anyone else encountered this issue? Have you found any workaround or solution to this, including using a different app instead of Inbox? We were not aware that Inbox prevents using triggers on emails, and interestingly enough this little piece of information is also nowhere to be found in Inbox's documentation (or at least, I have not been able to find it).
I am implementing an EmailService. I would like to store the emails I receive as an EmailMessage that would show up on the ActvityHistory for a record like Contact or Account. To do that I wrote the following code (treat it as pseudo code) : 

Task emailTask = new Task (
            ActivityDate  = Date.today(),
            Description   = results.getEmailBodyAsText(),
            // IsArchived    = False, -- This is not writable
            IsRecurrence  = False,
            IsReminderSet = False,
            OwnerId       = results.getPrimaryUser().Id,
            Priority      = 'High',
            Status        = 'Open', // Revisit this - We should check if an email requires response
            Subject       =    results.getSubject(),
            TaskSubType   = 'Email',
            WhoId         =  results.getPrimaryContact().Id
        );


        insert emailTask; // This will provide an Id
        // Notes: Salesforce Requires a Task be Present to associate
        // with it an EmailMessage. Email Message provides a cleaner
        // looking inteface for Emails
        EmailMessage emailMessage = new EmailMessage(
            ActivityId  = emailTask.Id,
            FromAddress = ((Contact)results.getSender()).Email,
            FromName    = ((Contact)results.getSender()).Name,
            Incoming    = False,
            MessageDate = Date.today(),
            Subject     = results.getSubject()
        );
        insert emailMessage;

Where "results" is an object that is created from parsing the Inbound Email (Some decoupling from that Object).  When I do this I get the following error - 
Line: 42, Column: 1
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_OR_READONLY, You cannot edit this field: [ActivityId]

Based on the document on EmailMessage it appears that ActivityId is the Id of the task that the email replaces in the ActivityHistory. I would like to use the EmailMessage object because it looks much cleaner than a Task that is of an Email SubType. Any ideas how to get this to really work?
I am currently not able to use lightning because every time I click on anything the following error message continuously pops up. I am the only one in my office who is receiving this message.  Does anyone know how I can fix this? Hitting refresh does not work. 

--Error Message--
This page has an error. You might just need to refresh it. First, would you give us some details? (We're reporting this as error ID: -1532527413)

[NoErrorObjectAvailable] Script error.
a()@https://paradigmgoc.lightning.force.com/auraFW/javascript/zsWZWPmRKjQt6GsG2UtCYg/aura_prod.js:744:128
{anonymous}()@https://paradigmgoc.lightning.force.com/auraFW/javascript/zsWZWPmRKjQt6GsG2UtCYg/aura_prod.js:744:303
I'm seeing this when running my canvas app on a custom tab (via a visual force page) installed managed package. I've had no issues running it the same way on the same enviroment without it being a managed package as I was developing. Any idea?
Errors in the logs
 
Is it possible to customize the email notifications sent to users for Chatter events?

More specifically, when a user creates a feed item, gets a comment to a feed item or comments following theirs, Salesforce sends an email notification. I couldn't find any email template, nor trigger, nor any other means to change the email content.

I was searching and found in the following links that that was not possible.

http://salesforce.stackexchange.com/questions/7734/how-to-customize-the-email-template-on-chatter-posts
https://success.salesforce.com/ideaView?id=08730000000HA1sAAG#

As the replies and idea were created many years ago, I would like to know if it still is not possible to customize the email notification sent to the users. If that is still the case, what are the alternatives? Should I mass update all the users preferences to not be notified on Chatter events and create a trigger to email users with a custom email template for all these events (feed creation and comments).
Hello, I am trying to solve the issue of Smart Links not supported in the Community Template.
The best workaround I found is to create a redirect rule at the Site level that does something very simple:

- if a web visitor requires to access:
https://success.mydomain.com/articles/en_US/Documentation/How-to-add-an-Access-point
- the visitor is instead redirected (permanent redirection) to:
https://success.mydomain.com/s/article/How-to-add-an-Access-point

I cannot afford doing this manually (creating one redirect rule) for each article/page.

Basically I'll need something as simple as an expression that replaces:
https://success.mydomain.com/articles/en_US/*
with
https://success.mydomain.com/s/article/*

Which is the simplest way to do it? Is it some sort of redirect regex rule? Or there is a way using an APEX class that does some redirection based on parameters (e.g. the article number and the language code)?

Thanks for any suggestion.
 
  • October 20, 2015
  • Like
  • 0
Hi good people,
I'm building a Lightning Experience prototype for the desktop.
I have placed a Lightning component on the Opportunity detail page. This component will display the results of a server-side query that uses the Opportunity id (and other Opportunity data) as filters in the query.
The component is linked to an Apex class (controller="xxx") and implements force:recordTab.
How do I pass details of the Opportunity record through to the Apex class?
Thanks in advance!
  • September 16, 2015
  • Like
  • 0
When I try to deploy some component (without any link to chatter) i have the error : 

"ChatterAnswersAuthProviderRegTest.validateCreateUpdateUser(), Details: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ProfileId]: [ProfileId] Class.ChatterAnswersAuthProviderRegTest.validateCreateUpdateUser: line 31, column 1"

the test class ask for a ProfileId, while i can't modify it.

Name                            Version       Nom d'espace       Type
API salesforce.com        33.0             API                     salesforce.com
____________________________________________________________________________________________________
@isTest
private class ChatterAnswersAuthProviderRegTest {
  static testMethod void validateCreateUpdateUser() {
    User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ];
    System.runAs ( thisUser ) {
      Auth.UserData userData = new Auth.UserData('testId', 'testFirst', 'testLast',
      'testFirst testLast', 'no-reply@salesforce.com', null, 'testuserlong', 'en_US', 'facebook',
      null, new Map<String, String>{'language' => 'en_US'});
      ChatterAnswersAuthProviderRegistration reg = new ChatterAnswersAuthProviderRegistration();
      Profile[] p = [SELECT Id FROM Profile WHERE Name = 'System Administrator'];
      User[] adminUser = [SELECT Id, Firstname, Lastname FROM User WHERE IsActive = true and ProfileId =: p[0].Id LIMIT 1];
      reg.setSiteAdminUserId(adminUser[0].Id);
      User newUser = reg.createUser(null, userData);
      System.assert(newUser != null, 'A new user should have been created');
      System.assertEquals(newUser.Firstname, 'testFirst', 'First name should have been same');
      System.assertEquals(newUser.Lastname, 'testLast', 'Last name should have been same');
      System.assertEquals(newUser.Email, 'no-reply@salesforce.com', 'Email should have been same');
      
      Contact c = new Contact();
      c.AccountId = (newUser.Username.split('@'))[0];
      c.LastName = 'contactLast';
      insert(c);
      
      newUser.Alias = 'firstusr';
      newUser.TimeZoneSidKey = 'America/Los_Angeles';
      newUser.LocaleSidKey = 'en_US';
      newUser.EmailEncodingKey = 'UTF-8';
      newUser.LanguageLocaleKey = 'en_US';
      newUser.ContactId = c.Id;
      // newUser.ProfileId = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1].Id;  [try to add this but i can't save]

      insert(newUser); // <= this is where the error is located :
      
      Auth.UserData updateUserData = new Auth.UserData('testId', 'updatedFirst', 'updatedLast',
      'updatedFirst updatedLast', 'no-reply@new.salesforce.com', null, 'testuserlong', 'en_US', 'facebook',
      null, new Map<String, String>{'language' => 'en_US'});
      reg.updateUser(newUser.Id, null, updateUserData);
      
      User dbUser =  [SELECT Id, Firstname, Lastname, Email FROM User WHERE Id = :newUser.Id];
      System.assertEquals(dbUser.Firstname, 'updatedFirst', 'First name should have been updated');
      System.assertEquals(dbUser.Lastname, 'updatedLast', 'Last name should have been updated');
      System.assertEquals(dbUser.Email, 'no-reply@new.salesforce.com', 'Email should have been updated');
    }
  }
}
________________________________________________________________________________________________
Hello, I wrote my 3rd trigger in order to update the first contact of an account anytime there is a change on the account.

It seems to work properly but... not with bulk changes on accounts. Could anyone kindly have a look and give me some hints?

Thanks!


trigger UpdateFirstContactOfAccount on Account (after update) {

  System.debug('UpdateFirstContactOfAccount BEGIN');

if(limitrecursion.runtwice()){

  System.debug('UpdateFirstContactOfAccount RECURSIONLIMIT PASSED');

  //aa
  Set<Id> AccIDs = new Set<Id>();
  //for(Contact con: Trigger.new) AccIDs.add(con.AccountId);
  for(Account acc: Trigger.new) {
      System.debug('added id to AccIDs: ' + acc.id);
      AccIDs.add(acc.Id);
  }

 

    // Fetch all the Contacts for these Accounts, selecting only the oldest one of each Account
    List<Contact> Cons = new List<Contact>([
        select
             Id, AccountId
             from Contact
             where AccountId = : AccIDs ORDER BY CreatedDate ASC NULLS LAST LIMIT 1
    //         where AccountId in : AccIDs

     ]);

    // Build a Map, keyed by AccID, of Lists of the related Cons
    Map<Id, List<Contact>> acMap = new Map<Id, List<Contact>>();
    for (Contact c: Cons) {
       if (acMap.containsKey(c.AccountId)) {
            List<Contact> clist2;
            clist2 = acMap.get(c.AccountId);
            clist2.add(c);
            acMap.put(c.AccountId, clist2);
       } else {

            System.debug('added id to acMap: acc ' + c.AccountId + ' contact ' + c.Id);

            List<Contact> clist1 = new List<Contact>();
            clist1.add(c);
            acMap.put(c.AccountId, clist1);
       }
    }



List<Account> ACCS = new List<Account>();

for(Id aid: AccIDs)
{
  if (acMap.containsKey(aid)) {

           for (Contact cc: acMap.get(aid)) {
             System.debug('Account ID' + aid + ' included');
                ACCS.add(
                     New Account(
                        First_Contact__c = cc.Id ,
                        id=aid)
                );
           }
  }
  else
  {
  //remove first contact
  System.debug('Account ID' + aid + ' not included');
  ACCS.add(
                     New Account(
                        First_Contact__c = Null ,
                        Id=aid)
                );
 
  }
}
      
       update ACCS; 










}
else
{
System.debug('UpdateFirstContactOfAccount STOPPED BECAUSE OF REC LIMIT');
}


}
  • October 17, 2014
  • Like
  • 0

Hello,

Can anyone tell me :

Am I missing something or it's not possible to create a lookup relationship to Articles ?

Thats something i definitely need.

So, at this point, should I create something like a String field on my Custom Object that will store the article id and make another SOQL query to fetch it every time additionally ?

 

Kind regards

  • September 20, 2011
  • Like
  • 1

I'm having an issue with 'fieldsToNull' and PHP Toolkit 13. I can't pass through an array of field names without getting this error:

 

$sObject->fieldsToNull = array('Current_Projects__c', 'About_Me__c');

 

Unexpected element {http://www.w3.org/2001/XMLSchema}string during simple type deserialization

 

Though, if I do:

 

$sObject->fieldsToNull = 'Current_Projects__c';

 

This will work fine, and set the field to null. But doesn't solve my problem of being able to set multiple field values to null.

 

Has anyone encountered this issue before?

Message Edited by David_FB on 03-10-2009 04:45 AM
I am trying to implement my own email-to-case class and I have the following code, which is working in my sandbox, to create an EmailMessage on a case using email services:
 
EmailMessage[] newEmail = new EmailMessage[0];
 
newEmail.add(new EmailMessage(FromAddress = email.fromAddress,
FromName = email.fromName,
ToAddress = email.toAddresses[0],
Subject = email.subject,
TextBody = email.plainTextBody,
HtmlBody = email.htmlBody,
ParentId = newCase[0].Id, 
ActivityId = newTask[0].Id));   // (newCase and newTask are the newly created case and task from earlier code)
 
insert newEmail;
 
I have several questions.  Is it possible to set the email message status to "New"?  If I attempt to add "Status = 'New'" in the .add() method I get an error: Message: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Status: bad value for restricted picklist field: New: [Status] null.  If I don't attempt to set the status, it defaults to "Sent".
 
Also, does anyone have any sample code to share that adds headers and attachments from an inbound email to an Email Message object?  I'm struggling with that one.
 
Another minor issue that is bugging me is that in the Email Section of the Case page in my sandbox, the column labelled "Email Address" shows the 'to address' and my production version using the the standard SFDC email to case application will have the 'from address' (contact's address) displayed.  Does anyone know what field in the Email Message object this data comes from?
 
Thanks for the help!
I'm seeing this when running my canvas app on a custom tab (via a visual force page) installed managed package. I've had no issues running it the same way on the same enviroment without it being a managed package as I was developing. Any idea?
Errors in the logs
 
Is it possible to customize the email notifications sent to users for Chatter events?

More specifically, when a user creates a feed item, gets a comment to a feed item or comments following theirs, Salesforce sends an email notification. I couldn't find any email template, nor trigger, nor any other means to change the email content.

I was searching and found in the following links that that was not possible.

http://salesforce.stackexchange.com/questions/7734/how-to-customize-the-email-template-on-chatter-posts
https://success.salesforce.com/ideaView?id=08730000000HA1sAAG#

As the replies and idea were created many years ago, I would like to know if it still is not possible to customize the email notification sent to the users. If that is still the case, what are the alternatives? Should I mass update all the users preferences to not be notified on Chatter events and create a trigger to email users with a custom email template for all these events (feed creation and comments).