• ChrisMagellan
  • NEWBIE
  • 10 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
Hi guys,

I'm pulling my hair out with this one, as almost identical code is working fine in another class!

I'm trying to run the below code and I'm getting a consistent error: FATAL_ERROR|System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Invalid to address : null: []

When I debug the toAddresses list and the whoel mail message it's not taking any of the inputs!

global class NBAAForward implements Messaging.InboundEmailHandler {

global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
 
  Messaging.reserveSingleEmailCapacity(1);
 
  Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
 
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

  String[] toAddresses = new String[] {'nickc@magellanjets.com'};
  String[] ccAddresses = new String[] {email.fromAddress};

  mail.setToAddresses(toAddresses);
  system.debug(mail.toAddresses);
  mail.setCcAddresses(ccAddresses);
 
  mail.setSenderDisplayName('Magellan Jets');
 
  mail.setSubject(email.Subject);
 
  mail.setBccSender(false);
 
  mail.setUseSignature(false);
 
  mail.setPlainTextBody('PLEASE REPLY TO ' + email.fromAddress + '\n \n' + email.plainTextBody);
  system.debug(mail);
  Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
  
  return result;
}

public static testmethod void testEmail() {
 
  // create new email for testing
  Messaging.InboundEmail email = new Messaging.InboundEmail();
  Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
 
  email.subject = 'test nbaa post';
  env.fromAddress = 'chris@magellanjets.com';
 
  email.plainTextBody = 'TEST NBAA POST';
 
  NBAAForward emailServiceObj = new NBAAForward();
  emailServiceObj.handleInboundEmail(email, env);
 
}

}

I have a user who's been happily using the Outlook sidebar for the past couple of months. Earlier today it started refusing to connect and giving this error: An attempt was made to access a socket in a way forbidden by its access permissions [salesforce ip address]:443

 

When I try to update the settings for the user I get a message that it's unable to connect to login.salesforce.com.

 

He's able to access the website from the same computer without any issues. I did find a forum post for troubleshooting errors like that, and went through everything but it didn't help.

 

Anyone seen this before or have any insight?

 

Thanks!
Chris

Close to my wits' end on this one. I have a trigger that calls a Future class. When I run through my tests I get up to 7 future calls. I then add another conditional to my SOQL query in the trigger, and the whole thing breaks, highlighting a random line in my class and saying  I'm suddenly using 11 future calls.

 

Trigger:

 

if (trigger.isInsert) {
			for (Contact workingContact : trigger.new) {
				// Check for existing Contacts
				List<Contact> orgContacts = [Select Id, Name, Email from Contact where ( Name = :workingContact.Name and Email = :workingContact.Email and Email != null and Id != :workingContact.Id)];
				if (orgContacts.size() != 0) {
					NotificationEmail.AvianisError(orgContacts[0].Id, orgContacts[0].Name, 'Duplicate Contact found on Contact insert');
					continue;
				}
				// Insert Contact into Avianis
				if (workingContact.AvianisID__c == null && workingContact.AccountId != null) {
					Avianis.aviContactFuture('insert', workingContact.Id);
				}
			}
		}

 Future method called:

// Contact method
    @future (callout=true)
    public static void aviContactFuture(String operation, String conId) {
    	
    	// Get contact info
        List<Contact> sfContacts = new List<Contact>();
        
        sfContacts = [SELECT Contact.Id, ...
                      FROM Contact WHERE Contact.Id = :conID ALL ROWS];
                      
        if (sfContacts.size() == 0) {
        	return;
        }   

    	aviContact(operation, sfContacts[0]);
    }

 The aviContact method builds a SOAP envelope and sends it, then updates the Contact with a return value. Eclipse is highlighting a random line in the aviContact method (where it's setting a variable with "") as System.LimitException: Too many future calls: 11

 

In case it matters, here's the NotificationEmail.AvianisError method:

public static void AvianisError(Id EId, String EName, String ErrType) {
		// Send notification email if Avianis trigger encounters an error.
		
		Messaging.SingleEmailMessage mail = new Messaging.Singleemailmessage();
		mail.setSaveAsActivity(false);
		String mailSubject = 'Avianis Trigger Error: ' + EName;
		String mailBody = 'Error for: ' + EName + ' https://na14.salesforce.com/' + EId + '\n\n' + 'Error Code: ' + ErrType;
		mail.setToAddresses(new String[] {'**@**.com'});
		mail.setSubject(mailSubject);
		mail.setPlainTextBody(mailBody);
		
		Messaging.sendEMail(new Messaging.SingleEmailMessage[] {mail});
		
	}

 

I'm going nuts here, any ideas?

I have triggers that run after insert on Account and Contact. The Contact trigger get the Contact.Account.Id value and passes it to a @future method for further processing. This works fine on normal Contact creation, but it's returning "null" for any related Contact.Account information I try to pull when the trigger runs during the Lead Conversion process.

Anyone know what's happening here or if there's a workaround?

Here's the relevant trigger code:

trigger AvianisUpdateContact on Contact (after delete, after insert, after undelete, after update) {

System.debug('Update Contact trigger run');
if (trigger.isInsert) {
Contact workingContact = Trigger.new[0];
System.debug('Insertion of contact ' + workingContact.FirstName + ' ' + workingContact.LastName + ' Acct name and id: ' + workingContact.Account.Name + ' ' + workingContact.Account.Id);
try {
Avianis.aviContact('Insert', workingContact.Id);
} catch(System.CalloutException e) {
System.debug('aviContact insert error: ' + e);
}
}

 

Close to my wits' end on this one. I have a trigger that calls a Future class. When I run through my tests I get up to 7 future calls. I then add another conditional to my SOQL query in the trigger, and the whole thing breaks, highlighting a random line in my class and saying  I'm suddenly using 11 future calls.

 

Trigger:

 

if (trigger.isInsert) {
			for (Contact workingContact : trigger.new) {
				// Check for existing Contacts
				List<Contact> orgContacts = [Select Id, Name, Email from Contact where ( Name = :workingContact.Name and Email = :workingContact.Email and Email != null and Id != :workingContact.Id)];
				if (orgContacts.size() != 0) {
					NotificationEmail.AvianisError(orgContacts[0].Id, orgContacts[0].Name, 'Duplicate Contact found on Contact insert');
					continue;
				}
				// Insert Contact into Avianis
				if (workingContact.AvianisID__c == null && workingContact.AccountId != null) {
					Avianis.aviContactFuture('insert', workingContact.Id);
				}
			}
		}

 Future method called:

// Contact method
    @future (callout=true)
    public static void aviContactFuture(String operation, String conId) {
    	
    	// Get contact info
        List<Contact> sfContacts = new List<Contact>();
        
        sfContacts = [SELECT Contact.Id, ...
                      FROM Contact WHERE Contact.Id = :conID ALL ROWS];
                      
        if (sfContacts.size() == 0) {
        	return;
        }   

    	aviContact(operation, sfContacts[0]);
    }

 The aviContact method builds a SOAP envelope and sends it, then updates the Contact with a return value. Eclipse is highlighting a random line in the aviContact method (where it's setting a variable with "") as System.LimitException: Too many future calls: 11

 

In case it matters, here's the NotificationEmail.AvianisError method:

public static void AvianisError(Id EId, String EName, String ErrType) {
		// Send notification email if Avianis trigger encounters an error.
		
		Messaging.SingleEmailMessage mail = new Messaging.Singleemailmessage();
		mail.setSaveAsActivity(false);
		String mailSubject = 'Avianis Trigger Error: ' + EName;
		String mailBody = 'Error for: ' + EName + ' https://na14.salesforce.com/' + EId + '\n\n' + 'Error Code: ' + ErrType;
		mail.setToAddresses(new String[] {'**@**.com'});
		mail.setSubject(mailSubject);
		mail.setPlainTextBody(mailBody);
		
		Messaging.sendEMail(new Messaging.SingleEmailMessage[] {mail});
		
	}

 

I'm going nuts here, any ideas?

I have triggers that run after insert on Account and Contact. The Contact trigger get the Contact.Account.Id value and passes it to a @future method for further processing. This works fine on normal Contact creation, but it's returning "null" for any related Contact.Account information I try to pull when the trigger runs during the Lead Conversion process.

Anyone know what's happening here or if there's a workaround?

Here's the relevant trigger code:

trigger AvianisUpdateContact on Contact (after delete, after insert, after undelete, after update) {

System.debug('Update Contact trigger run');
if (trigger.isInsert) {
Contact workingContact = Trigger.new[0];
System.debug('Insertion of contact ' + workingContact.FirstName + ' ' + workingContact.LastName + ' Acct name and id: ' + workingContact.Account.Name + ' ' + workingContact.Account.Id);
try {
Avianis.aviContact('Insert', workingContact.Id);
} catch(System.CalloutException e) {
System.debug('aviContact insert error: ' + e);
}
}