• Matt Field
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 27
    Replies
Hi All,

I am working on a trigger that looks at the status of a project and then updates the StageName of the associated opportunity.  I have it working for a single project status (Project Closed - Live) where it will update the Opportunity StageName to "Implementation Complete", but I need help to figure out how to change the Opportunity StageName to 'Closed - Inactive' if the project status = 'Project Closed - Not Implemented'.  I have attached the trigger below:

trigger UpdateBillDate on Milestone1_Project__c (before insert, before update) {

List<ID> OppIds = New List<ID>();
 
    for(Milestone1_Project__c o : Trigger.new){
        if(o.Projected_Live_Date__c != null && o.Status__c == 'Project Closed - Live'){
            OppIds.add(o.OpportunityID__c);
        }
    }
 
    List<Opportunity> oppList = [SELECT id, Billing_Date__c
                                                        FROM Opportunity
                                                       WHERE id in :OppIds];
    List<Milestone1_Project__c> mproj =[SELECT OpportunityID__c, Status__c, Projected_Live_Date__c
                                                                         FROM Milestone1_Project__c
                                                                        WHERE OpportunityID__c in: OppIds];
    for (Milestone1_Project__c milestone: Trigger.new) {
      
            for(Opportunity opp:oppList){
                    opp.Billing_Date__c = milestone.Projected_Live_Date__c;
                 opp.StageName = 'Implementation Complete';
            }
      }
       
 
    update oppList;
   
}

Any help you can provide will be GREATLY appreciated.

Thanks,

Matt
Hi all.  I am looking for some help with what should be a simple trigger.  What I want to do is update the Billing_Date__c field in the Opportunity object with the value from the Projected_Live_Date from the Milestone1_Project__c object when the following conditions are met:  1. Milestone1_Project__c.Status = "Project on Target", 2. Milestone1_Project__c.Projected_Live_Date__c != null, and 3. Opportunity.Probability = 95%.  Here is what I have so far:

trigger UpdateBillDate on Milestone1_Project__c (before insert) {
   
    List<ID> OppIds = New List<ID>();
   
    for(Milestone1_Project__c o : Trigger.new){
        if(o.Status__c == 'Project on Target' && o.Projected_Live_Date__c != null){
            OppIds.add(o.Opportunity);
        }
    }
   
    List<Opportunity> oppList = [SELECT id, Billing_Date__c FROM Opportunity WHERE
                                    id in :OppIds];
    for(integer i = 0 ; i < oppList.size(); i++){
        oppList[i].Billing_Date__c = Milestone1_Project__r.Projected_Live_Date__c;
    }
   
    update oppList;
}

Any help will be GREATLY appreciated.

Thanks
I have a registration controller that has the following code snippet:

public PageReference mysaveLead() {        ld.LeadSource = 'Early Warning Summit';        ld.OwnerId = '005400000012y4L';                message = 'Thank you for registering ' + ld.FirstName + '. Please Select File->Print in your browser to print your registration information.';        mode = true;        Contact[] c = [Select Name, LastName, FirstName, Id, Email FROM Contact WHERE Email =: ld.Email];        // Campaign ID 70140000000MPzt is the Summit 2011 Campaign        // Campaign ID 70140000000Mm1c is the Summit 2012 Campaign        // Campaign ID 70140000000O0nr is the Summit 2013 Campaign         Campaign cam = [ SELECT ID, Status FROM Campaign WHERE ID='70140000000osgB'];

Currently the controller shows a confirmation message at the top of the page when the user has completed the registration.  I would like to change that to sending the user to a webpage that will be set up to show that the user has successfully registered.  Can someone tell me how to push them to the webpage?  I think that I just have to change the "message =" line, but I don't know what to change it to.

Thanks

I have the following trigger on the Opportunity object to perform revenue calculations, and I need help making these updates:

 

1.  Change when the trigger is fired from the current:  Trigger.new[i].Opportunity.LastModifiedDate != Trigger.old[i].LastModifiedDate to use the LastModifiedDate from OpportunityLineItem or OpportunityLineItemSchedule instead.

 

2.  I have to add a new field to the Opportunity object to calculate first year revenue (FTV__c).  This calculation is different from the one in the trigger in that this calculation has to look at the first 12 months of revenue and use that number to populate FTV__c.  The First_Year_Revenue__c field in the trigger only looks at the revenue in the calendar year.

 

trigger reestablishServiceSchedule on Opportunity (after update) {

    Set<Id> oppIds = new Set<Id>();
    List<OpportunityLineItemSchedule> schedules = new List<OpportunityLineItemSchedule>();
    List<OpportunityLineItem> olis = new List<OpportunityLineItem>();

    if(!ProcessorControl.isTriggered){
        
        for(Integer i = 0; i < Trigger.new.size(); i++){
            if(Trigger.new[i].LastModifiedDate!=Trigger.old[i].LastModifiedDate){
                oppIds.add(Trigger.new[i].Id);
            }
        }
        
        
        for (OpportunityLineItem oli: [Select Id, PricebookEntry.Product2.Family, PricebookEntry.Product2.Name, Opportunity.Billing_Date__c, ServiceDate, First_Year_Revenue__c, Second_Year_Revenue__c, Third_Year_Revenue__c, Fourth_Year_Revenue__c, (Select Id, ScheduleDate, Revenue From OpportunityLineItemSchedules Order By ScheduleDate Asc) From OpportunityLineItem Where HasRevenueSchedule = true AND Opportunity.ID IN: oppIds]){
            Date closeDate = oli.Opportunity.Billing_Date__c;
            for(Integer i = 0; i < oli.OpportunityLineItemSchedules.size(); i++){
                oli.OpportunityLineItemSchedules[i].ScheduleDate = closeDate.addMonths(i);
                schedules.add(oli.OpportunityLineItemSchedules[i]);
            }
            oli.ServiceDate = oli.Opportunity.Billing_Date__c;
            olis.add(oli);
        }
        update olis;
        update schedules;
        
        olis = new List<OpportunityLineItem>();
        for (OpportunityLineItem oli: [Select Id, Opportunity.Billing_Date__c, First_Year_Revenue__c, Second_Year_Revenue__c, Third_Year_Revenue__c, Fourth_Year_Revenue__c, TotalPrice, HasRevenueSchedule, (Select Id, ScheduleDate, Revenue From OpportunityLineItemSchedules Order By ScheduleDate Asc) From OpportunityLineItem Where Opportunity.ID IN: oppIds]){
            double firstYearRevenue = 0;
            double secondYearRevenue = 0;
            double thirdYearRevenue = 0;
            double FourthYearRevenue = 0;
            if(oli.HasRevenueSchedule){
                for(OpportunityLineItemSchedule sched: oli.OpportunityLineItemSchedules){
                    if(oli.Opportunity.Billing_Date__c.year() == sched.ScheduleDate.year()){
                            firstYearRevenue += sched.Revenue;
                    } else if(oli.Opportunity.Billing_Date__c.year()+ 1 == sched.ScheduleDate.year()){
                            secondYearRevenue += sched.Revenue;
                    } else if(oli.Opportunity.Billing_Date__c.year()+ 2 == sched.ScheduleDate.year()){
                            thirdYearRevenue += sched.Revenue;
                    } else if(oli.Opportunity.Billing_Date__c.year() + 3 == sched.ScheduleDate.year()){
                            FourthYearRevenue += sched.Revenue;
                    }
                }
            } else {
                firstYearRevenue = oli.TotalPrice;
            }
            oli.First_Year_Revenue__c = firstYearRevenue;
            oli.Second_Year_Revenue__c = secondYearRevenue;
            oli.Third_Year_Revenue__c = thirdYearRevenue;
            oli.Fourth_Year_Revenue__c = FourthYearRevenue;
            olis.add(oli);
        }
        update olis;
    }

}

 Any help provided will be GREATLY appreciated.

 

Thanks,

 

Matt

I am looking for some help with a simple trigger.  I want to update the opportunity with the product name from the product2 object.  I can't get it to work for some reason.

 

trigger addServiceInformation on Opportunity (before insert, before update) {

	Set<Id>oppIds = new Set<Id>();
	Map<Id,String>oppIdMap = new Map<Id,String>();
	
	for(Integer i = 0;i<Trigger.new.size();i++){
		
		oppIds.add(Trigger.new[i].Id);
		
		
	}
	for(OpportunityLineItem oli:[SELECT Id, PricebookEntry.Product2.Name FROM OpportunityLineItem WHERE Id IN:oppIds AND HasRevenueSchedule = TRUE]){
		oppIdMap.put(oli.Id, oli.PricebookEntry.Product2.Name);
		
	}
	
	for(Opportunity o: Trigger.new){
		o.Service_Name__c=oppIdMap.get(o.Id);
	}
}

 Eventually, I would like to add more than 1 field with the same trigger, but the second field is a picklist, and I don't know how to add a picklist value to a text field in a trigger.

 

Any help will be GREATLY appreciated.

I have a trigger that we use to calculate annual revenue out to 4 years on an opportunity.  It works fine except when the opportunity revenue is changed.  When the amount is changed, I have found that the 3rd and 4th year revenue does not update.  Can someone look at this and tell me what the problem is?

 

trigger reestablishServiceSchedule on Opportunity (after update) {

    Set<Id> oppIds = new Set<Id>();
    List<OpportunityLineItemSchedule> schedules = new List<OpportunityLineItemSchedule>();
    List<OpportunityLineItem> olis = new List<OpportunityLineItem>();

    if(!ProcessorControl.isTriggered){
        
        for(Integer i = 0; i < Trigger.new.size(); i++){
             if(Trigger.new[i].CloseDate!=Trigger.old[i].CloseDate || (Trigger.new[i].Amount!=Trigger.old[i].Amount)){
                oppIds.add(Trigger.new[i].Id);
            }
        }
        
        
        for (OpportunityLineItem oli: [Select Id, Opportunity.CloseDate, ServiceDate, First_Year_Revenue__c, (Select Id, ScheduleDate, Revenue From OpportunityLineItemSchedules Order By ScheduleDate Asc) From OpportunityLineItem Where HasRevenueSchedule = true AND Opportunity.ID IN: oppIds]){
            Date closeDate = oli.Opportunity.CloseDate;
            for(Integer i = 0; i < oli.OpportunityLineItemSchedules.size(); i++){
                oli.OpportunityLineItemSchedules[i].ScheduleDate = closeDate.addMonths(i);
                schedules.add(oli.OpportunityLineItemSchedules[i]);
            }
            oli.ServiceDate = oli.Opportunity.CloseDate;
            olis.add(oli);
        }
        update olis;
        update schedules;
        
        olis = new List<OpportunityLineItem>();
        for (OpportunityLineItem oli: [Select Id, Opportunity.CloseDate, First_Year_Revenue__c, TotalPrice, HasRevenueSchedule, (Select Id, ScheduleDate, Revenue From OpportunityLineItemSchedules Order By ScheduleDate Asc) From OpportunityLineItem Where Opportunity.ID IN: oppIds]){
            double firstYearRevenue = 0;
            double secondYearRevenue = 0;
            double thirdYearRevenue = 0;
            double FourthYearRevenue = 0;
            if(oli.HasRevenueSchedule){
                for(OpportunityLineItemSchedule sched: oli.OpportunityLineItemSchedules){
                    if(oli.Opportunity.CloseDate.year() == sched.ScheduleDate.year()){
                            firstYearRevenue += sched.Revenue;
                    } else if(oli.Opportunity.CloseDate.year()+ 1 == sched.ScheduleDate.year()){
                            secondYearRevenue += sched.Revenue;
                    } else if(oli.Opportunity.CloseDate.year()+ 2 == sched.ScheduleDate.year()){
                            thirdYearRevenue += sched.Revenue;
                    } else if(oli.Opportunity.CloseDate.year() + 3 == sched.ScheduleDate.year()){
                            FourthYearRevenue += sched.Revenue;
                    }
                }
            } else {
                firstYearRevenue = oli.TotalPrice;
            }
            oli.First_Year_Revenue__c = firstYearRevenue;
            oli.Second_Year_Revenue__c = secondYearRevenue;
            oli.Third_Year_Revenue__c = thirdYearRevenue;
            oli.Fourth_Year_Revenue__c = FourthYearRevenue;
            olis.add(oli);
        }
        update olis;
        
            }

}

 I appreciate any help that you can give me.

 

Thanks,

 

Matt

I am looking for help with automatically adding a person to an opportunity team.  I have a user lookup on Product2 called Financial_Analyst__c.  This is the financial analyst assigned to the individual product.  What I am looking to do is to automatically add that person to the opportunity team when the opportunity is created.  Any help will be greatly appreciated.  Thanks.

Hi All,

I am working on a trigger that looks at the status of a project and then updates the StageName of the associated opportunity.  I have it working for a single project status (Project Closed - Live) where it will update the Opportunity StageName to "Implementation Complete", but I need help to figure out how to change the Opportunity StageName to 'Closed - Inactive' if the project status = 'Project Closed - Not Implemented'.  I have attached the trigger below:

trigger UpdateBillDate on Milestone1_Project__c (before insert, before update) {

List<ID> OppIds = New List<ID>();
 
    for(Milestone1_Project__c o : Trigger.new){
        if(o.Projected_Live_Date__c != null && o.Status__c == 'Project Closed - Live'){
            OppIds.add(o.OpportunityID__c);
        }
    }
 
    List<Opportunity> oppList = [SELECT id, Billing_Date__c
                                                        FROM Opportunity
                                                       WHERE id in :OppIds];
    List<Milestone1_Project__c> mproj =[SELECT OpportunityID__c, Status__c, Projected_Live_Date__c
                                                                         FROM Milestone1_Project__c
                                                                        WHERE OpportunityID__c in: OppIds];
    for (Milestone1_Project__c milestone: Trigger.new) {
      
            for(Opportunity opp:oppList){
                    opp.Billing_Date__c = milestone.Projected_Live_Date__c;
                 opp.StageName = 'Implementation Complete';
            }
      }
       
 
    update oppList;
   
}

Any help you can provide will be GREATLY appreciated.

Thanks,

Matt
Hi all.  I am looking for some help with what should be a simple trigger.  What I want to do is update the Billing_Date__c field in the Opportunity object with the value from the Projected_Live_Date from the Milestone1_Project__c object when the following conditions are met:  1. Milestone1_Project__c.Status = "Project on Target", 2. Milestone1_Project__c.Projected_Live_Date__c != null, and 3. Opportunity.Probability = 95%.  Here is what I have so far:

trigger UpdateBillDate on Milestone1_Project__c (before insert) {
   
    List<ID> OppIds = New List<ID>();
   
    for(Milestone1_Project__c o : Trigger.new){
        if(o.Status__c == 'Project on Target' && o.Projected_Live_Date__c != null){
            OppIds.add(o.Opportunity);
        }
    }
   
    List<Opportunity> oppList = [SELECT id, Billing_Date__c FROM Opportunity WHERE
                                    id in :OppIds];
    for(integer i = 0 ; i < oppList.size(); i++){
        oppList[i].Billing_Date__c = Milestone1_Project__r.Projected_Live_Date__c;
    }
   
    update oppList;
}

Any help will be GREATLY appreciated.

Thanks

I have the following trigger on the Opportunity object to perform revenue calculations, and I need help making these updates:

 

1.  Change when the trigger is fired from the current:  Trigger.new[i].Opportunity.LastModifiedDate != Trigger.old[i].LastModifiedDate to use the LastModifiedDate from OpportunityLineItem or OpportunityLineItemSchedule instead.

 

2.  I have to add a new field to the Opportunity object to calculate first year revenue (FTV__c).  This calculation is different from the one in the trigger in that this calculation has to look at the first 12 months of revenue and use that number to populate FTV__c.  The First_Year_Revenue__c field in the trigger only looks at the revenue in the calendar year.

 

trigger reestablishServiceSchedule on Opportunity (after update) {

    Set<Id> oppIds = new Set<Id>();
    List<OpportunityLineItemSchedule> schedules = new List<OpportunityLineItemSchedule>();
    List<OpportunityLineItem> olis = new List<OpportunityLineItem>();

    if(!ProcessorControl.isTriggered){
        
        for(Integer i = 0; i < Trigger.new.size(); i++){
            if(Trigger.new[i].LastModifiedDate!=Trigger.old[i].LastModifiedDate){
                oppIds.add(Trigger.new[i].Id);
            }
        }
        
        
        for (OpportunityLineItem oli: [Select Id, PricebookEntry.Product2.Family, PricebookEntry.Product2.Name, Opportunity.Billing_Date__c, ServiceDate, First_Year_Revenue__c, Second_Year_Revenue__c, Third_Year_Revenue__c, Fourth_Year_Revenue__c, (Select Id, ScheduleDate, Revenue From OpportunityLineItemSchedules Order By ScheduleDate Asc) From OpportunityLineItem Where HasRevenueSchedule = true AND Opportunity.ID IN: oppIds]){
            Date closeDate = oli.Opportunity.Billing_Date__c;
            for(Integer i = 0; i < oli.OpportunityLineItemSchedules.size(); i++){
                oli.OpportunityLineItemSchedules[i].ScheduleDate = closeDate.addMonths(i);
                schedules.add(oli.OpportunityLineItemSchedules[i]);
            }
            oli.ServiceDate = oli.Opportunity.Billing_Date__c;
            olis.add(oli);
        }
        update olis;
        update schedules;
        
        olis = new List<OpportunityLineItem>();
        for (OpportunityLineItem oli: [Select Id, Opportunity.Billing_Date__c, First_Year_Revenue__c, Second_Year_Revenue__c, Third_Year_Revenue__c, Fourth_Year_Revenue__c, TotalPrice, HasRevenueSchedule, (Select Id, ScheduleDate, Revenue From OpportunityLineItemSchedules Order By ScheduleDate Asc) From OpportunityLineItem Where Opportunity.ID IN: oppIds]){
            double firstYearRevenue = 0;
            double secondYearRevenue = 0;
            double thirdYearRevenue = 0;
            double FourthYearRevenue = 0;
            if(oli.HasRevenueSchedule){
                for(OpportunityLineItemSchedule sched: oli.OpportunityLineItemSchedules){
                    if(oli.Opportunity.Billing_Date__c.year() == sched.ScheduleDate.year()){
                            firstYearRevenue += sched.Revenue;
                    } else if(oli.Opportunity.Billing_Date__c.year()+ 1 == sched.ScheduleDate.year()){
                            secondYearRevenue += sched.Revenue;
                    } else if(oli.Opportunity.Billing_Date__c.year()+ 2 == sched.ScheduleDate.year()){
                            thirdYearRevenue += sched.Revenue;
                    } else if(oli.Opportunity.Billing_Date__c.year() + 3 == sched.ScheduleDate.year()){
                            FourthYearRevenue += sched.Revenue;
                    }
                }
            } else {
                firstYearRevenue = oli.TotalPrice;
            }
            oli.First_Year_Revenue__c = firstYearRevenue;
            oli.Second_Year_Revenue__c = secondYearRevenue;
            oli.Third_Year_Revenue__c = thirdYearRevenue;
            oli.Fourth_Year_Revenue__c = FourthYearRevenue;
            olis.add(oli);
        }
        update olis;
    }

}

 Any help provided will be GREATLY appreciated.

 

Thanks,

 

Matt

I am looking for some help with a simple trigger.  I want to update the opportunity with the product name from the product2 object.  I can't get it to work for some reason.

 

trigger addServiceInformation on Opportunity (before insert, before update) {

	Set<Id>oppIds = new Set<Id>();
	Map<Id,String>oppIdMap = new Map<Id,String>();
	
	for(Integer i = 0;i<Trigger.new.size();i++){
		
		oppIds.add(Trigger.new[i].Id);
		
		
	}
	for(OpportunityLineItem oli:[SELECT Id, PricebookEntry.Product2.Name FROM OpportunityLineItem WHERE Id IN:oppIds AND HasRevenueSchedule = TRUE]){
		oppIdMap.put(oli.Id, oli.PricebookEntry.Product2.Name);
		
	}
	
	for(Opportunity o: Trigger.new){
		o.Service_Name__c=oppIdMap.get(o.Id);
	}
}

 Eventually, I would like to add more than 1 field with the same trigger, but the second field is a picklist, and I don't know how to add a picklist value to a text field in a trigger.

 

Any help will be GREATLY appreciated.

I am looking for help with automatically adding a person to an opportunity team.  I have a user lookup on Product2 called Financial_Analyst__c.  This is the financial analyst assigned to the individual product.  What I am looking to do is to automatically add that person to the opportunity team when the opportunity is created.  Any help will be greatly appreciated.  Thanks.