• dcgb2332
  • NEWBIE
  • 75 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 44
    Replies
Here is my code, if someone could please help me with a test class, I would greatly appreciate it!

`trigger setOpportunityOwner on Task (before insert, before update) {
  Set<Id> oppIds = new Set<Id>();
  for ( Task newTask : Trigger.new ) {
    if ( newTask.WhatId != null && String.valueOf( newTask.WhatId ).startsWith( '006' ) ) {
      oppIds.add( newTask.WhatId );
    }
  }
  Map<Id, Opportunity> oppMap = new Map<Id, Opportunity>([Select Owner.Name FROM Opportunity WHERE Id IN :oppIds]);
  for(Task newTask: Trigger.new) {
    if ( oppMap.containsKey( newTask.WhatId ) ) {
      newTask.Opp_Owner__c = oppMap.get( newTask.WhatId ).Owner.Name;
    }
  }
}`
We recently migrated to lightning and my manager noticed that some leads are showing up as 'contacted' when viewed in classic, but in lightning, they still show up as 'new'. Why would this be? Is there a fix?

Thank you
Here's the code, not sure why it's not working when I've deployed it before... 

trigger UpdateAccountName on Task (before update)

    Map<Id, Task> idAccountTaskMap = new Map<Id, Task>();
    for (Task t : Trigger.new) {

        if(t.AccountId != null)
            idAccountTaskMap.put(t.AccountId, t);
    }

    if(idAccountTaskMap.isEmpty()) return;

    Map<Id, Account> accountMap = new Map<Id, Account>([SELECT Name FROM Account WHERE Id = :idAccountTaskMap.keyset()]);

    for(Task a : idAccountTaskMap.values())
    {  
        a.Account_Name__c = accountMap.get(a.AccountId).Name;
    }
}
As stated, I need to figure out how to auto populate my custom field ACCOUNT NAME from the opportunity a task is created on. I'm looking for a flow and process builder sequence, versus Apex. When I've tried it myself, it doesn't work...

Thanks in advance

I'm trying to populate the opportunity owner name in the TASK on a new custom field called Opp Owner. Should this be in process builder? Or is there a formula I can use? I'm trying to avoid using Apex Triggers.

Thanks!
I need to update the Account Name (Account_Name__c) custom field in the Task tab, with the Account Name (AccountId). My current code is:

trigger Account_Name on Task (before insert, before update) {
    for(Task a : trigger.new) {        
        task.Account_Name__c = a.AccountId;
    }
}


I keep receiving an error that says: A value cannot be stored to Account_Name__c in type task. What am I doing wrong?
I've tried work flow rules, process builder and apex triggers and keep running into a wall. Does anyone have a best practice for this? I simply need th Opportunity Record ID Number populated into my custom Job Number field in the Task in Lightning (shows up in Classic but lightning for some reason??)

Apex trigger or formula suggestions would be greatly appreciated.

Thanks!
When a task is created, I have a custom pick list on a custom field (Assigned To). I would like that information to populate the Created By field, with an Apex Trigger but am not sure how to start the code
Hi All,

I have a custom VF page for Tasks. Currently, I cannot figure out how to auto populate a custom field, called Account Name, with the actual account name the task is associated with, from the Opportunity. Does anyone know a trigger for this?

Thank you!
Hi Guys,
I've created a web tab for tasks. The issue is, there's no "account name" field. I've tried creating the custom field "Account Name" within the task, by selecting look up, but it doesn't work. Do you have any idea how I may go about doing this? Maybe with a formula field? I've already exhausted the number of SQL queries we can have (I have three apex triggers running) and I don't want to amend any of said triggers or create a new one, unless absolutely necessary. Really, all I need is for it to populate the field using the same information the task pulls the "related to" number from.

One more thing.. my org is married to SF Classic, and has no desire to migrate to Lightning.  I've looked through a bunch of other quesions, but they mostly reference "contacts" or a VF scenario in Lightning.

Thanks!
Hi Guys,

We have an appex trigger that creates a "new" opportunity in a custom tab (AE Opps), which works perfectly. Now, I'm trying to create a custom tab, called AE Tasks, which will take the tasks from the AE Opps tab, and populate them in the new custom tab (AE Tasks). Is there a way to do this or will I need a new apex trigger?

Many thanks
I've created a custom object with related custom fields. I've also created an Apex Trigger to roll up data into said custom object. We tested it in production and we have 95% coverage. When I go to validate through the inbound change set, it says I have 0% coverage. How can this be? I've checked in both the developer console test and in classes (an apex class was created as well). What am I doing wrong? I've looked at the other forums and can't find an answer. Thanks in advance
I have a code currently in place: 1
2
3
4
5
6
7
Trigger AE_Opps_c ON Opportunity (After Insert, Before Update){

  List<Opportunity> oppList = [SELECT Id, Name FROM Opportunity];
  List<AE_Opps__c> aeList = new List<AE_Opps__c>();
    
    insert aeList;
    }

The purpose is to create a new list by pulling NEW opportunities and placing them in the list. There a two problems:

1) Every time a new opportunity is created, the existing opportunities are duplicated on the list
2) The Opportunity owner name is defaulting to my name and/or the other ADMIN.


Can someone please help me?
Hello,
I'm new to triggers and struggling with this. I need a trigger that pulls the Opportunity name and creates a new record in my custom object, AE Opp. I do not need it to create a lookup or link it to the opp, i just need it to create a whole new record so that I can create a task on it.. Is this feasible?
Here is my code, if someone could please help me with a test class, I would greatly appreciate it!

`trigger setOpportunityOwner on Task (before insert, before update) {
  Set<Id> oppIds = new Set<Id>();
  for ( Task newTask : Trigger.new ) {
    if ( newTask.WhatId != null && String.valueOf( newTask.WhatId ).startsWith( '006' ) ) {
      oppIds.add( newTask.WhatId );
    }
  }
  Map<Id, Opportunity> oppMap = new Map<Id, Opportunity>([Select Owner.Name FROM Opportunity WHERE Id IN :oppIds]);
  for(Task newTask: Trigger.new) {
    if ( oppMap.containsKey( newTask.WhatId ) ) {
      newTask.Opp_Owner__c = oppMap.get( newTask.WhatId ).Owner.Name;
    }
  }
}`

I'm trying to populate the opportunity owner name in the TASK on a new custom field called Opp Owner. Should this be in process builder? Or is there a formula I can use? I'm trying to avoid using Apex Triggers.

Thanks!
I need to update the Account Name (Account_Name__c) custom field in the Task tab, with the Account Name (AccountId). My current code is:

trigger Account_Name on Task (before insert, before update) {
    for(Task a : trigger.new) {        
        task.Account_Name__c = a.AccountId;
    }
}


I keep receiving an error that says: A value cannot be stored to Account_Name__c in type task. What am I doing wrong?
I've tried work flow rules, process builder and apex triggers and keep running into a wall. Does anyone have a best practice for this? I simply need th Opportunity Record ID Number populated into my custom Job Number field in the Task in Lightning (shows up in Classic but lightning for some reason??)

Apex trigger or formula suggestions would be greatly appreciated.

Thanks!
When a task is created, I have a custom pick list on a custom field (Assigned To). I would like that information to populate the Created By field, with an Apex Trigger but am not sure how to start the code