• Shraddha D Gupta
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 5
    Questions
  • 9
    Replies
Hi All, 

I am getting the error as below while contracting the Opportunity -

SBQQ.OpportunityAfter: execution of AfterUpdate caused by: System.QueryException : duplicate field selected: SBQQ__Status__c(SBQQ) No record updated

and not sure how to resolve this. 

Any help would be much appreaciated. 

Thanks!
 
Hi All,

I am not a developer and in our Org few triggers are written by previous developers and recently we started getting SOQL error a lot and I am not sure how I can fix it. 

In one of the error log, I am seeing the name of this trigger and hence thought of getting reviewed it with the community -


rigger leadAutomaticAssignmentToCampaign on Lead (after insert, after update) {
    
    // This trigger assigns automatically all BrigthTalk leads to the BrightTalk parent campaign in sfdc with the member status "Subscriber"
    
    Map<Id,Lead> leadsToAssign = new Map<Id,Lead>();
    
    for (Lead newLead : Trigger.new){
        if ( newLead.Lead_Gen_Event__c != null && newLead.Lead_Gen_Event__c.compareTo('online_brighttalk_2015') == 0) {
            leadsToAssign.put(newLead.Id,newLead);
        }        
    }
    
    // Get the BrightTalk parent campaign in sfdc
    // CHANGE THE CAMPAING ID to run leadAutomaticAssignmentToCampaignTest or TO DEPLOY TRIGGER IN PRO
    // DEV6 Campaing ID = 7018A0000006QyU
    // PRO Campaing ID = 70170000001Cx0Y
    List<Campaign> parentBrightTALKCampaign = [SELECT Id, ParentId, Type, Status, Lead_Gen_Event__c FROM Campaign WHERE Id = '70170000001Cx0Y'];
    
    if (parentBrightTALKCampaign.size() == 1){
        List<CampaignMember> newMembers = new List<CampaignMember>();
            
        List<CampaignMember> currentMembers = [SELECT LeadId
                                               FROM CampaignMember 
                                               WHERE CampaignId = :parentBrightTALKCampaign.get(0).id AND LeadId IN :leadsToAssign.keyset()];
        
        // Check if the Lead is already a campaing member
        for (CampaignMember currentMember : currentMembers){
            if (leadsToAssign.containsKey(currentMember.leadId)){
                leadsToAssign.remove(currentMember.leadId);
            }
        }
        
        for(Lead lead : leadsToAssign.values()){
            newMembers.add(new CampaignMember(CampaignId = parentBrightTALKCampaign.get(0).id, LeadId = lead.Id, Status = 'Subscriber'));
        }                    
        
        insert newMembers;
    }
    
}

Also, a lot more errors are comming in leadspace trigger to but Leadspace trigger is the managed package trigger and I heard that managed packgae do not count for the limits but when I checked the Installed package list I found that limit checkbox is TRUE against the Leadspace package. 

I have also read few people saying that PB can also trigger SOQL isuse , is that true? 

Can anyone guide me how I can fix SOQL issues? 

Any help would be much appreciated. 

Thanks!
 
Hi Team,

Could you please help me in migrating below Trigger to Flow/PB if that is possible -


trigger limitCreationsFromZoominfo on Contact (before insert) {
//This trigger limit to 25 the number of contacts that can be created from Zoominfo per person per month (#7692)
//We can detect that the Contact comes from Zoominfo because: LeadSource = "Zoominfo"
//We need to filter the existing contacts (for the count operation) using the fields: 
//  CreatedBy = <same user> 
//  CreatedDate = <in the last 30 days> 
//  LeadOrigin = "Zoominfo"
    
    
//  Users with roles "System Administrator", "Denodo Systems Integration" or "Operations Supervisor" should not be affected by this rule.
    Id profileId = UserInfo.getProfileId();
    String profileName=[Select Id, Name from Profile where Id=:profileId].Name; 
    if ( !profileName.contains('Operations Supervisor') && !profileName.contains('System Administrator') 
            && !profileName.contains('Denodo Systems Integration')){
            
            String userId = UserInfo.getUserId();
            Datetime limitDate = System.now().addDays(-30);                            
            List<Contact> contactsToInsertFromZoominfo = new List<Contact>();
            for(Contact contactToInsert : System.Trigger.new){
                if (contactToInsert.LeadSource == 'Zoominfo'){
                    contactsToInsertFromZoominfo.add(contactToInsert);
                }
            }
            //if there are insertions from Zoominfo, check the limit
            if (contactsToInsertFromZoominfo.size() > 0) {
                List<AggregateResult> currentContactsZoominfo = [SELECT Count(Id) currentContacts FROM Contact 
                                      WHERE Lead_Origin__c ='Zoominfo' and CreatedDate >= :limitDate and CreatedById = :userId];
                for (Contact contactToInsert : contactsToInsertFromZoominfo) {
                    if ( (Integer.valueOf(currentContactsZoominfo.get(0).get('currentContacts')) + contactsToInsertFromZoominfo.size()) > 25 ){
                        contactToInsert.addError('You can not import more than 25 contacts from Zoominfo in 30 days.');                        
                    }   
                }
                             
            }    
            
     }
    
      
}

Basically, this trigger is to restrict specific profile to import contacts from Zoominfo to SFDC if number exceeds 25 in a month. 

Any help would be much appreciated.

Thanks!
 
 

Hi All,

I am not a developer and I am trying to copy one existing trigger and test class from the Org and while running the Test Class getting below error- 

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, State/Province is required for Australia, United States and Canada.: []

I even have included the BillingState in the Account creation to so that validation rule do not trigger. But still no luck. Can anyone help me in reviewing the below codes? 

APEX Trigger-
trigger limitCreationsFromZoominfo on Contact (before insert) {
//This trigger limit to 25 the number of contacts that can be created from Zoominfo per person per month (#33899)
//We can detect that the Contact comes from Zoominfo because: LeadSource = "Zoominfo"
//We need to filter the existing contacts (for the count operation) using the fields: 
//  CreatedBy = <same user> 
//  CreatedDate = <in the last 30 days> 
//  LeadOrigin = "Zoominfo"
    
    
//  Users with roles "System Administrator", "Denodo Systems Integration" or "Operations Supervisor" should not be affected by this rule.
    Id profileId = UserInfo.getProfileId();
    String profileName=[Select Id, Name from Profile where Id=:profileId].Name; 
    if ( !profileName.contains('Operations Supervisor') && !profileName.contains('System Administrator') 
            && !profileName.contains('Denodo Systems Integration')){
            
            String userId = UserInfo.getUserId();
            Datetime limitDate = System.now().addDays(-30);                            
            List<Contact> contactsToInsertFromZoominfo = new List<Contact>();
            for(Contact contactToInsert : System.Trigger.new){
                if (contactToInsert.LeadSource == 'Zoominfo'){
                    contactsToInsertFromZoominfo.add(contactToInsert);
                }
            }
            //if there are insertions from Zoominfo, check the limit
            if (contactsToInsertFromZoominfo.size() > 0) {
                List<AggregateResult> currentContactsZoominfo = [SELECT Count(Id) currentContacts FROM Contact 
                                      WHERE Lead_Origin__c ='Zoominfo' and CreatedDate >= :limitDate and CreatedById = :userId];
                for (Contact contactToInsert : contactsToInsertFromZoominfo) {
                    if ( (Integer.valueOf(currentContactsZoominfo.get(0).get('currentContacts')) + contactsToInsertFromZoominfo.size()) > 25 ){
                        contactToInsert.addError('You can not import more than 25 contacts from Zoominfo in 30 days.');                        
                    }   
                }
                             
            }    
            
     }
    
      
}




APEX Class Test -

/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class limitCreationsFromZoominfoTest {
    static testMethod void myUnitTest() {
        Test.startTest();

        Profile pISS = [SELECT Id FROM Profile WHERE Name='Inside Sales Specialist'];               
        User userISS = new User(Alias = 'userISS', UserName='newuserISS@relatedtotest.com', Email = 'test2@relatedtotest.com', 
                             EmailEncodingKey='UTF-8', FirstName = 'testuser2', LastName = 'ISS', ProfileId = pISS.Id,
                             TimeZoneSidKey='America/Los_Angeles',  LocaleSidKey='en_US', LanguageLocaleKey='en_US');           
        insert userIss;

        System.runAs(userISS){
            // Seed the database with some accounts, and make sure they can be bulk inserted successfully.
            Account account1 = new Account(Name = 'Test1RelatedTo Inc.', BillingCountry = 'United States', BillingState = 'California');
            Account[] accts = new Account[] {account1};
            insert accts;
            
            List<Contact> contacts = new List<Contact>();
            for (Integer i =0 ; i < 26; i++){
                String emailc = 'test' + i + '@relatedtotest.com';
                contacts.add(new Contact(LastName='Test1', AccountId=account1.Id, Email=emailc, MailingCountry = 'United States', MailingState = 'California', LeadSource='Zoominfo'));
            }
            contacts.add(new Contact(LastName='Test4', AccountId=account1.Id, Email='testa@relatedtotest.com', MailingCountry = 'United States', MailingState = 'California', LeadSource='Other'));
            contacts.add(new Contact(LastName='Test5', AccountId=account1.Id, Email='testb@relatedtotest.com', MailingCountry = 'United States', MailingState = 'California', LeadSource='Web'));
            
            try{
                insert contacts;  
                System.assert(false);
            } catch (DmlException e) {     
                System.assert(e.getNumDml() == 101); 
                System.assert(e.getDmlMessage(0).contains('You can not import more than 25 contacts from Zoominfo in 30 days.'));               
            }
                                  
        }
                    
                             
        Test.stopTest();
    }       
}

 

Any help would be much appreciated. 

Hi Team,

The Territory Name not being auto-updated on Opportunity from Account in Sandbox and Production.

Ideally, when new Opportunity is created , it should automatically be assigned with the Territory Name from the Account also if 'Run Opportunity Filter' button is being used on Territory Model, it should update the Territory Name on Opportunity but that is something not happening. Details given below - 
  1. Territory Name is not automatically updated on the newly created Opportunities in both Production and Sandbox.
  2. ‘Run Opportunity Filter’ button on Territory Model doesn’t assign the Territory Name on the Opportunities in  Production Org but on Sandbox.
PS. We have Enabled Filter-Based Opportunity Territory Assignment and using the name OppTerritoryAssignDefaultLogicFilter and below is the code used in both orgs-

/*** Apex version of the default logic.
* If opportunity's assigned account is assigned to
*  Case 1: 0 territories in active model
*            then set territory2Id = null
*  Case 2: 1 territory in active model
*            then set territory2Id = account's territory2Id
*  Case 3: 2 or more territories in active model
*            then set territory2Id = account's territory2Id that is of highest priority.
*            But if multiple territories have same highest priority, then set territory2Id = null 
*/
global class OppTerritoryAssignDefaultLogicFilter implements TerritoryMgmt.OpportunityTerritory2AssignmentFilter { 
    /**
     * No-arg constructor.
     */ 
     global OppTerritoryAssignDefaultLogicFilter() {}

     /**
      * Get mapping of opportunity to territory2Id. The incoming list of opportunityIds contains only those with IsExcludedFromTerritory2Filter=false.
      * If territory2Id = null in result map, clear the opportunity.territory2Id if set.
      * If opportunity is not present in result map, its territory2Id remains intact.
      */
    global Map<Id,Id> getOpportunityTerritory2Assignments(List<Id> opportunityIds) { 
        Map<Id, Id> OppIdTerritoryIdResult = new Map<Id, Id>();

        // Get the active territory model Id
        Id activeModelId = getActiveModelId();

        if(activeModelId != null){
            List<Opportunity> opportunities =
              [Select Id, AccountId, Territory2Id from Opportunity where Id IN :opportunityIds];
            Set<Id> accountIds = new Set<Id>();
            // Create set of parent accountIds
            for(Opportunity opp:opportunities){
                if(opp.AccountId != null){
                    accountIds.add(opp.AccountId);
                    }
                }

                Map<Id,Territory2Priority> accountMaxPriorityTerritory = getAccountMaxPriorityTerritory(activeModelId, accountIds);

            // For each opportunity, assign the highest priority territory if there is no conflict, else assign null.
            for(Opportunity opp: opportunities){
               Territory2Priority tp = accountMaxPriorityTerritory.get(opp.AccountId);
               // Assign highest priority territory if there is only 1.
              if((tp != null) && (tp.moreTerritoriesAtPriority == false) && (tp.territory2Id != opp.Territory2Id)){
                   OppIdTerritoryIdResult.put(opp.Id, tp.territory2Id);
               }else{
                   OppIdTerritoryIdResult.put(opp.Id, null);
               }
            }
        }
        return OppIdTerritoryIdResult;
    }
    
    /**
      * Query assigned territoryIds in active model for given accountIds.
      * Create a map of accountId to max priority territory.
      */
     @TestVisible private Map<Id,Territory2Priority> getAccountMaxPriorityTerritory(Id activeModelId, Set<Id> accountIds){
        Map<Id,Territory2Priority> accountMaxPriorityTerritory = new Map<Id,Territory2Priority>();
        for(ObjectTerritory2Association ota:[Select ObjectId, Territory2Id, Territory2.Territory2Type.Priority from ObjectTerritory2Association where objectId IN :accountIds and Territory2.Territory2ModelId = :activeModelId]){
            Territory2Priority tp = accountMaxPriorityTerritory.get(ota.ObjectId);

            if((tp == null) || (ota.Territory2.Territory2Type.Priority > tp.priority)){
                // If this is the first territory examined for account or it has greater priority than current highest priority territory, then set this as new highest priority territory.
                tp = new Territory2Priority(ota.Territory2Id,ota.Territory2.Territory2Type.priority,false);
            }else if(ota.Territory2.Territory2Type.priority == tp.priority){
                // The priority of current highest territory is same as this, so set moreTerritoriesAtPriority to indicate multiple highest priority territories seen so far.
                tp.moreTerritoriesAtPriority = true;
            }
            
            accountMaxPriorityTerritory.put(ota.ObjectId, tp);
        }
        return accountMaxPriorityTerritory;
    }


    /**
     * Get the Id of the Active Territory Model.
     * If none exists, return null.
     */
    @TestVisible private Id getActiveModelId() {
        List<Territory2Model> models = [Select Id from Territory2Model where State = 'Active'];
        Id activeModelId = null;
        if(models.size() == 1){
            activeModelId = models.get(0).Id;
        }

        return activeModelId;
    }

    /**
    * Helper class to help capture territory2Id, its priority, and whether there are more territories with same priority assigned to the account.
    */
    @TestVisible private class Territory2Priority {
        public Id territory2Id { get; set; }
        public Integer priority { get; set; }
        public Boolean moreTerritoriesAtPriority { get; set; }
        
        @TestVisible
        Territory2Priority(Id territory2Id, Integer priority, Boolean moreTerritoriesAtPriority){
            this.territory2Id = territory2Id;
            this.priority = priority;
            this.moreTerritoriesAtPriority = moreTerritoriesAtPriority;
        }
    }
}

Can anyone help me out here please?

Thanks!
Hi All, 

I am getting the error as below while contracting the Opportunity -

SBQQ.OpportunityAfter: execution of AfterUpdate caused by: System.QueryException : duplicate field selected: SBQQ__Status__c(SBQQ) No record updated

and not sure how to resolve this. 

Any help would be much appreaciated. 

Thanks!
 

Hi All,

I am not a developer and I am trying to copy one existing trigger and test class from the Org and while running the Test Class getting below error- 

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, State/Province is required for Australia, United States and Canada.: []

I even have included the BillingState in the Account creation to so that validation rule do not trigger. But still no luck. Can anyone help me in reviewing the below codes? 

APEX Trigger-
trigger limitCreationsFromZoominfo on Contact (before insert) {
//This trigger limit to 25 the number of contacts that can be created from Zoominfo per person per month (#33899)
//We can detect that the Contact comes from Zoominfo because: LeadSource = "Zoominfo"
//We need to filter the existing contacts (for the count operation) using the fields: 
//  CreatedBy = <same user> 
//  CreatedDate = <in the last 30 days> 
//  LeadOrigin = "Zoominfo"
    
    
//  Users with roles "System Administrator", "Denodo Systems Integration" or "Operations Supervisor" should not be affected by this rule.
    Id profileId = UserInfo.getProfileId();
    String profileName=[Select Id, Name from Profile where Id=:profileId].Name; 
    if ( !profileName.contains('Operations Supervisor') && !profileName.contains('System Administrator') 
            && !profileName.contains('Denodo Systems Integration')){
            
            String userId = UserInfo.getUserId();
            Datetime limitDate = System.now().addDays(-30);                            
            List<Contact> contactsToInsertFromZoominfo = new List<Contact>();
            for(Contact contactToInsert : System.Trigger.new){
                if (contactToInsert.LeadSource == 'Zoominfo'){
                    contactsToInsertFromZoominfo.add(contactToInsert);
                }
            }
            //if there are insertions from Zoominfo, check the limit
            if (contactsToInsertFromZoominfo.size() > 0) {
                List<AggregateResult> currentContactsZoominfo = [SELECT Count(Id) currentContacts FROM Contact 
                                      WHERE Lead_Origin__c ='Zoominfo' and CreatedDate >= :limitDate and CreatedById = :userId];
                for (Contact contactToInsert : contactsToInsertFromZoominfo) {
                    if ( (Integer.valueOf(currentContactsZoominfo.get(0).get('currentContacts')) + contactsToInsertFromZoominfo.size()) > 25 ){
                        contactToInsert.addError('You can not import more than 25 contacts from Zoominfo in 30 days.');                        
                    }   
                }
                             
            }    
            
     }
    
      
}




APEX Class Test -

/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class limitCreationsFromZoominfoTest {
    static testMethod void myUnitTest() {
        Test.startTest();

        Profile pISS = [SELECT Id FROM Profile WHERE Name='Inside Sales Specialist'];               
        User userISS = new User(Alias = 'userISS', UserName='newuserISS@relatedtotest.com', Email = 'test2@relatedtotest.com', 
                             EmailEncodingKey='UTF-8', FirstName = 'testuser2', LastName = 'ISS', ProfileId = pISS.Id,
                             TimeZoneSidKey='America/Los_Angeles',  LocaleSidKey='en_US', LanguageLocaleKey='en_US');           
        insert userIss;

        System.runAs(userISS){
            // Seed the database with some accounts, and make sure they can be bulk inserted successfully.
            Account account1 = new Account(Name = 'Test1RelatedTo Inc.', BillingCountry = 'United States', BillingState = 'California');
            Account[] accts = new Account[] {account1};
            insert accts;
            
            List<Contact> contacts = new List<Contact>();
            for (Integer i =0 ; i < 26; i++){
                String emailc = 'test' + i + '@relatedtotest.com';
                contacts.add(new Contact(LastName='Test1', AccountId=account1.Id, Email=emailc, MailingCountry = 'United States', MailingState = 'California', LeadSource='Zoominfo'));
            }
            contacts.add(new Contact(LastName='Test4', AccountId=account1.Id, Email='testa@relatedtotest.com', MailingCountry = 'United States', MailingState = 'California', LeadSource='Other'));
            contacts.add(new Contact(LastName='Test5', AccountId=account1.Id, Email='testb@relatedtotest.com', MailingCountry = 'United States', MailingState = 'California', LeadSource='Web'));
            
            try{
                insert contacts;  
                System.assert(false);
            } catch (DmlException e) {     
                System.assert(e.getNumDml() == 101); 
                System.assert(e.getDmlMessage(0).contains('You can not import more than 25 contacts from Zoominfo in 30 days.'));               
            }
                                  
        }
                    
                             
        Test.stopTest();
    }       
}

 

Any help would be much appreciated. 

I received 100+ error emails overnight that all look a bit like what I've copied/pasted below. I'm not a developer and am trying to figure out how to fix this. Luckily it's in our Partial Sandbox, so is not affecting our Production org but still, would like to get to the bottom of it. From what I've read, a duplicate field error like this means there are fields with identical API names and the query errors out essentially not knowing which one to use/reference. I do see fields with the label "Amount" with identical APIs but nothing that has changed or been added in the last couple days, which makes me think why would this error suddenly come up now. Where do I find the query? How do I identify which Amount field it's looking for? And where/how do I update the query to fix this?

Error Type: System.QueryException
Error Date: 2019-12-13 04:15:20
Message: "npsp__Largest_Soft_Credit_Date__c,npo02__LastOppAmount__c,npo02__LastCloseDate__c,npo02__LastMembershipAmount__c
^
ERROR at Row:1:Column:350
duplicate field selected: Amount

Rollups State:"
Context: CRLP.ContactSoftCredit

Stack Trace:
No stacktrace available at the time of saving the record. (npsp)
I have a Email Template Name ,Subject name but i am not able to find that Email Alert to stop . I have checket with those email template name  in Email Alerts also but i could not find it.

Please help me
I want to have a read-only look-up field in my instance of Salesforce. However, whenever I build one, they either seem to be invisible to all, or editable.
 
I want a Read-Only Look-up field is so I can update it later using some behind-the-scenes APEX coding as part of the sales & contracting process. I just don't want people to be putting information in that field before they're supposed to.
 
Does anybody know if Salesforce doesn't allow for Read-Only Look-ups? I'd understand why.
 
Thanks for your help!
 
Andy
Hi,
As i can see a territory field is there in the Opp level which reflects the assigned territory of the Account, i want to create a similar field in the Contact object which , when created any contact in the Account , it should reflect the assigned territory of the Account .

May i know how it can be achievable ? Territory is a standard object of SF, which seems related to only Account and the related Opps.