• Dbjensen
  • NEWBIE
  • 160 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 22
    Questions
  • 33
    Replies
Hello - I need help adding Account Ids to Contacts. I tried using a map but I don't have any matching keySet that will return the Id. Can I add the Ids to a list and then assign the Id from the list to a updateCt.AccountId?  If so, how can I do this without writing a different class?
 
//Query newly created Account
       List <Account> insertedAcct = [SELECT Id FROM Account WHERE Id =:insertAccounts];

//Query contact that needs the new Account Id 
        List <Contact> indClientIdList = [SELECT Id, AccountId FROM Contact WHERE Id = :clientIdList];
        
        if(indClientIdList.size() > 0){
            for(Contact updateCT : indClientIdList){
                updateCt.AccountId =   NEW ACCOUNT Id HERE );
            }
        }



 
Hello - Hoping to get help with this query. When a lead is created and if it has either a Core number or a PC Account Id number, I look for an account with that matching core number or pc Id. 

The problem with this query is, if a lead had a core number but no pc id, the query returns a non matching account because it returns any account that has no pc id. 

Do I need 2 different queries? One that looks for Core Number and another that looks for PC ID?

acctList = [SELECT Id, Core_Number__c, PC_Account_Id__c FROM Account WHERE Core_Number__c = :coreNumberTextList 
                            OR PC_Account_Id__c = :pcAccountIdList LIMIT 1];
Hello - I am using the Query Plan Tool to see if a formula field qualifies for indexing. The formula field is called FirstLastNameStreetAndZipCode__c and is on the contact object. 

I'm using this query to get the cost:

SELECT Id FROM Contact WHERE FirstLastNameStreetAndZipCode__c = 'Jensen43289874'   

In production, I get a cost of 0.0 but in the sandbox I'm getting 2.8. Is this the correct query to use to test formula fields for indexing? 

User-added image
Hello -I have a soql query that searches for tasks created in the last 7 days that are related to leads created today.

sssTask = [SELECT Id, Owner.Name, WhoId FROM Task 
                       WHERE WhoId != null
                       AND qbdialer__Call_Date_Time__c = Last_N_Days:7
                       AND WhoId IN :leadIds
                       ORDER BY CreatedDate DESC];

A lead may have more than 1 task. I need to add only the most recently created task to a new list for each lead created today. 

List<Task> recentlyCreated = new List<Task>();

Any assistance would be greatly appreciated. 
Hello all - I'm trying to use containsAll() but it is returning false (bullet point 3). Below is a pic of the debug log which shows the states from the set. Any help would be greatly apprceciated. 

1. I'm retrieving field values from a text area field called 'States' on a custom setting object and adding the states to a Set. (the custom settings is a list)

        //Get states from custom settings field and add to set
        Set<String> gwStates = new Set<String>();
        
        for(GW_States__c gwSts : GW_States__c.getAll().values()){
            if(gwSts.States__c != null){
                gwStates.add(gwSts.States__c);
            }
        }
        
        System.debug('States in Set ' +gwStates);

2. Then I query a custom object called Association and add the Association's state to a set and a map. 

        //map/set of states from association
        Map<Id, String> assocState = new Map<Id, String>();
        Set<String> stateSet = new Set<String>();
        
        if(assoc.size() > 0 ){
            for(Association__c associt : assoc){
            assocState.put(associt.Id, associt.Association_State_Province__c);
            stateSet.add(associt.Association_State_Province__c);
            }
        }

            System.debug('State in set from association ' + stateSet);
            System.debug('State in map ' +assocState);

3. Now I'm checking to see if the Association state is contained in the gwStates set and the map. Both return false. (see debug log)

//Use compare method to check for matching states
                Boolean state = gwStates.contains(assocState.get(assocEvent.WhatId));
                Boolean statezSetcompare = gwStates.containsAll(stateSet);
                    system.debug('state compare from map = ' +state);
                system.debug('state compare from Assoc set = ' +statezSetcompare);

User-added image
Hello - Hoping someone can help out with a validation rule that's not working in flow. I have a screen elment with a text field called "Last_Name_1" and a text field called "Phone_1". If the last name is not blank, there must be a phone number. I cannot get the vaidation rule to fire. I tested the same validation rule on the object fields and it works as expected. Below is my validation rule.  

AND(
NOT(ISBLANK({!Last_Name_1})),
ISBLANK({!Phone_1}))

User-added image

 
Hello - How can I return a lead list called 'returnedLead' from a class to a trigger. Any assistance would be greatly appreciated. 

Trigger:
if(Trigger.isUpdate){
                   //Passing Trigger.new and Trigger.old to LeadOwnerAssignment class
                    LeadOwnerAssignment.leadChanges(Trigger.new, Trigger.old);
}

Class: 
public class LeadOwnerAssignment {
    
    public static void leadChanges(List<Lead> newLead, List<Lead> oldLead){
        
        List<Lead> returnedLead = new List<Lead>();
        
        //Old Lead Map
        Map<String, String> mapOfOldAffinityType = new Map<String, String>();
        
        for(lead oldLds : oldLead) {
            mapOfOldAffinityType.put(oldLds.Affinity_Type__c, oldLds.LastNameStreetAndZipCode__c);
        }

        for(Lead ld : newLead) {
            if(ld.Affinity_Type__c != mapOfOldAffinityType.get(ld.Affinity_Type__c)){
                returnedLead.add(ld);     
            }
        }  
    }            
}
Hello - What is the best way to query a million leads? When a lead is created, I need to search all leads to see if there is a matching field. The matching field is a formula field called LastNameStreetAndZipCode__c. If a match is found, I'll add the Id of the matching lead to a lookup field on the new Lead. Below is the SOQL I have.  

public static void potentialDupes (List<Lead> newLead){

        //Lead Maps and list
        Map<String, Lead> mapOfLastNameStreet = new Map<String, Lead>();
        
        for(Lead ld : newLead){
            if(ld.PC_Submission_Id__c == null && ld.Lead_Id__c == null){
                mapOfLastNameStreet.put(ld.LastNameStreetAndZipCode__c, ld);
            } 
        }
        
        //query for existing leads that match new lead
        List<Lead> existingLead = [SELECT ID, LastNameStreetAndZipCode__c, Status, Home_Phone__c, CreatedDate 
                                   FROM LEAD 
                                   WHERE LastNameStreetAndZipCode__c IN :mapOfLastNameStreet.keySet()
                                   AND Duplicate__c != true
                                   ORDER BY CreatedDate ASC];
Hello - I'm trying to pass trigger.new and trigger.old to a single list which then will be passed to a class.

Here's the class I'm calling in the trigger: 
LeadOwnerAssignment.assignOwner(Trigger.new, Trigger.old);
Here is the class method I'm passing the lists to:
public static void assignOwner(List<Lead> newLead, List<Lead> oldLead) {

I'm hoping to do something like this (except pass both trigger.new and trigger.old).
List<Lead> newLeadList = new List<Lead>();
                    for(Lead newLead : Trigger.new){
                        if(newLead.Lead_Id__c == null){
                            newLeadList .add(newLead);
                        }  
                    }
                   LeadOwnerAssignment.assignOwner(newLeadList );
 
Any help would be greatly appreciated. 
hello - I'm hitting a govenor limit with this SOQL query. I can't figure out why it's hitting the limit. Any help would be greatly appreciated. 

for(Lead newLds : newLead){
            mapOfNewAffinityType.put(newLds.Affinity_Type__c, newLds.LastNameStreetAndZipCode__c);
            mapOfNewAffinitySubType.put(newLds.Affinity_Sub_Type__c, newLds.LastNameStreetAndZipCode__c);
        }

//Query Affinity Type 
        List<Affinity__c> affinity = [SELECT Id, Occupation_Code__c, Occupation_Sub_Type_Code__c, Occupation__c,
                                      Occupation_Sub_Type__c FROM Affinity__c
                                      WHERE Occupation_Code__c = :mapOfNewAffinityType.keySet() OR
                                      Occupation_Sub_Type_Code__c = :mapOfNewAffinitySubType.keySet()];

//Affinity maps
        Map<String, String> mapAffinityTyp = new Map<String, String>();
        Map<String, String> mapAffinitySubTyp = new Map<String, String>();
        
        //Affinity values
        for(Affinity__c af : affinity) {
            mapAffinityTyp.put(af.Occupation_Code__c, af.Occupation__c);
            mapAffinitySubTyp.put(af.Occupation_Sub_Type_Code__c, af.Occupation_Sub_Type__c);
        }
Hello - I have small class that looks for an existing lead that matches a newly inserted lead. If a matching lead is found, it checks a box called Resubmitted. If I dataload any more than 10 records, I get a CPU time limit error. What do I need to do to fix this code so I load leads in bulk? 

Class:
  1. public class ResubmittedLead {
  2.     public static void resubmittedLead(List<Lead> reLead){
  3.         List<Lead> leadList = new List<Lead>();
  4.         //Lead Maps
  5.         Map<String, String> mapOfLeadId = new Map<String, String>();      
  6.         for (Lead ld : reLead){   
  7.             mapOfLeadId.put(ld.LastNameStreetAndZipCode__c, ld.Status);
  8.         }
  9.        //Search for existing lead
  10.         for(Lead existingLd : [Select Id, Status FROM Lead WHERE LastNameStreetAndZipCode__c IN :mapOfLeadId.keySet()
  11.                               AND Duplicate__c = false]){
  12.             existingLd.Resubmitted__c = true;
  13.             leadList.add(existingLd);    
  14.         }
  15.         update leadList;
  16.     }
Trigger:
  1. if (Trigger.IsAfter) {
  2.                 if (Trigger.isInsert){
  3.                     for(Lead ld:Trigger.new){
  4.                         if(ld.Duplicate__c == true){
  5.                             ResubmittedLead.resubmittedLead(Trigger.new);
  6.                         }
  7.                     }
  8.                }
  9.           }
Hello - I have an object called Agent. Every sales rep has 2 agent records. One record represents an Outbound record and the other is Inbound. The field that identifies inbound/outbound is Rep_Type__c. For outbound it's SLO. For inbound it's SLI.

Below is the query I'm using to get both records.  

List<Agent__c> salesAgentList = [SELECT Id, SOB_Code__c, Name, Rep_Type__c, Agent_Performance__c, User__c FROM Agent__c 
                                         WHERE SOB_Code__c IN :mapNewSalesAgntSOB.keySet() OR User__c IN :mapOfNewLeadOwner.keySet()]; 

The problem is, my map is grabbing the inbound record (SLI) and I need to grab the outbound record (SLO). 

        Map<Id, String> mapOfSalesRepType = new Map<Id, String>();
            
        for(Agent__c agt : salesAgentList) {
            mapOfSalesRepType.put(agt.User__c, agt.Rep_Type__c);
        }
        
        System.debug('Agent Rep type ' + mapOfSalesRepType);
      
How can I do this? 
Hello - I'm running into an error when I run my test class. Below is the code from the class. The test class says line 17 (below) is causing too many soql queries.  The query looks for opporutnity line items where the OpportunityId is in the mapOfOppIds maps. Could you please let me know why this soql error is happening?
  1.  //Map of new opp values
  2.         Map<Id, Decimal> mapOfOppIds = new Map<Id, Decimal>();
  3.         Map<Id, Decimal> mapOfUpdatedOppIds = new Map<Id, Decimal>();
  4.         
  5.         for(Opportunity newOpp : newUpdatedOpp) {
  6.             if(mapOfOldOppArr.get(newOpp.Id) != mapOfUpdatedArr.get(newOpp.Id)
  7.                && newOpp.Renewed_Opportunity__c == true){
  8.                 mapOfOppIds.put(newOpp.Originating_Opp_Id__c, newOpp.ARR__c);
  9.                 mapOfUpdatedOppIds.put(newOpp.Id, newOpp.ARR__c);
  10.                     }        
  11.             }
  12.         
  13.         system.debug('values in mapOfOppIds ' +mapOfOppIds);
  14.         system.debug('values in mapOfUpdatedOppIds ' +mapOfUpdatedOppIds);
  15.         
  16.         //Query Original Opp Line Items
  17.          List<OpportunityLineItem> oli = [Select Id, OpportunityId, UnitPrice, Originating_OLI_Id__c FROM OpportunityLineItem
  18.                                               WHERE OpportunityId IN :mapOfOppIds.keySet()];
  19.         
  20.         System.debug('Opp Line Items from original opp ' +oli);
Hello - I have a list that that finds the the opportunity line items related to an opporunity. I'm adding the opportunity line item ids to a map using a for loop. However, only 1 key value is getting added to the map - even when the list contains multiple values. Could you let me know why the for loop is only adding 1 key value to the map?

//list of opportunity line items related to the opportunity
List<OpportunityLineItem> oliList = [SELECT Id, OpportunityId, Product_Name__c FROM 
                                             OpportunityLineItem WHERE OpportunityId IN :mapNewOpp.keySet()];
    
    system.debug('Opp Line Items in List ' +oliList);
        
        map<Id, String> mapOfOLI = new Map<Id, String>();
        
        for(OpportunityLineItem oliFromList : oliList) {
            mapOfOLI.put(oliFromList.OpportunityId, oliFromList.Product_Name__c);
        }
        
        system.debug('opp product names in map ' +mapOfOLI);
Hello - I have a long text field on an opportunity that I would like to auto populate with the names of the products associated to that opportunity. I'm using a before update trigger and class. I have a map that holds all of the product names and can see the results in a debug statement. However, when I update the field, it's not adding all of the product names in the map. It only adds one name. 

Example: My opp has 2 products. Widget 1 and Widget 2. I need to add both product names to a long text field. Below is my code. Any help would be appreciated. 

public class AddProductNamesToOpportunity {
    
    public static void addProductNmsToOpp(List<Opportunity> newOpp, List<Opportunity> oldOpp) {
        
        string separator = '; ';
        list<Opportunity> oppList = new list<Opportunity>();
        
        //Old Opportunity Maps
        map<Id, Decimal> mapOfOldOpps = new map<Id, Decimal>();
        
        for(Opportunity oldOpps : oldOpp) {
            mapOfOldOpps.put(oldOpps.Id, oldOpps.Amount);
        }
        
        system.debug('values in old map ' +mapOfOldOpps);
        
        //New Opportunity Maps
        map<Id, Decimal> mapOfnewOpps = new map<Id, Decimal>();
        
        for(Opportunity newOpps : newOpp) {
            mapOfnewOpps.put(newOpps.Id, newOpps.Amount);
        }
        
        system.debug('values in new map ' +mapOfnewOpps);
        
        //Query Opp Line Items
        List<OpportunityLineItem> oppLinImList = [SELECT 
                                                  //Id,Product2.Name,PricebookEntry.Product2.Name,
                                                  OpportunityId,Product_Name__c FROM OpportunityLineItem WHERE OpportunityId IN :mapOfnewOpps.keyset()];
        
        system.debug('opp line items found ' +oppLinImList);
        
        //Opp Line Item Maps
        map<Id, String> mapOLI = new map<Id, String>();
        
        for(OpportunityLineItem oli : oppLinImList) {
            mapOLI.put(oli.OpportunityId, oli.Product_Name__c);
        }
        
        system.debug('values in opp line item map' +mapOLI);
        
        for(Opportunity opp : newOpp) {
            if(mapOfOldOpps.values() != mapOfnewOpps.values() && !oppLinImList.isEmpty()) {
                opp.Products_2__c = mapOLI.get(opp.Id);
                oppList.add(opp);
            } else if (oppLinImList.isEmpty()){
                opp.Products_2__c = null;
                oppList.add(opp);
            }
        }
        
        try{
            update oppList;
        } catch (Exception e) {
            system.debug('Opp product field did not update ' +e);
        } 
    }
}
 
Hello - Is it possible to add a column to the debug log go show which class or method a debug statement is from? If not, is there an easy way to tell? 

User-added image
hello - I have class that adds the Lead ID to a custom object. However, it adds the same ID to very lead when I do a bulk upload because of this line: ldsubs.Lead__c = listOfLeadsSubIDs[0];

I can't figure how how to add the corect Lead Id to every lead inserted via bulk insert. Any assistance would be greatly appreciated. 

public class AddLeadSubmissionToLead {
    
    public static void addLStoLead (List<Lead> leadsFromTrigger) {
        
        Set<String> nameCompany = new Set<String>();
        List<Lead_Submission__c> listOfLeadsSubs = new List<Lead_Submission__c>();
        List<Id> listOfLeadsSubIDs = new List<Id>();
        
        for(Lead nwLead : leadsFromTrigger) {
            listOfLeadsSubIDs.add(nwLead.Id);
            nameCompany.add(nwLead.LastNameStreetAndZipCode__c );
        }
        
        List<Lead_Submission__c> ldSub = [SELECT Id, Lead__c, LastNameStreetAndZipCode__c
                                          FROM Lead_Submission__c 
                                          WHERE LastNameStreetAndZipCode__c =:nameCompany];
        
        System.debug('Lead Submission Found ' + ldSub);
        
        for(Lead_Submission__c ldsubs : ldSub) {
            if(ldsubs.Lead__c == null && !ldSub.isEmpty()) {
                ldsubs.Lead__c = listOfLeadsSubIDs[0];
                listOfLeadsSubs.add(ldsubs);
            }
        }
        update listOfLeadsSubs;
    }
}
Hello - I'm having issues adding an Id to another record. In a nutshell, I have a custom object called Lead Submission. When a Lead Submission is created, a standard Lead record is also created. How can I add the Id of the Lead Submission to the standard Lead record?

All of the code resides in a class and is called by a "before trigger". The code is a bit long but happy to post if it helps.

Any help would be greatly appreciated. 

 
Hello - I have a class that adds an account and contact to a new lead - if the account and contact exists. I'm trying to call this from an After Insert trigger. However, when I insert the lead, nothing happens. I'm wondering if it's something to do with the trigger parameter but just not sure. Any help would be greatly appreciated. 

This is the method I'm trying to call from the trigger.  AddExistingAccountAndContactToLead.findExistingAccountContact(Trigger.new);

Here is the trigger: 
trigger MasterLeadTrigger on Lead (
    before insert, after insert, 
    before update, after update, 
    before delete, after delete) {
        
        if (Trigger.isBefore) {
            if (Trigger.isInsert) {
                SetLeadRecordType.leadsToUpdate(Trigger.new); 
                DuplicateLead.potentialDupes(Trigger.new);
                CloseExpiredLeads.closingExpiredLeads(Trigger.new);
            } 
            if (Trigger.isUpdate) {
                
            }
            if (Trigger.isDelete) {
                
            }
            
         if (Trigger.IsAfter) {
             if (Trigger.isInsert) {
                 AddExistingAccountAndContactToLead.findExistingAccountContact(Trigger.new);
                 //AddAccountandContactToLead.addRecodrsToLead(Trigger.New);
                } 
                if (Trigger.isUpdate) {
                    
                }
                if (Trigger.isDelete) {
                }
            }
        }
    }

Here is the class:
public class AddExistingAccountAndContactToLead {
    
    public static void findExistingAccountContact(List<Lead> nonDupe) {
        
        List<String> LastNameStreetAndZipCode = new List<String>();
        List<Account> existingAcctsList = new List<Account>();
        List<Contact> existingCtList = new List<Contact>();
        List<Lead_Submission__c> existingLSList = new List<Lead_Submission__c>();
        
        for(Lead newLead : nonDupe) {
                LastNameStreetAndZipCode.add(newLead.LastNameStreetAndZipCode__c);
        }
        
        System.debug('Addresses in LastNameStreetAndZipCode ' + LastNameStreetAndZipCode);
        
        Map<String, Account> mapOfAccounts = new Map<String, Account>();

        if(LastNameStreetAndZipCode.size() > 0) {
            Try{ 
        List<Account> exsistingAccount = [Select Id, LastNameStreetAndZipCode__c FROM Account
                                          WHERE LastNameStreetAndZipCode__c IN : LastNameStreetAndZipCode];
        
         System.debug('Matching account found ' + exsistingAccount);      
                
            existingAcctsList.addAll(exsistingAccount);
            } catch(Exception e) {
                System.debug('No existing accounts found ' + e);
            }
        }
        
        for(Account acct : existingAcctsList) {
            mapOfAccounts.put(acct.LastNameStreetAndZipCode__c, acct);
        }
        
        Map<String, Contact> mapOfContacts = new Map<String, Contact>();
        
        if(LastNameStreetAndZipCode.size() > 0) {
            Try{ 
        List<Contact> existingContact = [Select Id, LastNameStreetAndZipCode__c FROM Contact
                                         WHERE LastNameStreetAndZipCode__c IN :LastNameStreetAndZipCode];
                
        System.debug('Matching contact found ' + existingContact);        
        
        existingCtList.addAll(existingContact);
                } catch(Exception e) {
                System.debug('No existing contacts found ' + e);
            }
        }
        
        for(Contact ct : existingCtList) {
            mapOfContacts.put(ct.LastNameStreetAndZipCode__c, ct);
        }
        
        Map<String, Lead_Submission__c> mapOfLeadSubmission = new Map<String, Lead_Submission__c>();

        if(LastNameStreetAndZipCode.size() > 0) {
            Try{ 
        List<Lead_Submission__c> exsistingLeadSubmission = [Select Id, LastNameStreetAndZipCode__c FROM Lead_Submission__c
                                          WHERE LastNameStreetAndZipCode__c =: LastNameStreetAndZipCode];
        
         System.debug('Matching lead submission found ' + exsistingLeadSubmission);
                
            existingLSList.addAll(exsistingLeadSubmission);
            } catch(Exception e) {
                System.debug('No existing lead submissions found ' + e);
            }
        }
        
        System.debug('Lead Sbumission added to list ' + existingLSList);
        
        for(lead_submission__c leadSub : existingLSList) {
            mapOfLeadSubmission.put(leadSub.LastNameStreetAndZipCode__c, leadSub);
        }
        
        for(Lead newLead : nonDupe) {
            //if(newLead.Duplicate__c == false) {
                Account retrievedAcctId = mapOfAccounts.get(newLead.LastNameStreetAndZipCode__c);
                Contact retrievedCtId = mapOfContacts.get(newLead.LastNameStreetAndZipCode__c);
                Lead_Submission__c retrievedLsId = mapOfLeadSubmission.get(newLead.LastNameStreetAndZipCode__c);
                //System.debug('retrievedLsId = ' + retrievedLsId.Id);
                try {
                    newLead.Household__c = retrievedAcctId.Id;
                    newLead.Individual_Client__c = retrievedCtId.Id;
                    //newLead.Lead_Submission__c = retrievedLsId.Id;
                } catch(Exception e) {
                System.debug('No household id or contact id found ' + e);
                  }
            //}
        }
    }
}
Hello - I need to bulkify this code as it's hitting govenor limits. This code triggers when a lead is inserted. The code looks for an existing account and contact based on a match from 3 fields on the lead. If the account and contact are found, it adds the account ID and contact ID to the lead that's being inserted. 

Could you please help if you know how to fix this code so it can handle bulk inserts?  Thanks for any help you can provide. 

public class AddExistingAccountAndContactToLead {
    
    public static void findExistingAccountContact(List<Lead> nonDupe) {
        
        List<Lead> leadsList = new List<Lead>();
        List<Id> acctId = new List<Id>();
        List<Account> accountList = new List<Account>();
        
        for(Lead newLead : nonDupe) {
            if(newLead.Duplicate__c == false) {
                List<Account> exsistingAccount = [Select Id FROM Account
                                               Where 
                                               First_3_Char_of_Street__c = :newLead.First_3_Char_of_Street__c
                                               AND First_5_Char_of_Last_Name__c = :newLead.First_5_Char_of_Last_Name__c
                                               AND BillingPostalCode = :newLead.PostalCode]; 
                
                for(Account acct : exsistingAccount) {
                    newLead.Household__c = acct.Id;
                }            
                           
            }

        }
        
    for(Lead newLead : nonDupe) {
            if(newLead.Duplicate__c == false) {
                List<Contact> existingContact = [Select Id FROM Contact
                                               Where 
                                               First_3_Char_of_Street__c = :newLead.First_3_Char_of_Street__c
                                               AND First_5_Char_of_Last_Name__c = :newLead.First_5_Char_of_Last_Name__c
                                               AND MailingPostalCode = :newLead.PostalCode]; 
                
                for(Contact ct : existingContact) {
                    newLead.Individual_Client__c = ct.Id;
                }            
                           
            }

        }

    }
}
Hello - I need help adding Account Ids to Contacts. I tried using a map but I don't have any matching keySet that will return the Id. Can I add the Ids to a list and then assign the Id from the list to a updateCt.AccountId?  If so, how can I do this without writing a different class?
 
//Query newly created Account
       List <Account> insertedAcct = [SELECT Id FROM Account WHERE Id =:insertAccounts];

//Query contact that needs the new Account Id 
        List <Contact> indClientIdList = [SELECT Id, AccountId FROM Contact WHERE Id = :clientIdList];
        
        if(indClientIdList.size() > 0){
            for(Contact updateCT : indClientIdList){
                updateCt.AccountId =   NEW ACCOUNT Id HERE );
            }
        }



 
Hello - Hoping to get help with this query. When a lead is created and if it has either a Core number or a PC Account Id number, I look for an account with that matching core number or pc Id. 

The problem with this query is, if a lead had a core number but no pc id, the query returns a non matching account because it returns any account that has no pc id. 

Do I need 2 different queries? One that looks for Core Number and another that looks for PC ID?

acctList = [SELECT Id, Core_Number__c, PC_Account_Id__c FROM Account WHERE Core_Number__c = :coreNumberTextList 
                            OR PC_Account_Id__c = :pcAccountIdList LIMIT 1];
Hello - I am using the Query Plan Tool to see if a formula field qualifies for indexing. The formula field is called FirstLastNameStreetAndZipCode__c and is on the contact object. 

I'm using this query to get the cost:

SELECT Id FROM Contact WHERE FirstLastNameStreetAndZipCode__c = 'Jensen43289874'   

In production, I get a cost of 0.0 but in the sandbox I'm getting 2.8. Is this the correct query to use to test formula fields for indexing? 

User-added image
Hello -I have a soql query that searches for tasks created in the last 7 days that are related to leads created today.

sssTask = [SELECT Id, Owner.Name, WhoId FROM Task 
                       WHERE WhoId != null
                       AND qbdialer__Call_Date_Time__c = Last_N_Days:7
                       AND WhoId IN :leadIds
                       ORDER BY CreatedDate DESC];

A lead may have more than 1 task. I need to add only the most recently created task to a new list for each lead created today. 

List<Task> recentlyCreated = new List<Task>();

Any assistance would be greatly appreciated. 
Hello all - I'm trying to use containsAll() but it is returning false (bullet point 3). Below is a pic of the debug log which shows the states from the set. Any help would be greatly apprceciated. 

1. I'm retrieving field values from a text area field called 'States' on a custom setting object and adding the states to a Set. (the custom settings is a list)

        //Get states from custom settings field and add to set
        Set<String> gwStates = new Set<String>();
        
        for(GW_States__c gwSts : GW_States__c.getAll().values()){
            if(gwSts.States__c != null){
                gwStates.add(gwSts.States__c);
            }
        }
        
        System.debug('States in Set ' +gwStates);

2. Then I query a custom object called Association and add the Association's state to a set and a map. 

        //map/set of states from association
        Map<Id, String> assocState = new Map<Id, String>();
        Set<String> stateSet = new Set<String>();
        
        if(assoc.size() > 0 ){
            for(Association__c associt : assoc){
            assocState.put(associt.Id, associt.Association_State_Province__c);
            stateSet.add(associt.Association_State_Province__c);
            }
        }

            System.debug('State in set from association ' + stateSet);
            System.debug('State in map ' +assocState);

3. Now I'm checking to see if the Association state is contained in the gwStates set and the map. Both return false. (see debug log)

//Use compare method to check for matching states
                Boolean state = gwStates.contains(assocState.get(assocEvent.WhatId));
                Boolean statezSetcompare = gwStates.containsAll(stateSet);
                    system.debug('state compare from map = ' +state);
                system.debug('state compare from Assoc set = ' +statezSetcompare);

User-added image
Hello - Hoping someone can help out with a validation rule that's not working in flow. I have a screen elment with a text field called "Last_Name_1" and a text field called "Phone_1". If the last name is not blank, there must be a phone number. I cannot get the vaidation rule to fire. I tested the same validation rule on the object fields and it works as expected. Below is my validation rule.  

AND(
NOT(ISBLANK({!Last_Name_1})),
ISBLANK({!Phone_1}))

User-added image

 
Hello - How can I return a lead list called 'returnedLead' from a class to a trigger. Any assistance would be greatly appreciated. 

Trigger:
if(Trigger.isUpdate){
                   //Passing Trigger.new and Trigger.old to LeadOwnerAssignment class
                    LeadOwnerAssignment.leadChanges(Trigger.new, Trigger.old);
}

Class: 
public class LeadOwnerAssignment {
    
    public static void leadChanges(List<Lead> newLead, List<Lead> oldLead){
        
        List<Lead> returnedLead = new List<Lead>();
        
        //Old Lead Map
        Map<String, String> mapOfOldAffinityType = new Map<String, String>();
        
        for(lead oldLds : oldLead) {
            mapOfOldAffinityType.put(oldLds.Affinity_Type__c, oldLds.LastNameStreetAndZipCode__c);
        }

        for(Lead ld : newLead) {
            if(ld.Affinity_Type__c != mapOfOldAffinityType.get(ld.Affinity_Type__c)){
                returnedLead.add(ld);     
            }
        }  
    }            
}
Hello - I'm trying to pass trigger.new and trigger.old to a single list which then will be passed to a class.

Here's the class I'm calling in the trigger: 
LeadOwnerAssignment.assignOwner(Trigger.new, Trigger.old);
Here is the class method I'm passing the lists to:
public static void assignOwner(List<Lead> newLead, List<Lead> oldLead) {

I'm hoping to do something like this (except pass both trigger.new and trigger.old).
List<Lead> newLeadList = new List<Lead>();
                    for(Lead newLead : Trigger.new){
                        if(newLead.Lead_Id__c == null){
                            newLeadList .add(newLead);
                        }  
                    }
                   LeadOwnerAssignment.assignOwner(newLeadList );
 
Any help would be greatly appreciated. 
hello - I'm hitting a govenor limit with this SOQL query. I can't figure out why it's hitting the limit. Any help would be greatly appreciated. 

for(Lead newLds : newLead){
            mapOfNewAffinityType.put(newLds.Affinity_Type__c, newLds.LastNameStreetAndZipCode__c);
            mapOfNewAffinitySubType.put(newLds.Affinity_Sub_Type__c, newLds.LastNameStreetAndZipCode__c);
        }

//Query Affinity Type 
        List<Affinity__c> affinity = [SELECT Id, Occupation_Code__c, Occupation_Sub_Type_Code__c, Occupation__c,
                                      Occupation_Sub_Type__c FROM Affinity__c
                                      WHERE Occupation_Code__c = :mapOfNewAffinityType.keySet() OR
                                      Occupation_Sub_Type_Code__c = :mapOfNewAffinitySubType.keySet()];

//Affinity maps
        Map<String, String> mapAffinityTyp = new Map<String, String>();
        Map<String, String> mapAffinitySubTyp = new Map<String, String>();
        
        //Affinity values
        for(Affinity__c af : affinity) {
            mapAffinityTyp.put(af.Occupation_Code__c, af.Occupation__c);
            mapAffinitySubTyp.put(af.Occupation_Sub_Type_Code__c, af.Occupation_Sub_Type__c);
        }
Hello - I have small class that looks for an existing lead that matches a newly inserted lead. If a matching lead is found, it checks a box called Resubmitted. If I dataload any more than 10 records, I get a CPU time limit error. What do I need to do to fix this code so I load leads in bulk? 

Class:
  1. public class ResubmittedLead {
  2.     public static void resubmittedLead(List<Lead> reLead){
  3.         List<Lead> leadList = new List<Lead>();
  4.         //Lead Maps
  5.         Map<String, String> mapOfLeadId = new Map<String, String>();      
  6.         for (Lead ld : reLead){   
  7.             mapOfLeadId.put(ld.LastNameStreetAndZipCode__c, ld.Status);
  8.         }
  9.        //Search for existing lead
  10.         for(Lead existingLd : [Select Id, Status FROM Lead WHERE LastNameStreetAndZipCode__c IN :mapOfLeadId.keySet()
  11.                               AND Duplicate__c = false]){
  12.             existingLd.Resubmitted__c = true;
  13.             leadList.add(existingLd);    
  14.         }
  15.         update leadList;
  16.     }
Trigger:
  1. if (Trigger.IsAfter) {
  2.                 if (Trigger.isInsert){
  3.                     for(Lead ld:Trigger.new){
  4.                         if(ld.Duplicate__c == true){
  5.                             ResubmittedLead.resubmittedLead(Trigger.new);
  6.                         }
  7.                     }
  8.                }
  9.           }
Hello - I have an object called Agent. Every sales rep has 2 agent records. One record represents an Outbound record and the other is Inbound. The field that identifies inbound/outbound is Rep_Type__c. For outbound it's SLO. For inbound it's SLI.

Below is the query I'm using to get both records.  

List<Agent__c> salesAgentList = [SELECT Id, SOB_Code__c, Name, Rep_Type__c, Agent_Performance__c, User__c FROM Agent__c 
                                         WHERE SOB_Code__c IN :mapNewSalesAgntSOB.keySet() OR User__c IN :mapOfNewLeadOwner.keySet()]; 

The problem is, my map is grabbing the inbound record (SLI) and I need to grab the outbound record (SLO). 

        Map<Id, String> mapOfSalesRepType = new Map<Id, String>();
            
        for(Agent__c agt : salesAgentList) {
            mapOfSalesRepType.put(agt.User__c, agt.Rep_Type__c);
        }
        
        System.debug('Agent Rep type ' + mapOfSalesRepType);
      
How can I do this? 
Hello - I'm running into an error when I run my test class. Below is the code from the class. The test class says line 17 (below) is causing too many soql queries.  The query looks for opporutnity line items where the OpportunityId is in the mapOfOppIds maps. Could you please let me know why this soql error is happening?
  1.  //Map of new opp values
  2.         Map<Id, Decimal> mapOfOppIds = new Map<Id, Decimal>();
  3.         Map<Id, Decimal> mapOfUpdatedOppIds = new Map<Id, Decimal>();
  4.         
  5.         for(Opportunity newOpp : newUpdatedOpp) {
  6.             if(mapOfOldOppArr.get(newOpp.Id) != mapOfUpdatedArr.get(newOpp.Id)
  7.                && newOpp.Renewed_Opportunity__c == true){
  8.                 mapOfOppIds.put(newOpp.Originating_Opp_Id__c, newOpp.ARR__c);
  9.                 mapOfUpdatedOppIds.put(newOpp.Id, newOpp.ARR__c);
  10.                     }        
  11.             }
  12.         
  13.         system.debug('values in mapOfOppIds ' +mapOfOppIds);
  14.         system.debug('values in mapOfUpdatedOppIds ' +mapOfUpdatedOppIds);
  15.         
  16.         //Query Original Opp Line Items
  17.          List<OpportunityLineItem> oli = [Select Id, OpportunityId, UnitPrice, Originating_OLI_Id__c FROM OpportunityLineItem
  18.                                               WHERE OpportunityId IN :mapOfOppIds.keySet()];
  19.         
  20.         System.debug('Opp Line Items from original opp ' +oli);