• cmaine3
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 6
    Replies

Hi everyone,

 

So I have a trigger that is workin ggreat in the test environment and I thought I could just bang out the test class and get it over. Well, I can't seem to write test code I guess. Can anyone advise?

 

Trigger-

trigger update30DayNoticeSentOnTaskComplete on Task (after update) {
public Id oppId;
for(Task t:Trigger.New){
if(t.WhatId != NULL)
if(t.Subject=='Send Out Notice To Vacate')
if(t.Status=='Completed'){
oppId = t.WhatId;
}
}
List<Opportunity> opp = [select Id from Opportunity where id = :oppId];
for(Opportunity o : opp){
o.X30_Day_Letter_Sent__c = system.today()+5;
update o;
}

}

 

 

Hi There!

 

I have a need to update a date field on an opportunity when the task status is changed to completed.Workflow as follows:

 

Task marked "Completed" > Field "Follow up date" = TODAY() + 5

 

Pretty simple, but I will be using this trigger as framework for other triggers to get all our reps in line to follow through with a process, so it's pretty important. Thanks anyone who's willing to help.

 

 

Hi there-

 

So I got assistance on this code, built the test class and deployed it. It works fine when creating a Task under Opp but throws a null pointer exception error when I create a task under any other object.

 

Goal: When adding a task in opportunity automatically pull the assigned rep and select the picklist field for them on the task. When no rep selected do nothing.

 

Both fields are named Assigned_Rep__c, however the field on the Opp is a reference Assigned_Rep__r.Name. I do not need any trigger except when accessed from an opportunity.

 

Error:

 

Attempt to de-reference a null object Trigger.populatePicklist: line 9, column 34

 Trigger

trigger populateAssignedRep on Task(before insert, before update){
    
    
    String oppPrefix = Schema.SObjectType.Opportunity.getKeyPrefix();
    List<Id> oppIds = new List<Id>();
    
    for(Task t: Trigger.new){
        String relatedTo = (String)t.WhatId;
        String relatedToPrefix = relatedTo.subString(0,3);
        if(oppPrefix == relatedToPrefix){
           oppIds.add(t.WhatId);
        }
    }
    
    Map<Id,Opportunity> oppMap = new Map<Id,Opportunity>();
    if(!oppIds.isEmpty()){
        oppMap.putAll([Select Id, Name, Assigned_Rep__c, Assigned_Rep__r.Name from Opportunity where Id IN :oppIds]);
        
    
          for(Task t: trigger.new){
             String relatedTo = (String)t.WhatId;
             String relatedToPrefix = relatedTo.subString(0,3);
             if(oppPrefix == relatedToPrefix){
                if(oppMap.containsKey(t.WhatId)){
                   Opportunity opp = oppMap.get(t.WhatId);
                   if(opp.Assigned_Rep__c != null){
                      t.ARI_Rep__c = opp.Assigned_Rep__r.Name;                    }
                }
             }
          }
    }
}

 

I'm using this as my first venture into triggers, and was able to handle the test class by myself, so I am extremely appreciative of the help I am getting. Thanks everyone.

 

Hello everyone-

This should be a quick slam dunk for any trigger masters out there and should help me to start learning myself.

 

Goal-

When a task is added to an Opportunity the lookup field Rep_Team__c on the opportunity record is checked. If the field is populated then it will take that value and convert it to the corresponding task record picklist value Rep_Tm__c.

 

This is 1:1 conversion or nothing. (meaning if the picklist value is not available then it will be left alone.)

 

I really wish I could give more information than this but I don't understand the syntax and am hoping that by seeing the working code I can learn to create my own.

 

Thanks for any help!!

 

 

 

 

 

Hi All,
     I wish to associate a custom tab view to a visualforce page , is it possible if so kindly guide me with the  appropriate steps.


Thanks in Advance
Regards
Nalini

Message Edited by Nalini on 06-03-2009 12:18 AM
Message Edited by Nalini on 06-03-2009 03:50 AM
Message Edited by Nalini on 06-03-2009 03:52 AM