function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Eric BlaxtonEric Blaxton 

Trigger to create task and assign to related user during quote approval process

Hi and thanks in advance.

Requirement: I need tips on a trigger to create a task and assign it to a related user on the Quote object.  It should happen when a quote enters the intial submittal.

Has anyone done this using Apex or vf?

Regards
Best Answer chosen by Eric Blaxton
Eric BlaxtonEric Blaxton
Hi Vinit, This particular requirement cannot be met with a workflow because a task cannot be assigned to a Related User. Eric Blaxton

All Answers

Vinit_KumarVinit_Kumar
Why don't you need Apex trigger for this,you can create a workflow and achieve the same functionality.
surekha Ksurekha K

Hi,

    I have a requirement,i have two fields in Account and opportunity objects those two are picklist data type one is controlling and another is dependent.if i insert a record in account those two fileds automatically populate in th opportunity before insert and update so that i wrote trigger.The code is below.Can anyone help me to wite test class for this

 public with sharing class Opportunity_PopulateVerticalSubvertical extends OpportunityTrigger {

    public Opportunity_PopulateVerticalSubvertical(Opportunity[] opportunityOldList, Opportunity[] opportunityNewList) {
        super(opportunityOldList,opportunityNewList);
    }
   
    public override Boolean executable(Opportunity opportunityOld, Opportunity opportunityNew) {
        return true;
    }
   
    public override void execute(Opportunity[] opportunityUpdatableList, Boolean forceUpdate) {
        if (setting.Disable_Opportunity_UpdateBackEndFields__c == true)
            return;
        Set<Id> accountIdSet = new Set<Id>();
      for (Opportunity oppObj : opportunityUpdatableList)  {
          accountIdSet.add(oppObj.AccountId);
      }
     
        Map<Id,Account> accMap = new Map<Id,Account>([SELECT id,Name,Industry,Sub_IG__c FROM Account WHERE Id in : accountIdSet]);
       
      if(accMap.size() > 0) {
          for(Opportunity oppObj : opportunityUpdatableList) {
              oppObj.IG__c = accMap.get(oppObj.AccountId).Industry;
              oppObj.Sub_IG__c = accMap.get(oppObj.AccountId).Sub_IG__c;
          }
      }       
    }

}

Thanks in advance,

Regards,
Rekha

surekha Ksurekha K
one more if i update the Account the related opportunity records also updated automatically.The code as below.Need test class also for this.

 public with sharing class Account_UpdateOpportunityFields extends AccountTrigger {
 
  public Account_UpdateOpportunityFields (Account[] accountOldList, Account[] accountNewList) {
    super(accountOldList,accountNewList);
  }
 
  public override Boolean executable(Account accountOld, Account accountNew) {
        return accountOld.Industry != accountNew.Industry ||
               accountOld.Sub_IG__c != accountNew.Sub_IG__c  ;
    }
   
     public override void execute(Account[] accountUpdatableList, Boolean forceUpdate) {
       
        if (setting.Disable_Account_UpdateOpportunityFields__c == true)
            return;
       
        Map<Id,Account> newAccMap=new Map<Id,Account>(accountUpdatableList);
       
        Opportunity [] OpportunityList = [Select IG__c,Sub_IG__c,Allow_Admin_to_Change__c,AccountId from Opportunity where AccountId In:newAccMap.keySet()];
        Opportunity [] OpportunityUpdateist = new Opportunity [] {};
        for (Opportunity opportunity : OpportunityList) {
            if (opportunity.Allow_Admin_to_Change__c == true)
                continue;
               
            Account account =   newAccMap.get(opportunity.AccountId);
            opportunity.IG__c = account.Industry;
            opportunity.Sub_IG__c =  account.Sub_IG__c;
           
            OpportunityUpdateist.add(opportunity);
        }
       
        if(OpportunityUpdateist.size() > 0) {
            update OpportunityUpdateist;
        }
    }
}

Regards,
Rekha
Eric BlaxtonEric Blaxton
Hi Vinit, This particular requirement cannot be met with a workflow because a task cannot be assigned to a Related User. Eric Blaxton
This was selected as the best answer
Vinit_KumarVinit_Kumar
How are you identifying that which user should the Task be reassigned  to??
Eric BlaxtonEric Blaxton
It is a related user on the Quote object. Eric Blaxton
Vinit_KumarVinit_Kumar
You can write an after insert and after update Trigger on Quote and create a Task in it and assign it to the Related User.


Eric BlaxtonEric Blaxton
Surekha, Why did you post this on my question? It seems to have nothing to do with my original question. What am I missing here. Eric Blaxton