• VDub
  • NEWBIE
  • 45 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 7
    Replies
Hi,

I'm getting an error on my trigger when I call the email class I created.  The Line in red is the one causing the error.  
I'm new to apex and any help would be appreciated .
Thanks, Vanessa

The Error

Method does not exist or incorrect signature: [AccCreatedEmailAlert].sendMail(LIST<Task>, SOBJECT:Task)

Class Code

public class AccCreatedEmailAlert{
public static void sendMail (User u, Task t) {
User u1 =[select Email from User where Id =: t.OwnerId limit 1];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddress = new String[] {u1.Email};
mail.setToAddresses(toAddress);
mail.setSubject('CS-Accommodation Order Task Created');
mail.setPlainTextBody('You are being sent this email because an CS-Accommodation Order Task has been created and assigned to you.\n\nThanks, SFDC');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}


Trigger Code

  User-added image


  • May 30, 2014
  • Like
  • 0
Hi,

I wrote a class to send an email and I'm getting an error when I try to save it to the Sandbox.

INVALID_CROSS_REFERENCE_KEY:invalid cross reference id
The only thing being referenced is a custom field on Task.  Assigned_To_Email__c, the custom field is a formula.
I double checked to make sure it was accessible by all users.  
I'm an Administrator working in a Sandbox so I should have access to all fields.
What level of access is needed to get past the error?

Thanks, Vanessa

Class Code:

public class SendEmailCreated{   
public void sendMail (User u, Task t) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String [] toAddress = New String [] {t.Assigned_To_Email__c};
mail.setToAddresses(toAddress);
mail.setSubject('CS-Accommodation Order Task Created');
mail.setPlainTextBody('You are being sent this email because an CS-Accommodation Order Task has been created and assigned to you.\n\nThanks, SFDC');

Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}

}





  • May 29, 2014
  • Like
  • 0
Hi,

I'm trying to color code my formula for percent change of YTD vs LYTD sales.  If the percent change is negative it make it red and if it's positive make it green.  I've been trying the stop lights but I would have to make another custom field instead of  changing the color of the value.  Is there anyway to do this?

Thanks, Vanessa 
  • March 27, 2014
  • Like
  • 0
Hi,

I've only created one trigger so I'm new to it.  I've created a custom button that fills out a form based on information from an opportunity.
I would like to create a trigger that initiates the custom button when a certain type of opportunity is saved.  
I need to use the custom button id to trigger the form
I've searched the boards but I can't find any sample code to go by.  I don't even know if this is possible.
This is what I've got so far and don't know where to go from here.

trigger ProEdgeFormTrigger on Opportunity (after update) {
for (Opportunity o : Trigger.new) {
if (o.Type == 'ProEdge')
   
    }
}

Any help would be greatly appreciated.  Thanks, Vanessa

  • January 24, 2014
  • Like
  • 0

Hi,

 

I'm new to triggers and I've been working on this for a week.  It works when I send it only to the Creator Email but when I add the Owner Email I get an error I don't know what I'm doing wrong. Any help would be much appreciated.

 

 It compiles fine but when I make an edit to the task I get this error:

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger QualityTaskEmailAlert caused an unexpected exception, contact your administrator: QualityTaskEmailAlert: execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: User.Email: Trigger.QualityTaskEmailAlert: line 39, column 1

 

 

Here is my trigger code, the line that is red is line 39:

 

/** This trigger sends an email message to the CreatedBy User when ActivityType = 'Maintenance - Quality' */
trigger QualityTaskEmailAlert on Task (after update) {
static final String SUBJECT = 'Quality Task Updated';
static final String BODY = 'You are being sent this email because the Quality Task "{0}" has been modified.\n\nCreated By: {5}\nAssigned To: {4}\nStatus: {1}\n\nClick the link below to view the task: \n{3}\n\nThanks, SFDC';

// Determine the creator's email and info about InsertionOrder for each Task, since it isn't in Trigger.new
List<Id> creatorIds = new List<Id>();
List<Id> ownerIds = new List<Id>();
List<Id> taskIDs = new List<Id>();
for (Task task : Trigger.new) {
if (task.Type == 'Maintenance - Quality') {
creatorIds.add(task.CreatedById);
ownerIds.add(task.OwnerId);
taskIDs.add(task.WhatId);
}
}

// Populate hashmap of Task Id to CreatedBy User's email address
List<User> creators = [Select Id, Email from User Where Id in :creatorIds];
Map<Id,String> creatorIdsToEmails = new Map<Id,String>();
for (User creator : creators) {
creatorIdsToEmails.put(creator.Id,creator.Email);
}
List<User> namecreators = [Select Id, FirstName, LastName from User Where Id in :creatorIds];
Map<Id,String> creatorIdsToNames = new Map<Id,String>();
for (User creator : creators) {
creatorIdsToNames.put(creator.Id,creator.Email);
}
// Populate hashmap of Owner UserId to Owner Name
List<User> owners = [Select Id, FirstName, LastName From User Where Id in :ownerIds];
Map<Id,String> ownerIdsToNames = new Map<Id,String>();
for (User owner : owners) {
ownerIdsToNames.put(owner.Id,owner.FirstName + ' ' + owner.LastName);
}

List<User> emailowners = [Select Id, Email From User Where Id in :ownerIds];
Map<Id,String> ownerIdsToEmails = new Map<Id,String>();
for (User owner : owners) {
ownerIdsToEmails.put(owner.Id,owner.Email);
}
// Populate hashmap of InsertionOrder Id (task.WhatId) to InsertionOrder Name
List<Task> tasks = [Select Id, Subject From Task Where ID in :taskIDs];
Map<Id,String> taskIDsToNames = new Map<Id,String>();
for (Task task : tasks) {
taskIDsToNames.put(task.Id, task.Subject);
}
for (Task task : Trigger.new) {
if (task.Type == 'Maintenance - Quality') {
try {
// send email to creator
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {creatorIdsToEmails.get(task.CreatedById)});
mail.setCcAddresses(new String[] {ownerIdsToEmails.get(task.OwnerId)});
mail.setSubject(SUBJECT);

// build a link to the relevant task programatically
String url = System.URL.getSalesforceBaseUrl().toExternalForm() + '/' + task.Id;

mail.setPlainTextBody(String.format(BODY,new String[]{
task.Subject ,task.Status, task.Type, url, OwnerIdsToNames.get(task.OwnerId), CreatorIdsToNames.get(task.CreatedById)
}));


Messaging.SendEmailResult[] result = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});

if (!result[0].isSuccess()) {
System.debug(LoggingLevel.ERROR, 'Failed to send email'+result[0].getErrors()[0].getMessage());
}

} catch (System.EmailException ex) {
System.debug(LoggingLevel.ERROR, 'Encountered EmailException');
}
}
}
}

 

  • October 31, 2013
  • Like
  • 0

Hi,

 

I'm new to creating triggers and I've been using the posts on this board to help me along but now I'm stuck. Any help would be greatly appreciated.

 

I'm trying to create a trigger for a specific type of task so when that task is updated it updates the fields on the custom object that has an Email Alert.

 

Here's my code:

 

trigger QualityTaskEmailAlertTrigger on Task (after insert) {

List <Custom_Task__c> vehToInsert = new List <Custom_Task__c> ();
for(Task t : Trigger.new) {
if (t.Type == 'Maintenance - Quality'){
Custom_Task__c ct = new Custom_Task__c ();
ct.OwnerId = t.OwnerId;
ct.CreatedById = t.CreatedById;
ct.LastModifiedById = t.LastModifiedById;
ct.Id = t.Id;
ct.Subject__c = t.Subject;

}
vehToinsert.add(ct);
}
}
try{
upsert vehToinsert;
} catch (system.DmlException e){
system.debug (e);
}

  • October 24, 2013
  • Like
  • 0
Hi,

I'm getting an error on my trigger when I call the email class I created.  The Line in red is the one causing the error.  
I'm new to apex and any help would be appreciated .
Thanks, Vanessa

The Error

Method does not exist or incorrect signature: [AccCreatedEmailAlert].sendMail(LIST<Task>, SOBJECT:Task)

Class Code

public class AccCreatedEmailAlert{
public static void sendMail (User u, Task t) {
User u1 =[select Email from User where Id =: t.OwnerId limit 1];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddress = new String[] {u1.Email};
mail.setToAddresses(toAddress);
mail.setSubject('CS-Accommodation Order Task Created');
mail.setPlainTextBody('You are being sent this email because an CS-Accommodation Order Task has been created and assigned to you.\n\nThanks, SFDC');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}


Trigger Code

  User-added image


  • May 30, 2014
  • Like
  • 0
Hi,

I wrote a class to send an email and I'm getting an error when I try to save it to the Sandbox.

INVALID_CROSS_REFERENCE_KEY:invalid cross reference id
The only thing being referenced is a custom field on Task.  Assigned_To_Email__c, the custom field is a formula.
I double checked to make sure it was accessible by all users.  
I'm an Administrator working in a Sandbox so I should have access to all fields.
What level of access is needed to get past the error?

Thanks, Vanessa

Class Code:

public class SendEmailCreated{   
public void sendMail (User u, Task t) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String [] toAddress = New String [] {t.Assigned_To_Email__c};
mail.setToAddresses(toAddress);
mail.setSubject('CS-Accommodation Order Task Created');
mail.setPlainTextBody('You are being sent this email because an CS-Accommodation Order Task has been created and assigned to you.\n\nThanks, SFDC');

Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}

}





  • May 29, 2014
  • Like
  • 0
Hi,

I'm trying to color code my formula for percent change of YTD vs LYTD sales.  If the percent change is negative it make it red and if it's positive make it green.  I've been trying the stop lights but I would have to make another custom field instead of  changing the color of the value.  Is there anyway to do this?

Thanks, Vanessa 
  • March 27, 2014
  • Like
  • 0
Hi,

I've only created one trigger so I'm new to it.  I've created a custom button that fills out a form based on information from an opportunity.
I would like to create a trigger that initiates the custom button when a certain type of opportunity is saved.  
I need to use the custom button id to trigger the form
I've searched the boards but I can't find any sample code to go by.  I don't even know if this is possible.
This is what I've got so far and don't know where to go from here.

trigger ProEdgeFormTrigger on Opportunity (after update) {
for (Opportunity o : Trigger.new) {
if (o.Type == 'ProEdge')
   
    }
}

Any help would be greatly appreciated.  Thanks, Vanessa

  • January 24, 2014
  • Like
  • 0

Hi,

 

I'm new to triggers and I've been working on this for a week.  It works when I send it only to the Creator Email but when I add the Owner Email I get an error I don't know what I'm doing wrong. Any help would be much appreciated.

 

 It compiles fine but when I make an edit to the task I get this error:

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger QualityTaskEmailAlert caused an unexpected exception, contact your administrator: QualityTaskEmailAlert: execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: User.Email: Trigger.QualityTaskEmailAlert: line 39, column 1

 

 

Here is my trigger code, the line that is red is line 39:

 

/** This trigger sends an email message to the CreatedBy User when ActivityType = 'Maintenance - Quality' */
trigger QualityTaskEmailAlert on Task (after update) {
static final String SUBJECT = 'Quality Task Updated';
static final String BODY = 'You are being sent this email because the Quality Task "{0}" has been modified.\n\nCreated By: {5}\nAssigned To: {4}\nStatus: {1}\n\nClick the link below to view the task: \n{3}\n\nThanks, SFDC';

// Determine the creator's email and info about InsertionOrder for each Task, since it isn't in Trigger.new
List<Id> creatorIds = new List<Id>();
List<Id> ownerIds = new List<Id>();
List<Id> taskIDs = new List<Id>();
for (Task task : Trigger.new) {
if (task.Type == 'Maintenance - Quality') {
creatorIds.add(task.CreatedById);
ownerIds.add(task.OwnerId);
taskIDs.add(task.WhatId);
}
}

// Populate hashmap of Task Id to CreatedBy User's email address
List<User> creators = [Select Id, Email from User Where Id in :creatorIds];
Map<Id,String> creatorIdsToEmails = new Map<Id,String>();
for (User creator : creators) {
creatorIdsToEmails.put(creator.Id,creator.Email);
}
List<User> namecreators = [Select Id, FirstName, LastName from User Where Id in :creatorIds];
Map<Id,String> creatorIdsToNames = new Map<Id,String>();
for (User creator : creators) {
creatorIdsToNames.put(creator.Id,creator.Email);
}
// Populate hashmap of Owner UserId to Owner Name
List<User> owners = [Select Id, FirstName, LastName From User Where Id in :ownerIds];
Map<Id,String> ownerIdsToNames = new Map<Id,String>();
for (User owner : owners) {
ownerIdsToNames.put(owner.Id,owner.FirstName + ' ' + owner.LastName);
}

List<User> emailowners = [Select Id, Email From User Where Id in :ownerIds];
Map<Id,String> ownerIdsToEmails = new Map<Id,String>();
for (User owner : owners) {
ownerIdsToEmails.put(owner.Id,owner.Email);
}
// Populate hashmap of InsertionOrder Id (task.WhatId) to InsertionOrder Name
List<Task> tasks = [Select Id, Subject From Task Where ID in :taskIDs];
Map<Id,String> taskIDsToNames = new Map<Id,String>();
for (Task task : tasks) {
taskIDsToNames.put(task.Id, task.Subject);
}
for (Task task : Trigger.new) {
if (task.Type == 'Maintenance - Quality') {
try {
// send email to creator
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {creatorIdsToEmails.get(task.CreatedById)});
mail.setCcAddresses(new String[] {ownerIdsToEmails.get(task.OwnerId)});
mail.setSubject(SUBJECT);

// build a link to the relevant task programatically
String url = System.URL.getSalesforceBaseUrl().toExternalForm() + '/' + task.Id;

mail.setPlainTextBody(String.format(BODY,new String[]{
task.Subject ,task.Status, task.Type, url, OwnerIdsToNames.get(task.OwnerId), CreatorIdsToNames.get(task.CreatedById)
}));


Messaging.SendEmailResult[] result = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});

if (!result[0].isSuccess()) {
System.debug(LoggingLevel.ERROR, 'Failed to send email'+result[0].getErrors()[0].getMessage());
}

} catch (System.EmailException ex) {
System.debug(LoggingLevel.ERROR, 'Encountered EmailException');
}
}
}
}

 

  • October 31, 2013
  • Like
  • 0