• aaronbauman
  • NEWBIE
  • 0 Points
  • Member since 2012

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

SOAP API upsert() method supports using any foreign key, id lookup, or 'Id' field as an upsert key.

REST API does not.

 

Why?

Trying to import from a CSV, which contains records that have line breaks, e.g. for an Address field.

They're properly enclosed in double quotes, but LexiLoader reports an error for each occurence.

 

I must be missing something obvious, but my cursory googling turned up no results.

Is it a bug in LexiLoader? Should I be replacing or escaping newlines somehow?

Any suggestions appreciated.

I have a AfterInsert + AfterUpdate trigger designed to send an email under certain criteria.

After it was first built, double-emails were being sent, since these kinds of triggers can fire twice per operation.

So, I built a script (like so) to make sure the email is only sent once, and further I added a beforeInsert + beforeUpdate trigger that always changes a custom field to make sure the after* triggers always fire twice.

 

Now, sometimes the email gets sent and sometimes it doesn't:

 

  • When I setup the email to get sent during the first invocation, and I create a record via the web, the email gets sent.
    If I create a record via upsert() API method, it doesn't.

  • When I setup the email to get sent during the second invocation, the opposite happens.
    Creating via upsert() API sends the email, creating via the web doesn't. 

 

I'm using Messaging.sendEmail() method to do the actual sending.

The mail invocation limit is well under, and Apex Debug Logs do not report any errors.

But the activity is not recorded on the related object record, and I do not actually receive any email.

WTH?

 

I've spent hours already trying to debug this, and I have no idea how to go any further.

Plz halp.

My entire APEX trigger is wrapped in a try/catch block, catching the generic Exception object, but I'm still hitting a fatal System.LimitException.

 

What's the point of try/catch if it doesn't actually catch an exception? 

How can I make sure my try / catch block prevents a fatal error?

 

Here's the relevant snippet:

 

for (Contact c : [SELECT Email, Id FROM Contact WHERE AccountId = :account_id LIMIT 10]) {
  if(c.Email != null){
    try {
      Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
      message.setTemplateID(email_template.Id);
      message.setWhatId(detail.Id);
      message.setTargetObjectId(c.Id);
      Messaging.sendEmail(new Messaging.SingleEmailMessage[] { message });
    }    

    catch (System.LimitException e) {

      // I don't really care if the email fails.

      // I just don't want it to break my data entry process.

     }

     catch (Exception e) {

      // I don't really care if the email fails.

      // I just don't want it to break my data entry process.
    }
  }

}

 

updated: even explicitly catching system.limitexception fails.

Trying to import from a CSV, which contains records that have line breaks, e.g. for an Address field.

They're properly enclosed in double quotes, but LexiLoader reports an error for each occurence.

 

I must be missing something obvious, but my cursory googling turned up no results.

Is it a bug in LexiLoader? Should I be replacing or escaping newlines somehow?

Any suggestions appreciated.

I have a AfterInsert + AfterUpdate trigger designed to send an email under certain criteria.

After it was first built, double-emails were being sent, since these kinds of triggers can fire twice per operation.

So, I built a script (like so) to make sure the email is only sent once, and further I added a beforeInsert + beforeUpdate trigger that always changes a custom field to make sure the after* triggers always fire twice.

 

Now, sometimes the email gets sent and sometimes it doesn't:

 

  • When I setup the email to get sent during the first invocation, and I create a record via the web, the email gets sent.
    If I create a record via upsert() API method, it doesn't.

  • When I setup the email to get sent during the second invocation, the opposite happens.
    Creating via upsert() API sends the email, creating via the web doesn't. 

 

I'm using Messaging.sendEmail() method to do the actual sending.

The mail invocation limit is well under, and Apex Debug Logs do not report any errors.

But the activity is not recorded on the related object record, and I do not actually receive any email.

WTH?

 

I've spent hours already trying to debug this, and I have no idea how to go any further.

Plz halp.

My entire APEX trigger is wrapped in a try/catch block, catching the generic Exception object, but I'm still hitting a fatal System.LimitException.

 

What's the point of try/catch if it doesn't actually catch an exception? 

How can I make sure my try / catch block prevents a fatal error?

 

Here's the relevant snippet:

 

for (Contact c : [SELECT Email, Id FROM Contact WHERE AccountId = :account_id LIMIT 10]) {
  if(c.Email != null){
    try {
      Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
      message.setTemplateID(email_template.Id);
      message.setWhatId(detail.Id);
      message.setTargetObjectId(c.Id);
      Messaging.sendEmail(new Messaging.SingleEmailMessage[] { message });
    }    

    catch (System.LimitException e) {

      // I don't really care if the email fails.

      // I just don't want it to break my data entry process.

     }

     catch (Exception e) {

      // I don't really care if the email fails.

      // I just don't want it to break my data entry process.
    }
  }

}

 

updated: even explicitly catching system.limitexception fails.

"Send an Email" through the salesforce UI allows you to specify a "Related To" record which can be of type custom object OR standard object.

However the WhatId property through the API only allows standard objects.  Is this expected?

-------------- from the apex language reference -------------------------
Optional. If you specify a contact for the targetObjectId field, you can specify a whatId as well. This helps to further ensure that merge fields in the template contain the correct data. The value must be one of the following types:
  • Account
  • Asset
  • Campaign
  • Case
  • Contract
  • Opportunity
  • Order
  • Product
  • Solution
  • Custom



  • September 16, 2008
  • Like
  • 0