• Swaroopa Akula 2
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 4
    Replies
Getting below error while I am inserting Opportunities using dataloader.

ERROR: dlrs_OpportunityTrigger: execution of AfterInsertcaused by: System.QueryException: List has more than 1 row for assignment to SObject()

Below is the trigger code:
/**
 * Auto Generated and Deployed by the Declarative Lookup Rollup Summaries Tool package (dlrs)
 **/
trigger dlrs_OpportunityTrigger on Opportunity
    (before delete, before insert, before update, after delete, after insert, after undelete, after update){
{
    dlrs.RollupService.triggerHandler(Opportunity.SObjectType);
    
  }  
    
   if(trigger.isafter&& trigger.isInsert){
        
        
        
    
    Set<id> oId = new set<id>();
    for(Opportunity opp : trigger.new){
        oId.add(opp.Id);
    }
    
    Opportunity opp = [select Id ,NRR_value__c ,CurrencyIsoCode,RecordTypeId,recordtype.name from Opportunity where ID =: oId];
    system.debug('opp************'+opp);
     
   PriceBookEntry p = [SELECT Id, Product2Id, Product2.Id, Product2.Name, CurrencyIsoCode FROM PriceBookEntry WHERE 
                        Product2Id='01t0J00000IDOpDQAX' and CurrencyIsoCode =: opp.CurrencyIsoCode and Pricebook2Id = '01s0J000002SCKDQA4' LIMIT 1];
    system.debug('p***************'+p);
    
    string recordtypename = Schema.SObjectType.Opportunity.getRecordTypeInfosById().get(opp.recordtypeid).getname();
    system.debug(' recordtypename*************'+recordtypename);
    
    List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
    for(Opportunity op : trigger.new){
        if(opp.RecordType.Name == 'Services Record Type'){
             OpportunityLineItem oli = new OpportunityLineItem();
             oli.OpportunityId = opp.Id;
             oli.Quantity = 1;
             oli.PricebookEntryId = p.Id;
             //oli.name = opp.name;
             
             oli.UnitPrice = opp.NRR_value__c;
             oliList.add(oli);
            system.debug('oliList------------'+oliList);
        }   
     }
     insert oliList;
   
    }
}

Pls let me know what is the issue
Here is my trigger to add a opportunity line item in the oppty.

Set<id> oId = new set<id>();
    for(Opportunity opp : trigger.new){
        oId.add(opp.Id);
    }
    
    Opportunity opp = [select Id ,NRR_value__c ,CurrencyIsoCode,RecordTypeId,recordtype.name from Opportunity where ID =: oId];
    system.debug('opp************'+opp);
     
    PriceBookEntry p = [SELECT Id, Product2Id, Product2.Id, Product2.Name, CurrencyIsoCode FROM PriceBookEntry WHERE 
                        Product2Id='01t3O000003UXKsQAO' and CurrencyIsoCode =: opp.CurrencyIsoCode and Pricebook2Id = '01s0J000002SCKDQA4'];
    system.debug('p***************'+p);
    
    string recordtypename = Schema.SObjectType.Opportunity.getRecordTypeInfosById().get(opp.recordtypeid).getname();
    system.debug(' recordtypename*************'+recordtypename);
    
    List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
    for(Opportunity op : trigger.new){
        if(opp.RecordType.Name == 'Services Record Type'){
             OpportunityLineItem oli = new OpportunityLineItem();
             oli.OpportunityId = opp.Id;
             oli.Quantity = 1;
             oli.PricebookEntryId = p.Id;
             //oli.name = opp.name;
             
             oli.UnitPrice = opp.NRR_value__c;
             oliList.add(oli);
            system.debug('oliList------------'+oliList);
        }   
     }
     insert oliList;



Test class for this trigger:



@isTest(SeeAllData=true)
public class insertopplineitemTest{
    static testMethod void insertopptylineitemTest() {
        Account acct = new Account(Name = 'Celigo testing account',Billingcountry = 'United States');
        insert acct;
       
        //PriceBook Standard
        PriceBook2 stdPBook = [ SELECT Id, IsActive FROM PriceBook2 WHERE IsStandard = True AND IsActive = TRUE LIMIT 1 ];
       
        //Pricebook Custom
        PriceBook2 custPBook = new PriceBook2( Name = 'Test Pricebook',Description = 'Custom Pricebook',CurrencyIsoCode = 'USD',IsActive = TRUE );
        insert custPBook;
       
        //Product
        Product2 prod = new Product2( Name = 'Celigo Test Product',CurrencyIsoCode = 'USD',isActive = TRUE );
        insert prod;
       
        //PriceBookEntry Standard
        PricebookEntry pbEntry1 = new PricebookEntry( Pricebook2Id = stdPBook.Id,Product2Id = prod.id,CurrencyIsoCode = 'USD',IsActive = TRUE );
        pbEntry1.UnitPrice = 100.0;
        pbEntry1.UseStandardPrice = FALSE;
        insert pbEntry1;
           
        PricebookEntry pbEntry2 = new PricebookEntry( Pricebook2Id = custPBook.Id,Product2Id = prod.id,CurrencyIsoCode = 'USD',IsActive = TRUE );
        pbEntry2.UnitPrice = 200.0;
        pbEntry2.UseStandardPrice = FALSE;
        insert pbEntry2;
       
        
        // Opportunity
        Opportunity oppy = new Opportunity( Name = 'Celigo Test Opportunity',AccountId = acct.Id,CurrencyIsoCode = 'USD',NRR_value__c=100);
        
        //oppy.RecordTypeId=Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('Services_Record_Type').getRecordTypeId();
        oppy.StageName = '0 - Meeting';
        oppy.CloseDate = System.Today()+10;
     
        insert oppy;
           
        // OpportunityLineItem
        OpportunityLineItem opItem1 = new OpportunityLineItem(OpportunityId = oppy.Id, PricebookEntryId = pbEntry1.id);
        opItem1.UnitPrice = 100;
        opItem1.Quantity = 10;
        
        
        insert opItem1;
      
      Test class is passing but I am not able to get code coverage more than 75%. Whatelse we can add in the test class to get more code coverage? 
Hi,

I have 'product family' field on the quote line items. On quote I need to populate the 'product family' field from quote line items and this field can contains multiple values.

Example: product family- product family1
                                         product family2
                                         product family3

quoteline item1 has product family1
quoteline item2 has product family2
quoteline item3 has product family3

In the quote if all the above quoteline items were added, In the 'product family' on quote it should have the all values(product family1,product family2,product family3). How can we achieve this problem?


 
Here is the code for auto populate account on lead when the email domain match. Can pls someone let me know test class for this class

public static void handleBeforUpdate() 
    {
        Set<String> leadEmails = new Set<String>();
        Map<String,Id> conmap = new Map<String,Id>();
        List<Lead> vLstLead = new List<Lead>();

    for(Lead l :(List<Lead>)trigger.new){

        if(!l.IsConverted && null != l.email && '' != l.email)
            leadEmails.add(l.Lead_s_email_domain__c);
    }

    Set<String> contactEmailMatches = new Set<String>();
    
    List<Contact> conList = [SELECT Id,Accountid,Email,Contact_s_email_domain__c From Contact where Contact_s_email_domain__c IN :leadEmails];
   
    if(conList != null) {
    for(Contact c : conList) {
        contactEmailMatches.add(c.Contact_s_email_domain__c);
        conmap.put(c.Contact_s_email_domain__c, c.accountId);
       }
    }
  

    for(Lead l :(List<Lead>)trigger.new){

        if(!l.IsConverted){
         if(contactEmailMatches.contains(l.Lead_s_email_domain__c) && !l.is_domain_matched__c){
                l.is_domain_matched__c = True;
                l.AccountName__c = conmap.get(l.Lead_s_email_domain__c);
             }
            }
        }
    }

}
I need to convert the leads automatically if the lead email domain matches to contact email domain. Please letme know how can i do this
I am having process builder error for the auto milestone completion. 
entitlement exit criteria i kept based on case closed date

flow tried to update these records: null. This error occurred: FIELD_INTEGRITY_EXCEPTION: You can’t change the completion date on a milestone that’s already exited an entitlement process.: Completion Date
I have a trigger and handler which is used to get the auto entitlement name select in the case.

Here is the code. Please help me on why i am having process delay issues. Thanks in advance!

Trigger:


trigger CaseUpdatedTrigger on Case (before insert, before update) {
       
    if(trigger.isBefore){
        
        if(trigger.isInsert){
        
        CaseUpdatedTriggerHandler.handleBeforInsert(trigger.new);
        }
        
        if(trigger.isUpdate){
       
         CaseUpdatedTriggerHandler.handleBeforUpdate(trigger.new);
        }
        
    }
}

Handler:

public class CaseUpdatedTriggerHandler {
    
    public static void handleBeforInsert(List<Case> newCaseList){
        getCaseEntilementID(newCaseList);  
    }
    
    public static void handleBeforUpdate(List<Case> newCaseList){
        getCaseEntilementID(newCaseList);
    }
    
    //Helper method to get EntilementID based on case priority
    private Static void getCaseEntilementID(List<Case> caseList){
        
        Set<Id> acctIds = new Set<Id>();
        for (Case c : caseList) {
            acctIds.add(c.AccountId);
        }
        
        List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, 
                    e.AccountId
                    From Entitlement e
                    Where e.AccountId in :acctIds AND e.StartDate <= Today];                  
        if(entls.isEmpty()==false){
            for(Case c : caseList){
               if(c.EntitlementId == null && c.AccountId != null){
                    for(Entitlement e:entls){
                       if(e.AccountId==c.AccountId){
                            // entilementID = e.Id;
                            c.EntitlementId  = e.Id; 
                            break;
                        }
                    } 
                }
            } 
        }
    }
}
Hi I have written a trigger to get autopopulate  the entitlement name(Look up field on case) on case when the time of case creation. 

One account has 2 entitlement processes. 
trigger EntitlementAssign on Case (before insert) {
 Set<Id> accountIds = new Set<Id>();
    for (Case c : Trigger.new) {
        accountIds.add(c.AccountId);
    }
    accountIds.remove(null);
    if (!accountIds.isEmpty()) {
        Map<Id, Entitlement> entitlementMap = new Map<Id, Entitlement>();
         for (Entitlement e : [select AccountId,Name from Entitlement where AccountId in :accountIds]) {
            entitlementMap.put(e.AccountId, e);
        }

        Entitlement process = [select Name from Entitlement where Name = 'Entitlement Process Name'];
            List<Entitlement> entitlementsToInsert = new List<Entitlement>();
            for (Id id : accountIds) {
                if (entitlementMap.containsKey(id)) {
                continue;
        }
            entitlementsToInsert.add(new Entitlement(Name = 'Entitlement Name',SlaProcessId = process.Id,
                StartDate = Date.today().addDays(-1), // Start date of yesterday
                Enddate = Date.today().addDays(1), // End date of tomorrow
                AccountId = id ));
        }

        if (!entitlementsToInsert.isEmpty()) {
            insert entitlementsToInsert;
            for (Entitlement e : entitlementsToInsert) {
                entitlementMap.put(e.AccountId, e);
            }
        }
 
        for (Case c : Trigger.new) {

            if (c.AccountId == null) {
                continue;

            }

            c.EntitlementId = entitlementMap.get(c.AccountId).Id;
        }
    }

}
I am having process builder error for the auto milestone completion. 
entitlement exit criteria i kept based on case closed date

flow tried to update these records: null. This error occurred: FIELD_INTEGRITY_EXCEPTION: You can’t change the completion date on a milestone that’s already exited an entitlement process.: Completion Date
Here is my trigger to add a opportunity line item in the oppty.

Set<id> oId = new set<id>();
    for(Opportunity opp : trigger.new){
        oId.add(opp.Id);
    }
    
    Opportunity opp = [select Id ,NRR_value__c ,CurrencyIsoCode,RecordTypeId,recordtype.name from Opportunity where ID =: oId];
    system.debug('opp************'+opp);
     
    PriceBookEntry p = [SELECT Id, Product2Id, Product2.Id, Product2.Name, CurrencyIsoCode FROM PriceBookEntry WHERE 
                        Product2Id='01t3O000003UXKsQAO' and CurrencyIsoCode =: opp.CurrencyIsoCode and Pricebook2Id = '01s0J000002SCKDQA4'];
    system.debug('p***************'+p);
    
    string recordtypename = Schema.SObjectType.Opportunity.getRecordTypeInfosById().get(opp.recordtypeid).getname();
    system.debug(' recordtypename*************'+recordtypename);
    
    List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
    for(Opportunity op : trigger.new){
        if(opp.RecordType.Name == 'Services Record Type'){
             OpportunityLineItem oli = new OpportunityLineItem();
             oli.OpportunityId = opp.Id;
             oli.Quantity = 1;
             oli.PricebookEntryId = p.Id;
             //oli.name = opp.name;
             
             oli.UnitPrice = opp.NRR_value__c;
             oliList.add(oli);
            system.debug('oliList------------'+oliList);
        }   
     }
     insert oliList;



Test class for this trigger:



@isTest(SeeAllData=true)
public class insertopplineitemTest{
    static testMethod void insertopptylineitemTest() {
        Account acct = new Account(Name = 'Celigo testing account',Billingcountry = 'United States');
        insert acct;
       
        //PriceBook Standard
        PriceBook2 stdPBook = [ SELECT Id, IsActive FROM PriceBook2 WHERE IsStandard = True AND IsActive = TRUE LIMIT 1 ];
       
        //Pricebook Custom
        PriceBook2 custPBook = new PriceBook2( Name = 'Test Pricebook',Description = 'Custom Pricebook',CurrencyIsoCode = 'USD',IsActive = TRUE );
        insert custPBook;
       
        //Product
        Product2 prod = new Product2( Name = 'Celigo Test Product',CurrencyIsoCode = 'USD',isActive = TRUE );
        insert prod;
       
        //PriceBookEntry Standard
        PricebookEntry pbEntry1 = new PricebookEntry( Pricebook2Id = stdPBook.Id,Product2Id = prod.id,CurrencyIsoCode = 'USD',IsActive = TRUE );
        pbEntry1.UnitPrice = 100.0;
        pbEntry1.UseStandardPrice = FALSE;
        insert pbEntry1;
           
        PricebookEntry pbEntry2 = new PricebookEntry( Pricebook2Id = custPBook.Id,Product2Id = prod.id,CurrencyIsoCode = 'USD',IsActive = TRUE );
        pbEntry2.UnitPrice = 200.0;
        pbEntry2.UseStandardPrice = FALSE;
        insert pbEntry2;
       
        
        // Opportunity
        Opportunity oppy = new Opportunity( Name = 'Celigo Test Opportunity',AccountId = acct.Id,CurrencyIsoCode = 'USD',NRR_value__c=100);
        
        //oppy.RecordTypeId=Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('Services_Record_Type').getRecordTypeId();
        oppy.StageName = '0 - Meeting';
        oppy.CloseDate = System.Today()+10;
     
        insert oppy;
           
        // OpportunityLineItem
        OpportunityLineItem opItem1 = new OpportunityLineItem(OpportunityId = oppy.Id, PricebookEntryId = pbEntry1.id);
        opItem1.UnitPrice = 100;
        opItem1.Quantity = 10;
        
        
        insert opItem1;
      
      Test class is passing but I am not able to get code coverage more than 75%. Whatelse we can add in the test class to get more code coverage? 
Hi I have written a trigger to get autopopulate  the entitlement name(Look up field on case) on case when the time of case creation. 

One account has 2 entitlement processes. 
trigger EntitlementAssign on Case (before insert) {
 Set<Id> accountIds = new Set<Id>();
    for (Case c : Trigger.new) {
        accountIds.add(c.AccountId);
    }
    accountIds.remove(null);
    if (!accountIds.isEmpty()) {
        Map<Id, Entitlement> entitlementMap = new Map<Id, Entitlement>();
         for (Entitlement e : [select AccountId,Name from Entitlement where AccountId in :accountIds]) {
            entitlementMap.put(e.AccountId, e);
        }

        Entitlement process = [select Name from Entitlement where Name = 'Entitlement Process Name'];
            List<Entitlement> entitlementsToInsert = new List<Entitlement>();
            for (Id id : accountIds) {
                if (entitlementMap.containsKey(id)) {
                continue;
        }
            entitlementsToInsert.add(new Entitlement(Name = 'Entitlement Name',SlaProcessId = process.Id,
                StartDate = Date.today().addDays(-1), // Start date of yesterday
                Enddate = Date.today().addDays(1), // End date of tomorrow
                AccountId = id ));
        }

        if (!entitlementsToInsert.isEmpty()) {
            insert entitlementsToInsert;
            for (Entitlement e : entitlementsToInsert) {
                entitlementMap.put(e.AccountId, e);
            }
        }
 
        for (Case c : Trigger.new) {

            if (c.AccountId == null) {
                continue;

            }

            c.EntitlementId = entitlementMap.get(c.AccountId).Id;
        }
    }

}
I have implemented web-to-case + entitlements / service contracts and an entitlement process.
How can I automatically create and assign an entitlement to a case? I now have to do it manually and only then does it trigger the entitlement process with the relevant processes. In my use case it concerns a case that needs to be picked up after 60 minutes when it is in the queue. I can assign an escalation rule but I would rather work with an entitlement process as you can add other milestones in the process to resolve the case according to SLA settings.