• June Power
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 7
    Replies
I added a trigger on Note with this scenario which works in the sandbox.  I also need a test class.  Can anyone assist?
trigger UpdateOppLastNote on Note (after insert, after update) {


List<Jr_Processing_Tasks__c> oppLstToUpdate=new List<Jr_Processing_Tasks__c>();
    if(Trigger.isInsert){
        for(Note nt : Trigger.new){
            {
                Jr_Processing_Tasks__c opp=new Jr_Processing_Tasks__c(Id=nt.parentId,Latest_Note__c=nt.Body); 
                oppLstToUpdate.add(opp);
            }   
        }
    }if(Trigger.isUpdate){
        for(Note nt : Trigger.new){
            {
                if(nt.Body != Trigger.oldMap.get(nt.Id).Body){
                   Jr_Processing_Tasks__c opp=new Jr_Processing_Tasks__c(Id=nt.parentId,Latest_Note__c=nt.Body); 
                    oppLstToUpdate.add(opp);
                }
            }
        }
    }
    if(!oppLstToUpdate.isEmpty()){
        try{
            update oppLstToUpdate;
        }catch(DmlException de ){
            System.debug(de);
        }
    }


}

 
I have two contact fields: Property_Address_from_Form__c and Loan_Needed_from_Form__c
which will be auto populated from an online survey into either my lead or my person account.

I need a trigger to create an opportunity associated with that lead/account when one or both of these fields are created.
opportunity to also show both of those fields.

opportunity close date = today()+45
opportunity stage = pre-qual
I added a trigger on Note with this scenario which works in the sandbox.  I also need a test class.  Can anyone assist?
trigger UpdateOppLastNote on Note (after insert, after update) {


List<Jr_Processing_Tasks__c> oppLstToUpdate=new List<Jr_Processing_Tasks__c>();
    if(Trigger.isInsert){
        for(Note nt : Trigger.new){
            {
                Jr_Processing_Tasks__c opp=new Jr_Processing_Tasks__c(Id=nt.parentId,Latest_Note__c=nt.Body); 
                oppLstToUpdate.add(opp);
            }   
        }
    }if(Trigger.isUpdate){
        for(Note nt : Trigger.new){
            {
                if(nt.Body != Trigger.oldMap.get(nt.Id).Body){
                   Jr_Processing_Tasks__c opp=new Jr_Processing_Tasks__c(Id=nt.parentId,Latest_Note__c=nt.Body); 
                    oppLstToUpdate.add(opp);
                }
            }
        }
    }
    if(!oppLstToUpdate.isEmpty()){
        try{
            update oppLstToUpdate;
        }catch(DmlException de ){
            System.debug(de);
        }
    }


}

 
Hello, 

I have created a field on the Opportunity object called Latest Note. When a user adds a new note to the Opportunitues Notes section I want to copy the Body and insert it to the field "Latest Note". Can a trigger be created on the Note object to handle this?

Thanks for all your help,
Ricky