• jsnyder
  • NEWBIE
  • 55 Points
  • Member since 2013

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
trigger TaskCompletionMailerTrigger on Task (after update) {
	Task[] tasks = trigger.new;
    for (Task t : tasks) {
        if (t.Status.equals('Completed') && !t.OwnerId.equals(UserInfo.getUserId())) {
            User[] user = [SELECT Id, Email
                           FROM User
                           WHERE Id =: (t.OwnerId)]; 
            String userEmail;
            if (user.size() > 0) {
                userEmail = user[0].Email;
            } else {
                System.debug('User Lookup Failed on Task OwnerId: ' + t.OwnerId);
            }

			Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
			String[] toAddresses = new String[] { userEmail }; 
     
			mail.setToAddresses(toAddresses); 
            
			mail.setSubject('Automated Task Completion email: ' + t.Subject); 
            String rel = '';
			Account[] acct = [SELECT Id, Name
                 			  FROM Account
                			  WHERE Id =: t.AccountId];
            if (acct.size() > 0) {
                rel = 'Account - ' + acct[0].Name;
            }
            
			String body = 'Task: ' + t.Subject + '\nCompleted by ' + UserInfo.getName()
                + '\nRelated To: ' + rel + '\nComments: ' + t.Description; 
			mail.setPlainTextBody(body); 
            
			Messaging.sendEmail(new Messaging.SingleEMailMessage[]{mail});
        }
    }
}


@isTest (seeAllData=true)
public class TaskCompletionMailerTest{
    static testMethod void test() {
        Account acct = new Account(Name = 'Test Account');
        insert acct;
        User creator = new User(alias = 'crtr', email='patrick@eatstreet.com',
                                emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
                                localesidkey='en_US', profileid = UserInfo.getProfileId(),
                                timezonesidkey='America/Los_Angeles', username='creator@testorg.com');
        User completer = new User(alias = 'cmpltr', email='completer@test.com',
                                  emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
                                  localesidkey='en_US', profileid = UserInfo.getProfileId(),
                                  timezonesidkey='America/Los_Angeles', username='completer@testorg.com');
        insert creator;
        insert completer;
        
        Task t = new Task(Ownerid = creator.Id, Subject = 'Test', ActivityDate = Date.today(), 
                          WhatId = acct.Id, Status = 'Pending', Priority = 'Low', 
                	      Description = 'Test');
        insert t;
        
        Integer emailbefore = Limits.getEmailInvocations();
        System.runAs(completer) {
            t.Status = 'Completed';
            update t;
        }
        System.assertNotEquals(emailbefore,Limits.getEmailInvocations(),'should have decreased');
        
        emailbefore = Limits.getEmailInvocations();
        System.runAs(creator) {
            t.Status = 'Completed';
            update t;
        }
        System.assertEquals(emailbefore,Limits.getEmailInvocations(),'should remained constant');
    }
}


I am having touble deploying this. It keeps returning "Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []", Failure Stack Trace: "Class.IdleCaseTriggerTest.test: line 16, column 1"" 

 

I don't even have any code on line 16.
 

Hello! 

 

I have a custom field in the Accounts tab called, " Strategic Account", which is a NUMBER field 

 

I need to have this custom field in the OPPORTUNITY layout. 

 

 

So for example if I start a new Opportunity and select Account Name: Company ABC, the Strategic Account field will automatically populate to the number I associated it with in Accounts. 

 

Thanks in advance! 

 

-Rob 

trigger TaskCompletionMailerTrigger on Task (after update) {
	Task[] tasks = trigger.new;
    for (Task t : tasks) {
        if (t.Status.equals('Completed') && !t.OwnerId.equals(UserInfo.getUserId())) {
            User[] user = [SELECT Id, Email
                           FROM User
                           WHERE Id =: (t.OwnerId)]; 
            String userEmail;
            if (user.size() > 0) {
                userEmail = user[0].Email;
            } else {
                System.debug('User Lookup Failed on Task OwnerId: ' + t.OwnerId);
            }

			Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
			String[] toAddresses = new String[] { userEmail }; 
     
			mail.setToAddresses(toAddresses); 
            
			mail.setSubject('Automated Task Completion email: ' + t.Subject); 
            String rel = '';
			Account[] acct = [SELECT Id, Name
                 			  FROM Account
                			  WHERE Id =: t.AccountId];
            if (acct.size() > 0) {
                rel = 'Account - ' + acct[0].Name;
            }
            
			String body = 'Task: ' + t.Subject + '\nCompleted by ' + UserInfo.getName()
                + '\nRelated To: ' + rel + '\nComments: ' + t.Description; 
			mail.setPlainTextBody(body); 
            
			Messaging.sendEmail(new Messaging.SingleEMailMessage[]{mail});
        }
    }
}


@isTest (seeAllData=true)
public class TaskCompletionMailerTest{
    static testMethod void test() {
        Account acct = new Account(Name = 'Test Account');
        insert acct;
        User creator = new User(alias = 'crtr', email='patrick@eatstreet.com',
                                emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
                                localesidkey='en_US', profileid = UserInfo.getProfileId(),
                                timezonesidkey='America/Los_Angeles', username='creator@testorg.com');
        User completer = new User(alias = 'cmpltr', email='completer@test.com',
                                  emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
                                  localesidkey='en_US', profileid = UserInfo.getProfileId(),
                                  timezonesidkey='America/Los_Angeles', username='completer@testorg.com');
        insert creator;
        insert completer;
        
        Task t = new Task(Ownerid = creator.Id, Subject = 'Test', ActivityDate = Date.today(), 
                          WhatId = acct.Id, Status = 'Pending', Priority = 'Low', 
                	      Description = 'Test');
        insert t;
        
        Integer emailbefore = Limits.getEmailInvocations();
        System.runAs(completer) {
            t.Status = 'Completed';
            update t;
        }
        System.assertNotEquals(emailbefore,Limits.getEmailInvocations(),'should have decreased');
        
        emailbefore = Limits.getEmailInvocations();
        System.runAs(creator) {
            t.Status = 'Completed';
            update t;
        }
        System.assertEquals(emailbefore,Limits.getEmailInvocations(),'should remained constant');
    }
}


I am having touble deploying this. It keeps returning "Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []", Failure Stack Trace: "Class.IdleCaseTriggerTest.test: line 16, column 1"" 

 

I don't even have any code on line 16.
 

I have a trigger and have to change the logic a little check if a number field is Null. I have done some research and everything is telling me to use the IsNull Fuction and it keep getting the error below and Can't figure it out. I have the section of code that is giving me the issue. 

Error Error: Compile Error: Method does not exist or incorrect signature: IsNull(Decimal) at line 3 column 4

trigger AssignTerritoryType on Account (Before insert, Before update) {
    For (Account a :trigger.new){
if(IsNull(a.Fortune_1000_Rank__c) && (a.NumberOfEmployees >= 10000) && (a.Industry != 'Education')==True  ||
   IsNull(a.Fortune_1000_Rank__c) && (a.AnnualRevenue >= 800000000) && (a.Industry != 'Education')==True  ||
    a.Industry == 'Energy' ||
    a.Industry == 'Pharma/BioTech' ||
    a.Industry == 'Fed - Gov'  ||
    a.Fortune_1000_Rank__c <=650 )
    {
  a.Major__c=true;
  a.Mid__c=False;
  a.Inside__c=False;
  a.Inside_small__c=False;
    }

Hello! 

 

I have a custom field in the Accounts tab called, " Strategic Account", which is a NUMBER field 

 

I need to have this custom field in the OPPORTUNITY layout. 

 

 

So for example if I start a new Opportunity and select Account Name: Company ABC, the Strategic Account field will automatically populate to the number I associated it with in Accounts. 

 

Thanks in advance! 

 

-Rob