• Lauren Honyotski
  • NEWBIE
  • 20 Points
  • Member since 2014


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 9
    Replies
I have a requirement to pass a date field to an external database when this date field changes. What would be the easiest way to accomplish this?
I have a record type on the lead object that requires the email field to be hidden. Salesforce does not allow the email field to be hidden on the page layout of the lead object. I cannot use field level permissions to hide this field either, as the email field is used for other integrations. I just need the email to be hidden from users for this record type. I have a visualforce page that has everything I need. How can I have this page displayed when the lead is this particular record type?
I am trying to write a trigger on task that queries the subject, and if it is equal to "Requalify", find the related account and related opportunity and change the opportunity status to "Re-qualify". I have the below trigger, but it is not changing the opportunity status. Any help would be greatly appreciated!

trigger TaskSubject on Task (after update, after insert) {

set<id> accountIdSet = new set<id>();
//capture all the subject names in a set
//set<string> subjectName = new set<string>{'Requalify'};
map<id, list<opportunity>> opptyMap = new map<id, list<opportunity>>();
list<opportunity> updateOppList = new list<opportunity>();

//get those tasks where the tasks are related to account. Capture the account IDs in a set.
for(task t: trigger.new){
            string tempId = string.valueOf(t.WhatId);
    if(tempId.startsWith('001')){
        accountIdSet.add(t.whatId);
    }
}

//If we have any account IDs then get the associated opportuity and store the one account to many opportunity in a map<id, list<opportunity>>
if(accountIdSet.size()>0){
    for(opportunity opp:[select Name, stageName, accountid from opportunity where accountid IN :accountIdSet]){
        if(opptyMap.containsKey(opp.accountId)){
            list<opportunity> oppList = opptyMap.get(opp.accountId);
            oppList.add(opp);
            opptyMap.put(opp.accountId, oppList);
        }else{
            list<opportunity> newOppList = new list<opportunity>();
            newOppList.add(opp);
            opptyMap.put(opp.accountId, newOppList);
        }
    }
}

//If we get the opportunities then change the stage.
if(Trigger.isUpdate && opptyMap.size()>0){
    for(task t: trigger.new){

 //Check if the subject of the task is one among the set 
 //and also confirm that the subject has been changed.

        if(t.subject != trigger.oldMap.get(t.id).subject && opptyMap.containsKey(t.whatId)){

  //iterate thru the list of the opportunity associated with that account 
  //and check which of the opportunity contains the task subject in the 
   //opportunity name and update the stage to re-qualify

            for(opportunity oppty: opptyMap.get(t.whatId)){
               {
                    oppty.stageName='Re-Qualify';
                    updateOppList.add(oppty);
                }
            }
        }
    }
}
if(Trigger.isInsert && opptyMap.size()>0){
     for(task t: trigger.new){
            if(opptyMap.containsKey(t.whatId)){
                for(opportunity oppty: opptyMap.get(t.whatId)){
                   if(oppty.name.contains(t.subject)){
                      oppty.stageName='Re-Qualify';
                      updateOppList.add(oppty);
                   }
               }
            }
        }
    }
//update the oppties
if(updateOppList.size()>0){
    update updateOppList;
}
}
I am trying to get a trigger in place that upon creating a task with the subject 'Requalify', change the closed opportunity to stage "Re-Qualify". This below code is not working. Any ideas?

trigger TaskSubject on Task (after update, after insert) {

set<id> accountIdSet = new set<id>();
//capture all the subject names in a set
//set<string> subjectName = new set<string>{'Requalify'};
map<id, list<opportunity>> opptyMap = new map<id, list<opportunity>>();
list<opportunity> updateOppList = new list<opportunity>();

//get those tasks where the tasks are related to account. Capture the account IDs in a set.
for(task t: trigger.new){
            string tempId = string.valueOf(t.WhatId);
    if(tempId.startsWith('001')){
        accountIdSet.add(t.whatId);
    }
}

//If we have any account IDs then get the associated opportuity and store the one account to many opportunity in a map<id, list<opportunity>>
if(accountIdSet.size()>0){
    for(opportunity opp:[select Name, stageName, accountid from opportunity where accountid IN :accountIdSet]){
        if(opptyMap.containsKey(opp.accountId)){
            list<opportunity> oppList = opptyMap.get(opp.accountId);
            oppList.add(opp);
            opptyMap.put(opp.accountId, oppList);
        }else{
            list<opportunity> newOppList = new list<opportunity>();
            newOppList.add(opp);
            opptyMap.put(opp.accountId, newOppList);
        }
    }
}

//If we get the opportunities then change the stage.
if(Trigger.isUpdate && opptyMap.size()>0){
    for(task t: trigger.new){

 //Check if the subject of the task is one among the set 
 //and also confirm that the subject has been changed.

        if(t.subject != trigger.oldMap.get(t.id).subject && opptyMap.containsKey(t.whatId)){

  //iterate thru the list of the opportunity associated with that account 
  //and check which of the opportunity contains the task subject in the 
   //opportunity name and update the stage to re-qualify

            for(opportunity oppty: opptyMap.get(t.whatId)){
               {
                    oppty.stageName='Re-Qualify';
                    updateOppList.add(oppty);
                }
            }
        }
    }
}
if(Trigger.isInsert && opptyMap.size()>0){
     for(task t: trigger.new){
            if(opptyMap.containsKey(t.whatId)){
                for(opportunity oppty: opptyMap.get(t.whatId)){
                   if(oppty.name.contains(t.subject)){
                      oppty.stageName='Re-Qualify';
                      updateOppList.add(oppty);
                   }
               }
            }
        }
    }
//update the oppties
if(updateOppList.size()>0){
    update updateOppList;
}
}
I need a trigger to query the WhoID on task, and if it is lead, look at lead field pi__score__c and populate this on task field score__c. The below trigger is not working in Sandbox. This is a modified trigger, in case certain parts don't make sense Any ideas?


trigger UpdatedRelatedLead on Task (after insert, after update) {

// Goal: Find the Lead Score of the lead that a task is related to
// and update the Score__c field on the task object with the value

// If related to a Lead, query to find out the LeadID

// Create collection of tasks that are related to a lead (where the lead is listed only once)
    Set<Id> LeadIds = new Set<Id>();
    for(Task t : trigger.new){
        String wId = t.WhatId;
        if(wId!=null && wId.startsWith('00Q') && !LeadIds.contains(t.WhoId)){
            LeadIds.add(t.WhoId);
        }
    }
    // Pull in Lead ids and related field to populate task record
    List<Lead> taskLeads = [Select Id, pi__score__c from Lead where Id in :LeadIds];
    Map<Id, Lead> ldMap = new Map<Id, Lead>();
    for(Lead l : taskLeads){
        ldMap.put(l.Id,l);
    }
    // Update custom task field with custom lead field
    for(Task t : trigger.new){
        String wId = t.WhoId;
        if(wId!=null && wId.startswith('00Q')){
            Lead thisLead = ldMap.get(t.WhoId);
            if(thisLead!=null){t.Score__c = thisLead.pi__score__c;}
        }
    }
}
I was able to get this trigger working in Sandbox, but when I tried to upload to production via change set, I received code coverage errors. Pardot is telling me to use the force.com IDE, however we do not have experience with that tool. Any ideas why this trigger cannot be uploaded to production throught a change set? The Pardot package has been installed.

trigger LogPersonAccountChange on Account (before delete, after insert, after undelete)
{
  List<pi__ObjectChangeLog__c> logs = new List<pi__ObjectChangeLog__c>();
 
  if (Trigger.new != null) {
    for (Account account : Trigger.new) {
 
      if (Account.PersonEmail != null && Account.PersonEmail != '') {
        pi__ObjectChangeLog__c log = new pi__ObjectChangeLog__c();
        log.pi__ObjectFid__c = Account.PersonContactId;
        log.pi__ObjectType__c = 1;
        log.pi__ObjectEmail__c = Account.PersonEmail;
 
        if  (System.Trigger.isInsert) {
          log.pi__ObjectState__c = 1;
        } else if  (System.Trigger.isDelete) {
          log.pi__ObjectState__c = 2;
        } else if  (System.Trigger.isUnDelete) {
          log.pi__ObjectState__c = 3;
 
        }
        logs.add(log);
      }
    }
  } else if (Trigger.old != null) {
    for (Account account : Trigger.old) {
      if (Account.PersonEmail != null && Account.PersonEmail != '') {
        pi__ObjectChangeLog__c log = new pi__ObjectChangeLog__c();
 
        log.pi__ObjectFid__c = Account.PersonContactId
 
        ;
        log.pi__ObjectType__c = 1;
        log.pi__ObjectEmail__c = Account.PersonEmail;
        if  (System.Trigger.isInsert) {
          log.pi__ObjectState__c = 1;
        } else if  (System.Trigger.isDelete) {
          log.pi__ObjectState__c = 2;
        } else if  (System.Trigger.isUnDelete) {
          log.pi__ObjectState__c = 3;
        }
        logs.add(log);
      }
    }
  }
 
  if (logs.size() > 0) {
 
    insert logs;
  }
}
 
I have a requirement to pass a date field to an external database when this date field changes. What would be the easiest way to accomplish this?
I am trying to write a trigger on task that queries the subject, and if it is equal to "Requalify", find the related account and related opportunity and change the opportunity status to "Re-qualify". I have the below trigger, but it is not changing the opportunity status. Any help would be greatly appreciated!

trigger TaskSubject on Task (after update, after insert) {

set<id> accountIdSet = new set<id>();
//capture all the subject names in a set
//set<string> subjectName = new set<string>{'Requalify'};
map<id, list<opportunity>> opptyMap = new map<id, list<opportunity>>();
list<opportunity> updateOppList = new list<opportunity>();

//get those tasks where the tasks are related to account. Capture the account IDs in a set.
for(task t: trigger.new){
            string tempId = string.valueOf(t.WhatId);
    if(tempId.startsWith('001')){
        accountIdSet.add(t.whatId);
    }
}

//If we have any account IDs then get the associated opportuity and store the one account to many opportunity in a map<id, list<opportunity>>
if(accountIdSet.size()>0){
    for(opportunity opp:[select Name, stageName, accountid from opportunity where accountid IN :accountIdSet]){
        if(opptyMap.containsKey(opp.accountId)){
            list<opportunity> oppList = opptyMap.get(opp.accountId);
            oppList.add(opp);
            opptyMap.put(opp.accountId, oppList);
        }else{
            list<opportunity> newOppList = new list<opportunity>();
            newOppList.add(opp);
            opptyMap.put(opp.accountId, newOppList);
        }
    }
}

//If we get the opportunities then change the stage.
if(Trigger.isUpdate && opptyMap.size()>0){
    for(task t: trigger.new){

 //Check if the subject of the task is one among the set 
 //and also confirm that the subject has been changed.

        if(t.subject != trigger.oldMap.get(t.id).subject && opptyMap.containsKey(t.whatId)){

  //iterate thru the list of the opportunity associated with that account 
  //and check which of the opportunity contains the task subject in the 
   //opportunity name and update the stage to re-qualify

            for(opportunity oppty: opptyMap.get(t.whatId)){
               {
                    oppty.stageName='Re-Qualify';
                    updateOppList.add(oppty);
                }
            }
        }
    }
}
if(Trigger.isInsert && opptyMap.size()>0){
     for(task t: trigger.new){
            if(opptyMap.containsKey(t.whatId)){
                for(opportunity oppty: opptyMap.get(t.whatId)){
                   if(oppty.name.contains(t.subject)){
                      oppty.stageName='Re-Qualify';
                      updateOppList.add(oppty);
                   }
               }
            }
        }
    }
//update the oppties
if(updateOppList.size()>0){
    update updateOppList;
}
}
I need a trigger to query the WhoID on task, and if it is lead, look at lead field pi__score__c and populate this on task field score__c. The below trigger is not working in Sandbox. This is a modified trigger, in case certain parts don't make sense Any ideas?


trigger UpdatedRelatedLead on Task (after insert, after update) {

// Goal: Find the Lead Score of the lead that a task is related to
// and update the Score__c field on the task object with the value

// If related to a Lead, query to find out the LeadID

// Create collection of tasks that are related to a lead (where the lead is listed only once)
    Set<Id> LeadIds = new Set<Id>();
    for(Task t : trigger.new){
        String wId = t.WhatId;
        if(wId!=null && wId.startsWith('00Q') && !LeadIds.contains(t.WhoId)){
            LeadIds.add(t.WhoId);
        }
    }
    // Pull in Lead ids and related field to populate task record
    List<Lead> taskLeads = [Select Id, pi__score__c from Lead where Id in :LeadIds];
    Map<Id, Lead> ldMap = new Map<Id, Lead>();
    for(Lead l : taskLeads){
        ldMap.put(l.Id,l);
    }
    // Update custom task field with custom lead field
    for(Task t : trigger.new){
        String wId = t.WhoId;
        if(wId!=null && wId.startswith('00Q')){
            Lead thisLead = ldMap.get(t.WhoId);
            if(thisLead!=null){t.Score__c = thisLead.pi__score__c;}
        }
    }
}
I was able to get this trigger working in Sandbox, but when I tried to upload to production via change set, I received code coverage errors. Pardot is telling me to use the force.com IDE, however we do not have experience with that tool. Any ideas why this trigger cannot be uploaded to production throught a change set? The Pardot package has been installed.

trigger LogPersonAccountChange on Account (before delete, after insert, after undelete)
{
  List<pi__ObjectChangeLog__c> logs = new List<pi__ObjectChangeLog__c>();
 
  if (Trigger.new != null) {
    for (Account account : Trigger.new) {
 
      if (Account.PersonEmail != null && Account.PersonEmail != '') {
        pi__ObjectChangeLog__c log = new pi__ObjectChangeLog__c();
        log.pi__ObjectFid__c = Account.PersonContactId;
        log.pi__ObjectType__c = 1;
        log.pi__ObjectEmail__c = Account.PersonEmail;
 
        if  (System.Trigger.isInsert) {
          log.pi__ObjectState__c = 1;
        } else if  (System.Trigger.isDelete) {
          log.pi__ObjectState__c = 2;
        } else if  (System.Trigger.isUnDelete) {
          log.pi__ObjectState__c = 3;
 
        }
        logs.add(log);
      }
    }
  } else if (Trigger.old != null) {
    for (Account account : Trigger.old) {
      if (Account.PersonEmail != null && Account.PersonEmail != '') {
        pi__ObjectChangeLog__c log = new pi__ObjectChangeLog__c();
 
        log.pi__ObjectFid__c = Account.PersonContactId
 
        ;
        log.pi__ObjectType__c = 1;
        log.pi__ObjectEmail__c = Account.PersonEmail;
        if  (System.Trigger.isInsert) {
          log.pi__ObjectState__c = 1;
        } else if  (System.Trigger.isDelete) {
          log.pi__ObjectState__c = 2;
        } else if  (System.Trigger.isUnDelete) {
          log.pi__ObjectState__c = 3;
        }
        logs.add(log);
      }
    }
  }
 
  if (logs.size() > 0) {
 
    insert logs;
  }
}
 

I have searched high and low for someone who has done this and have come up empty handed. I find it hard to believe this is not a common issue.

 

As you know, if an Opportunity is added to a Contact, the Contact is automatically added as a Contact Role on that Opportunity. It does not make them the Primary Contact Role or define the Role, but it does add them.

 

If an Opportunity is added to a Person Account, the Contact/Person Account is not automatically added as a Contact Role on the Opportunity. When the Opportunity is created there are no Contacts listed.

 

What I would like to do is to have a trigger that automatically adds the Person Account as a Contact to the Contact Roles when an Opportunity is created under them. I would like for them to be made Primary and a role of Decision Maker. 

 

It seems to me that adding Contact Roles automatically would be more common, but I guess not. Has anyone found a solution to this that they can share? Thank you everyone!

 

Dusty