• alex51atlas
  • NEWBIE
  • 0 Points
  • Member since 2011

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

I am trying to send out a list of emails using an Org Wide Email address via apex but it is timing out. The emails are sent out quickly without any issues when I don't use the setOrgWideEmailAddressId() function. This is an unacceptable user experience because the page keeps on loading until it times out. 

Unfortunately I need to use an org wide email address because the email must be sent from a generic email, not the logged in user's.

 

To test out the functionality on its own I executed the following code snippet as annonymous apex and it took 3.2 minutes to finish executing. This is just for a single email.

 

List<Messaging.Email> emails = new List<Messaging.Email>();
EmailTemplate template = [SELECT Name, Markup, HtmlValue, Body, DeveloperName FROM EmailTemplate WHERE DeveloperName = 'Some_Email_Template'];
OrgWideEmailAddress replyEmail = [SELECT ID, DisplayName FROM OrgWideEmailAddress WHERE Address =: 'address@sample.com'];

// The logic here is repeated in a for loop for various contacts
Messaging.SingleEmailMessage currEmail =  new Messaging.SingleEmailMessage();

currEmail.setTemplateId(template.Id);
currEmail.setTargetObjectId('003S000000QcNfl'); // Add a contact ID
currEmail.setWhatId('701S00000007YTgIAM'); // Set a campaign ID
currEmail.setOrgWideEmailAddressId(replyEmail.Id);

// This is why I am putting the emails in a list, then sending them all
emails.add(currEmail);

Messaging.sendEmail(emails);

 Last execution at 11/30 13:38:44 in 192,171 milliseconds.

 

 

Is there a reason why this takes so long to complete when running as an annonymous apex script? In the UI it times out.

 

OR
 

Is there another way I can achieve this without providing an unacceptable user experience?

 

I am having trouble inserting a list of chatter feed items of type 'ContentPost'. These feed items are being dynamically created for a list of contacts/campaign members (post.ParentId = 'contact id goes here') associated to a campaign; as well as the campaign itself. While I am iterating over the list of contacts I am also creating an attachment for each of them then
associating this attachment to the feed item. Both Attachments and Feed Items are added to separate lists then post for loop are inserted into the database.

 

I am able to successfully insert the chatter feed items (as text post posts, not content) if I don't associated the attachments, however when I associate the attachment body to the content data field of the feed item I get the following error:

 

Insert failed. First exception on row 0; first error: INVALID_ID_FIELD, You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.: []

 

I am running this as a system administrator on our dev sandbox, so I'm not sure what is causing this insufficient privileges error. I would appreciate any help on this, and if needed I can provide a more technical description with code snippets of the logic.

Does anyone know how to send an email, from a template, via apex code, as someone other than the currently logged in user? Maybe using a company org-wide email?

java.lang.IllegalArgumentException: Illegal view ID '. The ID must begin with / 

 

I have the following VF page, whose controller performs some validation logic and if succesful redirects, in a new window, to a visualforce page rendered as a PDF. Afterwards the logic inside the addTitleVISubmissions function (from the action tag) is executed .

 

<apex:page standardController="Campaign" extensions="TitleVIMailController" action="{!addTitleVISubmissions}">
...
</apex:page>

 The addTitleVISubmissions function looks like so:

public PageReference addTitleVISubmissions() {
	if ( !errorsFound && whichLetter.equalsIgnoreCase('first') ) {
		List <OCIO_Title_VI_Submission__c> titleVISubmissions = 
			new List<OCIO_Title_VI_Submission__c>();

		for ( CampaignMember curr : contactList ) {
			OCIO_Title_VI_Submission__c currSubmission = new OCIO_Title_VI_Submission__c();
			currSubmission.OCR_Donee_Contact__c = curr.ContactId; // The issue comes with this lookup field

			currSubmission.OCR_Submission_Status__c = 'No Activity';
			currSubmission.OCR_Rollout__c = campgn.Id;
			titleVISubmissions.add(currSubmission);
		}
		database.insert(titleVISubmissions);
	}
	return null;
}

Anyway, I've pin pointed an issue with writing to the OCR_Donee_Contact__c field (simple lookup field to Contact). If I leave the code as is above, instead of rending the dynamic PDF page I get the following error:

 

java.lang.IllegalArgumentException: Illegal view ID '. The ID must begin with / 

 

The records generated in the for loop are correctly inserted, but the user sees a salesforce page with the error above instead of the visualforce PDF page.

 

If I comment out that line, everything works fine, the PDF is displayed and the records are inserted. However, since I commented out the line that populates the lookup field I don't have a reference to the contacts on these records.

 

I've looked into this error and it seems like it occurs if the action function contains a string literal instead of a function name, but this is clearly not the case here. Can anyone shed some light as to why the system would behave this way or why I am getting this issue in this situation?

 

Thanks in advance.

 

 

 

 

I am trying to send out a list of emails using an Org Wide Email address via apex but it is timing out. The emails are sent out quickly without any issues when I don't use the setOrgWideEmailAddressId() function. This is an unacceptable user experience because the page keeps on loading until it times out. 

Unfortunately I need to use an org wide email address because the email must be sent from a generic email, not the logged in user's.

 

To test out the functionality on its own I executed the following code snippet as annonymous apex and it took 3.2 minutes to finish executing. This is just for a single email.

 

List<Messaging.Email> emails = new List<Messaging.Email>();
EmailTemplate template = [SELECT Name, Markup, HtmlValue, Body, DeveloperName FROM EmailTemplate WHERE DeveloperName = 'Some_Email_Template'];
OrgWideEmailAddress replyEmail = [SELECT ID, DisplayName FROM OrgWideEmailAddress WHERE Address =: 'address@sample.com'];

// The logic here is repeated in a for loop for various contacts
Messaging.SingleEmailMessage currEmail =  new Messaging.SingleEmailMessage();

currEmail.setTemplateId(template.Id);
currEmail.setTargetObjectId('003S000000QcNfl'); // Add a contact ID
currEmail.setWhatId('701S00000007YTgIAM'); // Set a campaign ID
currEmail.setOrgWideEmailAddressId(replyEmail.Id);

// This is why I am putting the emails in a list, then sending them all
emails.add(currEmail);

Messaging.sendEmail(emails);

 Last execution at 11/30 13:38:44 in 192,171 milliseconds.

 

 

Is there a reason why this takes so long to complete when running as an annonymous apex script? In the UI it times out.

 

OR
 

Is there another way I can achieve this without providing an unacceptable user experience?

 

I am trying to send out a list of emails using an Org Wide Email address via apex but it is timing out. The emails are sent out quickly without any issues when I don't use the setOrgWideEmailAddressId() function. This is an unacceptable user experience because the page keeps on loading until it times out. 

Unfortunately I need to use an org wide email address because the email must be sent from a generic email, not the logged in user's.

 

To test out the functionality on its own I executed the following code snippet as annonymous apex and it took 3.2 minutes to finish executing. This is just for a single email.

 

List<Messaging.Email> emails = new List<Messaging.Email>();
EmailTemplate template = [SELECT Name, Markup, HtmlValue, Body, DeveloperName FROM EmailTemplate WHERE DeveloperName = 'Some_Email_Template'];
OrgWideEmailAddress replyEmail = [SELECT ID, DisplayName FROM OrgWideEmailAddress WHERE Address =: 'address@sample.com'];

// The logic here is repeated in a for loop for various contacts
Messaging.SingleEmailMessage currEmail =  new Messaging.SingleEmailMessage();

currEmail.setTemplateId(template.Id);
currEmail.setTargetObjectId('003S000000QcNfl'); // Add a contact ID
currEmail.setWhatId('701S00000007YTgIAM'); // Set a campaign ID
currEmail.setOrgWideEmailAddressId(replyEmail.Id);

// This is why I am putting the emails in a list, then sending them all
emails.add(currEmail);

Messaging.sendEmail(emails);

 Last execution at 11/30 13:38:44 in 192,171 milliseconds.

 

 

Is there a reason why this takes so long to complete when running as an annonymous apex script? In the UI it times out.

 

OR
 

Is there another way I can achieve this without providing an unacceptable user experience?

 

I am having trouble inserting a list of chatter feed items of type 'ContentPost'. These feed items are being dynamically created for a list of contacts/campaign members (post.ParentId = 'contact id goes here') associated to a campaign; as well as the campaign itself. While I am iterating over the list of contacts I am also creating an attachment for each of them then
associating this attachment to the feed item. Both Attachments and Feed Items are added to separate lists then post for loop are inserted into the database.

 

I am able to successfully insert the chatter feed items (as text post posts, not content) if I don't associated the attachments, however when I associate the attachment body to the content data field of the feed item I get the following error:

 

Insert failed. First exception on row 0; first error: INVALID_ID_FIELD, You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.: []

 

I am running this as a system administrator on our dev sandbox, so I'm not sure what is causing this insufficient privileges error. I would appreciate any help on this, and if needed I can provide a more technical description with code snippets of the logic.

Does anyone know how to send an email, from a template, via apex code, as someone other than the currently logged in user? Maybe using a company org-wide email?