• econ242
  • NEWBIE
  • 50 Points
  • Member since 2006

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 29
    Replies
Hi,

I need assitance on a formula for creating a default close date on Opportunities for existing Accounts. As we know, when a Lead is converted and an Opportunity is created, the default close date on that Opportunity defaults to the end of the current fiscal quarter from the day it was converted/created. I'd like to replicate that same functionality on existing Accounts so if a new Opportunity is created for an existing Account on July 3, 2016, the close date will update when the record is saved to September 30, 2016...the last day of the current fiscal quarter from which the Opportunity (create date) was created.

I already know how to custumize a close date for (x) amount of days i.e., create date +30, or +60 etc...but how can I get it to default to the last day of the quarter? Any help would be GREATLY appreciated!!!

Thanks so much!!!
Hi everyone...

Looking for some help with opportunities here... My company has never used opportunities and I believe they need to, and my experience is minimal with opportunities because of this, so this (Opportunities) is slightly new to me as well, but here is the scenario...

Currently, we track customer orders via a custom object called Shipments...these are quantity based with no dollar value associated. I also have many roll-up sommary fields on the Account record that tracks total orders for the current month to gauge the volume of business received from the customer. The previous business days' orders are automatically uploaded each morning to the shipment custom object which in turn update the roll-up custom fields daily.

I've added the Shipments related list to the Opportunity page layout and have created a few roll-up custom summary fields to capture the amount of orders received on the opportunity, i also have a Quantity field that the Sales Team needs to populate with the number of orders they anticipate from the customer for this particular opportunity...my question here is, is there a formula or workflow rule that can accomplish the following - when the number of orders received matches the quantity value (i.e., orders received = 10 and Quantity = 10) can I automatically update the opportunity Stage to "Closed/Won" and automatically close the opportunity for that Account?

Can a WFR do this, or do I need a trigger? if a WFR is possible...any help in setting up would be most apprecaited...thanks and sorry for the novel, lol!!!
 
Hello all...

Looking for some assistance on a trigger i'm writing...

Basically, I have a trigger that will update an Account Status and Stage (custom field) based on the completion of an Activity. I wrote the trigger initially based on the completed activity being logged on the Account record. When I realized I also needed to accomplish the same functionality if an activity is completed against a Contact (oopsies) within said Account, I modified the trigger to the below:

trigger changeAccountStagetask1 on Task (before update, after update) {
   
    Set<String> whatIDs = new Set<String>();
   
    for (Task tsk: Trigger.new) {
        whatIDs.add(tsk.whatID);
         } 
    List<Contact> conlist = [SELECT Id, AccountId FROM Contact WHERE accountId in :whatIDs];
   
    List<Account> filteredAccts = new List<Account>();
    Map<Id, Account> accts = new Map<Id, Account>();  
   
                                       
    Map<String, Task> taskMap = new Map<String, Task>();
    for (Task tsk: Trigger.new) {         
            if(taskMap.containsKey(tsk.whatId)) {      
            if(tsk.Status=='Completed' && tsk.Subject=='Call To Qualify (Successful)'){
                Account ld = new Account(Id=tsk.whatID);
                     ld.Status__c = 'Qualified Prospect';                             
                     ld.Stage__c = 'Need To Set Meeting';
                taskMap.put(tsk.whatID, tsk);          
            }
          
        }      
        update accts.values();
   }
   }

However, when I attempt to test this trigger in my Sandbox, nothing changes...whether I log the call on the Account, or on the Contact, the Status/Stage doesn't change...and no errors are coming up...any thoughts on what I'm missing based on my code above?

Thanks so much in advance for your help!!!

E
  • September 09, 2014
  • Like
  • 0
Hello,

Looking for some assistance with a workflow rule...

We don't utilize Leads in the traditional sense within Salesforce...all "Leads" are entered as Accounts and given a "Status" of "Lead". Once a Lead is qualified, the Status changes to "Qualified Prospect", then once an order is placed, the Account Status is changed to Active. What we want (need) to do is capture the date the Account Status is changed from Lead to Qualified Prospect, then again when the Account Status is changed from Qualified Prospect to Active. We also want (need) to capture the number of days an Account remains at said Status.

So...I've created 2 custom date fields and 2 custom age fields to capture the changes from both Lead to Qualified Prospect, and then again when changed from Qualified Prospect to Active seperately...now I want to utilize these fields with a workflow rule that will basically capture the date the Status was changed from Lead to Qualified Prospect, which would then in turn kick off the age field and display the number of days at that status.

I'm stuck on the formula piece for the Status change...i utilized parts of the info contained in the link below:

https://success.salesforce.com/answers?id=90630000000gxreAAA

Is it possible through a workflow rule to capture those dates and time at each Status individually? Or would a trigger be better suited?

Any help would be appreciated...thanks everyone!!!
  • September 05, 2014
  • Like
  • 0
Hi Everyone,

I currently have a trigger deployed in production that updates an Account Status and Stage based on a completed activity...code is below:

trigger changeAccountStageContacttask1 on Task (before update, after update) {
    List<Account> accsToUpdate = new List<Account>();
        for (Task tsk: Trigger.new){
            if(tsk.Status=='Completed' && tsk.Subject=='Call To Qualify (Successful)'){
                Account ld = new Account(Id=tsk.whatid);
                     ld.Status__c = 'Qualified Prospect';                             
                     ld.Stage__c = 'Need To Set Meeting';
                accsToUpdate.add(ld);          
            }
          
        }      
        update accsToUpdate;
   }

I need to apply this same logic but on the Contact record for the related Account...so if an activity is completed against a Contact related to the Account, the Account Stage and Status would be updated.  I think it's only a few lines of extra code to query the whoID related to the acc ID, but I'm a bit stuck on what to enter and where...any help would be SUPER appreciated...Thanks!!!
Hello,

So I'm a newbie to writing triggers and need help on wrting a test class so I can deploy to production...here is my situation:

I have a trigger that updates a hidden field on an Account record that was needed in order to track changes on a seperate field that is a formula field. When the field value changes, the trigger runs and captures the previous value in the Account History. Here is my trigger code in my sandbox:

trigger BusinessRatingChange on Account (before update)
{
    for(Account a:Trigger.new)
    {
        if(system.trigger.OldMap.get(a.Id).Business_Rating__c != system.trigger.NewMap.get(a.Id).Business_Rating__c)
        {
            a.Business_Rating_History__c = a.Business_Rating__c;
            }
            }
            }

This trigger works perfect in my sandbox, but with my limited knowledge on triggers and writing test classes...is there anyone out there that can assist me, or guide me to where I can understand better?? Bad news is i need to get this deployed QUICK!!!  :(

Thanks so much!!!

Eric
Hello,

We're using activities to drive an Account "Status" and "Stage" both of which are custom fields. For Tasks, when a Task is completed, I have a trigger that automatically updates the Account "Status" and "Stage" based on the "Task" subject...so for example, when a Task is completed with a Subject of "Initial Needs Assessment Completed" my trigger fires and updates the Related Account "Status" to Qualified Prospect, and  "Stage" to Needs Assessment Completed.

Now, I need to accomplish the same thing on an "Event", so when the Event date and time pass, depending on the Event "Subject" the custom fields on the Related Account get updated as well. Now, I know using a trigger won't work per se, because you can't "Complete" an Event.

So...I'm told that using a time-based workflow is the way to go, but I'm not quite sure how to accomplish this and if a trigger is still necessary along with the workflow rule. Is it possible to have a cross object workflow update a field between an Event and an Account?

Any and all assistance on this would be greatly appreciated!!!

Thanks!!!

E
Hello,

I have created a trigger that updates a hidden field on an Account record that was needed in order to track changes on a seperate field that is a formula field. When the field value changes, the trigger runs and captures the previous value in the Account History. Below is my trigger code (in Sandbox) that works perfect:


trigger BusinessRatingChange on Account (before insert, before update)
{
    for(Account a:Trigger.new)
    {
        if(system.trigger.OldMap.get(a.Id).Business_Rating__c != system.trigger.NewMap.get(a.Id).Business_Rating__c)
        {
            a.Business_Rating_History__c = a.Business_Rating__c;
            }
            }
            }

However, when I attempt to create a NEW account, I get the below error that looks like is due to the "BeforeInsert" action on the trigger:


Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger BusinessRatingChange caused an unexpected exception, contact your administrator: BusinessRatingChange: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.BusinessRatingChange: line 5, column 1


Does anyone have any insight as to how I can remedy this? Thanks so much in advance for your assistance!!!

Eric
Hi all,

Looking for some assistance here...I have a requirement to have a Lead automatically convert to an Account and Contact (no opportunity needed) when the Lead status is set to "Qualified". I also have an existing trigger on "Task" that when a particular picklist value is selected and the Task is marked "Completed" it will automatically change the Lead status to Qualified...that trigger works perfect in my Sandbox.

I've searched tons of articles on here about a trigger to auto-convert a Lead based on certain values and used the below code as suggested:

trigger LeadConvert on Lead (after insert,after update) {
  //Bulkified
  List<String> LeadNames = new List<String>{};
  for(Lead myLead: Trigger.new){
   if((myLead.isconverted==false) && (myLead.status == 'Qualified')) {
  Database.LeadConvert lc = new database.LeadConvert();
          lc.setLeadId(myLead.Id);
          lc.convertedStatus = 'Qualified';
          //Database.ConvertLead(lc,true);
          lc.setDoNotCreateOpportunity(true);
          Database.LeadConvertResult lcr = Database.convertLead(lc);
          System.assert(lcr.isSuccess());
          }
          }
  }

Issue: When I complete a Task that fires the trigger to change the Lead status to Qualified, it says the Lead was converted, but when I go back to check, the Lead was NOT converted AND the Task does not show up in the activity history AND the Lead Status is unchanged (not showing as "Qualified") even though it should per the Task trigger...

I'm totally lost on this one...any help would be great...thanks in advance!!!
Hi,

I'm trying to figure out how to write a trigger that will update a custom field (Stage_c) with a particular pick-list value after an Event date and time passes.

Basically in the Event Subject field, I have a picklist value called "Needs Assessment", what I need to accomplish is...if an Event has the subject of "Needs Assessment" and the date and time passes i.e., "Completed" and this Event now falls under Activity History, I need to have the custom field (Stage_c) update to a picklist value "Needs Assessment Completed".

I have triggers working great for the same process on Tasks, but since Events are not "Completed" per se, how do I go about writing a trigger for this same action but on events? Is it possible?

Below is the code I currently use on my Task trigger:

trigger changeAccountStagetask3 on Task (before update, after update) {
    List<Account> accsToUpdate = new List<Account>();
        for (Task tsk: Trigger.new){
            if(tsk.Status=='Completed' && tsk.Subject=='Initial Sell/Needs Assessment'){
                Account ld = new Account(Id=tsk.whatid);                             
                     ld.Stage__c = 'Needs Assessment Completed';
                accsToUpdate.add(ld);          
            }
          
        }      
        update accsToUpdate;
    }

Any help would be wonderful!!!

Thanks!!!
Hi...being new to triggers and APEX, I'm in need of some help on an error I received...

I currently have a trigger that automatically updates a Lead Status and Lead Custon Field (Stage_C) based on the completion of an Activity. Below is my code for the tigger...which, works perfect:

trigger changeLeadStatustask2 on Task (before insert, before update) {
    List<Lead> LeadToUpdate = new List<Lead>();
        for (Task tsk: Trigger.new){
            if(tsk.Status=='Completed' && tsk.Subject=='Call to Qualify (Successful)'){
                Lead ld = new Lead(Id=tsk.whoid);
                   ld.Status = 'Qualified';             
                     ld.Stage__c = 'Qualified - Convert to QP';
                LeadToUpdate.add(ld);           
            }
           
        }       
        update LeadToUpdate;
    }

However...when I attempt to convert this Lead into an Account, I get the below error/exception:

Error: System.DmlException: Update failed. First exception on row 0 with id 00TR000000EdoDYMAZ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, changeLeadStatustask2: execution of BeforeUpdate caused by: System.TypeException: Invalid id value for this SObject type: 003R000000ojtF5IAI Trigger.changeLeadStatustask2: line 5, column 1: [] (System Code)

Any help would be most appreciated!!! Thank you!!!

Hi Everyone,

I'm just getting started on how to use triggers...I'm trying to write a trigger that will update a custom field (Stage_c) to a specific picklist value (Actively Working) on my Lead Detail page based on an Activity Task Type - Call to Qualify (Unsuccessful) - when the Activity has been completed.

I came across this post - https://developer.salesforce.com/forums/ForumsMain?id=906F00000008mcOIAQ - and tried tweaking it a bit to work for this requirement, but I keep getting errors.

ANY assistance would be greatly appreciated!!!

Thank you in advance for your help!!!
I was wondering if it is possible to have Close Date of newly created opportunity to be automatically set up for  90 days.
Thank you.
Kasia
help, I want to create a new custom field LEAD AGE on Lead Page, any idea about formula I have to use to know how many days each lead has since creating.thanks
Hi,

I need assitance on a formula for creating a default close date on Opportunities for existing Accounts. As we know, when a Lead is converted and an Opportunity is created, the default close date on that Opportunity defaults to the end of the current fiscal quarter from the day it was converted/created. I'd like to replicate that same functionality on existing Accounts so if a new Opportunity is created for an existing Account on July 3, 2016, the close date will update when the record is saved to September 30, 2016...the last day of the current fiscal quarter from which the Opportunity (create date) was created.

I already know how to custumize a close date for (x) amount of days i.e., create date +30, or +60 etc...but how can I get it to default to the last day of the quarter? Any help would be GREATLY appreciated!!!

Thanks so much!!!
Hi everyone...

Looking for some help with opportunities here... My company has never used opportunities and I believe they need to, and my experience is minimal with opportunities because of this, so this (Opportunities) is slightly new to me as well, but here is the scenario...

Currently, we track customer orders via a custom object called Shipments...these are quantity based with no dollar value associated. I also have many roll-up sommary fields on the Account record that tracks total orders for the current month to gauge the volume of business received from the customer. The previous business days' orders are automatically uploaded each morning to the shipment custom object which in turn update the roll-up custom fields daily.

I've added the Shipments related list to the Opportunity page layout and have created a few roll-up custom summary fields to capture the amount of orders received on the opportunity, i also have a Quantity field that the Sales Team needs to populate with the number of orders they anticipate from the customer for this particular opportunity...my question here is, is there a formula or workflow rule that can accomplish the following - when the number of orders received matches the quantity value (i.e., orders received = 10 and Quantity = 10) can I automatically update the opportunity Stage to "Closed/Won" and automatically close the opportunity for that Account?

Can a WFR do this, or do I need a trigger? if a WFR is possible...any help in setting up would be most apprecaited...thanks and sorry for the novel, lol!!!
 
Hello all...

Looking for some assistance on a trigger i'm writing...

Basically, I have a trigger that will update an Account Status and Stage (custom field) based on the completion of an Activity. I wrote the trigger initially based on the completed activity being logged on the Account record. When I realized I also needed to accomplish the same functionality if an activity is completed against a Contact (oopsies) within said Account, I modified the trigger to the below:

trigger changeAccountStagetask1 on Task (before update, after update) {
   
    Set<String> whatIDs = new Set<String>();
   
    for (Task tsk: Trigger.new) {
        whatIDs.add(tsk.whatID);
         } 
    List<Contact> conlist = [SELECT Id, AccountId FROM Contact WHERE accountId in :whatIDs];
   
    List<Account> filteredAccts = new List<Account>();
    Map<Id, Account> accts = new Map<Id, Account>();  
   
                                       
    Map<String, Task> taskMap = new Map<String, Task>();
    for (Task tsk: Trigger.new) {         
            if(taskMap.containsKey(tsk.whatId)) {      
            if(tsk.Status=='Completed' && tsk.Subject=='Call To Qualify (Successful)'){
                Account ld = new Account(Id=tsk.whatID);
                     ld.Status__c = 'Qualified Prospect';                             
                     ld.Stage__c = 'Need To Set Meeting';
                taskMap.put(tsk.whatID, tsk);          
            }
          
        }      
        update accts.values();
   }
   }

However, when I attempt to test this trigger in my Sandbox, nothing changes...whether I log the call on the Account, or on the Contact, the Status/Stage doesn't change...and no errors are coming up...any thoughts on what I'm missing based on my code above?

Thanks so much in advance for your help!!!

E
  • September 09, 2014
  • Like
  • 0
Hello,

Looking for some assistance with a workflow rule...

We don't utilize Leads in the traditional sense within Salesforce...all "Leads" are entered as Accounts and given a "Status" of "Lead". Once a Lead is qualified, the Status changes to "Qualified Prospect", then once an order is placed, the Account Status is changed to Active. What we want (need) to do is capture the date the Account Status is changed from Lead to Qualified Prospect, then again when the Account Status is changed from Qualified Prospect to Active. We also want (need) to capture the number of days an Account remains at said Status.

So...I've created 2 custom date fields and 2 custom age fields to capture the changes from both Lead to Qualified Prospect, and then again when changed from Qualified Prospect to Active seperately...now I want to utilize these fields with a workflow rule that will basically capture the date the Status was changed from Lead to Qualified Prospect, which would then in turn kick off the age field and display the number of days at that status.

I'm stuck on the formula piece for the Status change...i utilized parts of the info contained in the link below:

https://success.salesforce.com/answers?id=90630000000gxreAAA

Is it possible through a workflow rule to capture those dates and time at each Status individually? Or would a trigger be better suited?

Any help would be appreciated...thanks everyone!!!
  • September 05, 2014
  • Like
  • 0
Hi Everyone,

I currently have a trigger deployed in production that updates an Account Status and Stage based on a completed activity...code is below:

trigger changeAccountStageContacttask1 on Task (before update, after update) {
    List<Account> accsToUpdate = new List<Account>();
        for (Task tsk: Trigger.new){
            if(tsk.Status=='Completed' && tsk.Subject=='Call To Qualify (Successful)'){
                Account ld = new Account(Id=tsk.whatid);
                     ld.Status__c = 'Qualified Prospect';                             
                     ld.Stage__c = 'Need To Set Meeting';
                accsToUpdate.add(ld);          
            }
          
        }      
        update accsToUpdate;
   }

I need to apply this same logic but on the Contact record for the related Account...so if an activity is completed against a Contact related to the Account, the Account Stage and Status would be updated.  I think it's only a few lines of extra code to query the whoID related to the acc ID, but I'm a bit stuck on what to enter and where...any help would be SUPER appreciated...Thanks!!!
Hello,

So I'm a newbie to writing triggers and need help on wrting a test class so I can deploy to production...here is my situation:

I have a trigger that updates a hidden field on an Account record that was needed in order to track changes on a seperate field that is a formula field. When the field value changes, the trigger runs and captures the previous value in the Account History. Here is my trigger code in my sandbox:

trigger BusinessRatingChange on Account (before update)
{
    for(Account a:Trigger.new)
    {
        if(system.trigger.OldMap.get(a.Id).Business_Rating__c != system.trigger.NewMap.get(a.Id).Business_Rating__c)
        {
            a.Business_Rating_History__c = a.Business_Rating__c;
            }
            }
            }

This trigger works perfect in my sandbox, but with my limited knowledge on triggers and writing test classes...is there anyone out there that can assist me, or guide me to where I can understand better?? Bad news is i need to get this deployed QUICK!!!  :(

Thanks so much!!!

Eric
Hello,

We're using activities to drive an Account "Status" and "Stage" both of which are custom fields. For Tasks, when a Task is completed, I have a trigger that automatically updates the Account "Status" and "Stage" based on the "Task" subject...so for example, when a Task is completed with a Subject of "Initial Needs Assessment Completed" my trigger fires and updates the Related Account "Status" to Qualified Prospect, and  "Stage" to Needs Assessment Completed.

Now, I need to accomplish the same thing on an "Event", so when the Event date and time pass, depending on the Event "Subject" the custom fields on the Related Account get updated as well. Now, I know using a trigger won't work per se, because you can't "Complete" an Event.

So...I'm told that using a time-based workflow is the way to go, but I'm not quite sure how to accomplish this and if a trigger is still necessary along with the workflow rule. Is it possible to have a cross object workflow update a field between an Event and an Account?

Any and all assistance on this would be greatly appreciated!!!

Thanks!!!

E