• davidjgriff
  • NEWBIE
  • 140 Points
  • Member since 2013
  • Salesforce Wizard Extraordinaire
  • Hyland Software

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 55
    Replies

Hi,

 

I am trying to modify one of my test methods to make sure that it complies with some validation rules I recently created.  I also added a lookup filter on the Decision_Maker__c field (lookup on the Contact) so users can only look up Contact that are related to Account that Opportunity is related to.  So if Account A had two contacts, if I create an Opportunity and want to add the Decision Maker field, I only want to be able to find the two contact that Account A has in the lookup filter.  Here's my logic for the filter:

 

Decision Maker: Account ID equals Field Opportunity: Account ID (required filter)

 

This is the error that I am getting:

 

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [Decision_Maker__c]

 

I'm confused because I am pretty sure the Contact that I create in the Unit Test is related the Account I create.  Then the Opportunity I create is related to the Account, so I'm confused on why it's tripping up the error since I related everything together on the original Account.

 

 

 

public static testMethod void TestCreateActualsAndTargets_Trigger(){
    
        Account l_oAccount = new Account(Name='TestAccount', Type='Eligible');
        insert l_oAccount;
        
        User testUser = TestFactory.buildTestASUser(0, 'Standard User');
        insert testUser;
        
        Contact testContact = new Contact ();
        testContact.FirstName='Testo';
        testContact.LastName='Westo';
        testContact.Account=l_oAccount;
        insert testContact;
        
        Opportunity l_oOpportunity = new Opportunity();
        l_oOpportunity.Name='Test Opportunity';
        l_oOpportunity.Type = 'New Ad Sales';
        l_oOpportunity.CloseDate=System.today();
        l_oOpportunity.StageName='Closed/Won';
        l_oOpportunity.AccountId=l_oAccount.Id;
        l_oOpportunity.ForecastCategoryName='Pipeline';
        l_oOpportunity.Contract_ID__c = '123173';
        l_oOpportunity.Multiple_Contract_IDs_at_Close__c = 'No - I have one single Contract';
        l_oOpportunity.Split__c = '50/50';
        l_oOpportunity.User__c = testUser.Id;
        l_oOpportunity.Report_Generation_Tools_Reviewed_withSP__c = 'Yes';
        l_oOpportunity.Personality_of_ServiceProvider__c = 'Yes';
        l_oOpportunity.SPs_Expectations__c = 'Yes';
        l_oOpportunity.Why_We_Gave_SpecialPricing__c = 'Yes';
        l_oOpportunity.UpsellOpportunities__c = 'Yes';
        l_oOpportunity.Advertising_Contact__c = testContact.Id;
        l_oOpportunity.SP_knows_grade_and_current_revie__c = 'Yes';
        l_oOpportunity.Decision_Maker__c = testContact.Id;
        l_oOpportunity.SP_verbally_agreed_to_specific_coupon__c = 'Yes';
        l_oOpportunity.Length_of_SalesCycle__c = 'Within a Week';
        insert l_oOpportunity;   
    }

 

I'm trying to write a test class for a trigger that performs a new record insertion. The trigger is before update, and will insert a record on an associate object. When writing the test class, I am getting this error:

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateOnboardingRecord: execution of BeforeUpdate

caused by: System.DmlException: Insert failed. First exception on row 0 with id 00Tc0000004Q0dqEAC; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

Class.CreateOnboardingFromApplication.createOnboard: line 121, column 1
Trigger.CreateOnboardingRecord: line 7, column 1: []

 

 Any idea where I may be going wrong?

 

Thanks!

Hello!

 

I created a Visualforce page that have a Custom Object as a standardController. In that page I get one field from the Object and that field have a Validation rule. My question is:

 

How can I get the error message and display it in my own vf page?

 

'Cause when the Validation is activated, it shows a long and confusing (in the user point of view) message in the whole page. I'd like to show just a message in the Top of the page.

 

 Thanks!

 

Life Is Too Short to Remove USB Safely

I'm trying to capture the new and old contact Account names into string fields for string comparrison, and sending in an email.  The code below is a test trigger on a contact record.  The email sent to me after changing the contact's account to another give me values of null.  If I do this, for example, with the c.Title field I don't have this issue, I can pull the value into a string.

 

The email message: "Account field changed: Old Account: null New Account null"

 

Thanks for any help.

 

Kevin

================

 

The trigger:

 

trigger EmailAccountName on Contact (after update) {

string OldAccount;

string NewAccount;

 

for (Contact c : Trigger.old) {

          OldAccount = c.account.name;

}

 

for (Contact c : Trigger.new) {

          NewAccount = c.account.name;

}

 

            // Send Email Notification

            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

            String[] toAddresses = new String[] {'my email address'};

            mail.setToAddresses(toAddresses);

            mail.setReplyTo('my email address');

            mail.setSenderDisplayName('Me');

            mail.setSubject('Alumni Contact Information has changed.');

            mail.setBccSender(false);

            mail.setUseSignature(false);

            mail.setHtmlBody('Account field changed: Old Account: ' + OldAccount + ' New Account ' + NewAccount );

            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });     

}

It seems that the new Summer'13 update enforces you to work with 18 character ID's always. For example, this happens in apex:

 

Id Id15 = string.valueOf(Id18).substring(0,15);
System.AssertEquals (Id15,Id18);

 

Pre-Summer that assertion fails, as Id15 is the 15 character Id and Id18 is the 18 character Id.
In our custom code many times we use Custom Setting and Custom Labels to avoid hardcoding recordtypes, profiles and other "constant" values. We usually worked with 15 character Ids as Salesforce (SOQL) sometimes returns 15 and other times returns 18 character Ids.

 

Now it seems the ID type always returns 18 character, if you do something like this the assertion is true:

 

Id Id15 = '012200000005byN';
System.AssertEquals (Id15,'012200000005byNAAQ');

 

As this is happening now with the Summer'13 but not happening before with Spring'13, this invalidates many coding.

We found this problem as Salesforce triggered a deep system error like this Salesforce System Error: 1619326252-34083 (1564369920) (1564369920) trying to compare a SelectOption loaded with record types with a Custom Settings String Id Stored.

 

This is a really weird annoyance. You can take a workaround working always with ID type instead of storing Ids into Strings, and always working with 18 character Ids, wether you hardcode Ids into apex and formulas (not a good approach) or you use custom setting and labels to store the ids.

 

Hope this helps... I lost all morning trying to figure out this.

I'm deploying an Apex Class from a Dev sandbox to a Full and getting a compile error that I did not get in the Dev sandbox.  The error is Compile Error: Invalid type: SRMapping__c.   Any ideas?

 

Here's the first part of the code:

public with sharing class oppProductFieldSelExtension {
   //List that holds all Selection Items
    public List<ExtendedProduct> selection {get;set;}
        public List<ProdOppLineWrapper> oppSelections{get; set;}
        public List<OpportunityLineItem> existingItems {get; set;}
        public String oppID {get; set;}
        public Opportunity oppRec {get; set;}
        public ProductsIDTracker__c prodTracker {get; set;}
        public List<PriceBookEntry> prodPriceBkList {get; set;}
        public List<String> productIDs{get; set;}
        public List<String> prodPriceBkIDs{get; set;}
        //public list<selectOption> sensor_Resolution {get;set;}      
    //soql string without the order and limit      
    private String soql {get;set;}
    //the collection of products to display
    public List<ExtendedProduct> products {get;set;}
    //Product Family list
    private List<String> productFamilies;
    //String to hold selected Family
    private String selectedFamily;
    //Pricebook to look at
    private list<Pricebook2> pricebook;
    //Map of Field Names and Description of that field
    Map<String,Schema.SObjectField> fields;
    private String selectedField;
    private String selectedOperator;
    private String fieldSearch;
    private String quickSearch;   
    public List<selectOption> resolutionList {get;set;}
    //public String sensorKeys {get; set;}
   
    //public String sensor {get;set;}
   
    public map<String, SRMapping__c> mapResolution1 {get;set;}   
   
         public String getselectedOperator()
        {
                return this.selectedOperator;
        }
        public void setselectedOperator(String s)
        {
                this.selectedOperator = s;
        }

Guys, i'm pretty new to apex and development on Salesforce, I'm trying to build a trigger where it populates the field Fase_Ciclo_vida__c on lead with current the stagename on Opportunity.

 

Anything i'm missing?

 

 

trigger OpportunityAfter on Opportunity (after insert, after update) {
    
    if (LibCommonFunctions.isTriggerStatusActive()) {
        
        if (trigger.isUpdate) {
            
            if (trigger.new.size() == 1) {
                
                if (trigger.new[0].IsWon) {
                    
                    Opportunity ls = [Select Id, StageName from Opportunity where IsWon=True];
                    
                    if (trigger.new[0].ConvertedOpportunityId != null) {
                        
                        Lead o = [Select Id From Lead Where Id =: trigger.new[0].Id];
                        o.Fase_Ciclo_de_vida__c = ls.Stagename;
                        update o;
                        
                    }
                    
                }
                
            }
            
        }
        
    }

}

 

<apex:page controller="AccountExample1" showHeader="true" action="{!ActionToDo}">
    <apex:form >
        <apex:sectionHeader title="New Account" subtitle="Edit Account" />
        
        <apex:pageBlock title="Account Edit" mode="Edit">
            
                <apex:pageBlockSection title="Account Information">
                    <apex:outputField value="{!acc.ownerID}"/>
                    <apex:inputField value="{!acc.Rating}"/>
                    <apex:inputField value="{!acc.Name}"/>
                    <apex:inputField value="{!acc.Phone}"/>
                    <!--<apex:inputField value="{!acc.Parent}"/>-->
                    <apex:inputField value="{!acc.Fax}"/>
                    <apex:inputField value="{!acc.AccountNumber}"/>
                    <apex:inputField value="{!acc.Website}"/>
                    <apex:inputField value="{!acc.Site}"/>
                    <apex:inputField value="{!acc.TickerSymbol}"/>
                    <apex:inputfield value="{!acc.Type}"/>
                    <apex:inputField value="{!acc.OwnerShip}"/>
                    <apex:inputField value="{!acc.Industry}"/>
                    <apex:inputfield value="{!acc.NumberOfEmployees}"/>
                    <apex:inputfield value="{!acc.AnnualRevenue}"/>
                    <apex:inputField value="{!acc.sic}"/>
                    <apex:inputField value="{!acc.Account_Email__c}" />
                    <apex:inputField value="{!acc.Count_Contacts__c}"/>
                    
                </apex:pageBlockSection>     
                <apex:pageBlockSection title="Account Information" >
                    <apex:inputTextarea value="{!acc.BillingStreet}"/>
                    <apex:inputTextarea value="{!acc.ShippingStreet}"/>
                    <apex:inputField value="{!acc.BillingCity}"/>
                    <apex:inputField value="{!acc.ShippingCity}"/>
                    <apex:inputfield value="{!acc.BillingState}"/>
                    <apex:inputField value="{!acc.ShippingState}"/>
                    <!--<apex:inputField  value="{!acc.BillingZip}"/>-->
                    <!--<apex:inputField value="{!acc.ShippingZip}"/>-->
                    
                
                </apex:pageBlockSection>
            <apex:pageBlockSection title="Account Information">
                <apex:inputfield value="{!acc.CustomerPriority__c}"/>
                <apex:inputField value="{!acc.SLA__c}"/>
                <apex:inputField value="{!acc.SLAExpirationDate__c}"/>
                <apex:inputField value="{!acc.SLASerialNumber__c}"/>
                <apex:inputField value="{!acc.NumberofLocations__c}"/>
                <apex:inputField value="{!acc.UpsellOpportunity__c}"/>
                <apex:inputField value="{!acc.Active__c}"/>
            
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Description Information">
                <apex:inputtextarea value="{!acc.Active__c}"/ >
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!Save}" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    
    </apex:form>
</apex:page>

 

 

 

 

 

public class AccountExample1
{
    public void Save() {
     //acc = new Account();
        insert acc;
    }

    public AccountExample1()
    {
       
        //acclist = [Select * from Account];
    }
    
    public Account acc{set;get;}
    //public List<Account> acclist{set;get;}
    public void ActionToDo()
    {
    }
}

Hi Everyone,

 

I am trying to build a VF Page that will sit in a standard Contact Page Layout.  I know that Account Contact Role relates to Account and there is a related list on Accounts.  What we are looking for is a way to show these Account Contact Roles on the Contact.

 

My best assumption is to create a VF Page that can be added to the standard page layout with a apex class related to the Account Contact Role where the ContactId from the AccountContactRole object is equal to the current Contact Id.

 

The following code is my VF page and Apex Class.  I feel there may already be a solution for this so I am totally open to new suggestions or fixes to my current code and logic.


Thank You Very Much.

 

<apex:page standardcontroller="Contact" recordSetVar="contacts" extensions="AccountContactRoles">
 <apex:pageBlock title="Account Contact Roles">
        <apex:form id="theForm1">
            <apex:pageBlockSection >
                <apex:dataList value="{!AccountContactRoles}" var="acr" type="1">
                    {!acr.Id}
                </apex:dataList>
            </apex:pageBlockSection>
            <apex:panelGrid columns="2">
                <apex:commandLink action="{!previous}">Previous</apex:commandlink>
                <apex:commandLink action="{!next}">Next</apex:commandlink>
            </apex:panelGrid>
        </apex:form> 
    </apex:pageBlock>
</apex:page>

 This is my VF Page Coding

 

public with sharing class AccountContactRoles {
	private final Contact acr;
	public Id cntId{get;set;}
	
	public AccountContactRoles(ApexPages.StandardSetController controller){
		this.acr = (Contact)controller.getRecord();
	}
	public ApexPages.Standardsetcontroller acrRecords{
		get{
			if(acrRecords == null){
				cntId = ApexPages.currentPage().getParameters().get('Id');
				acrRecords = new ApexPages.Standardsetcontroller(
				Database.getQueryLocator([Select Id, AccountId, ContactId, Role, IsPrimary From AccountContactRole 
				Where ContactId=:cntId]));
			}
			return acrRecords;
		}
		private set;
	}
	public List<AccountContactRole> getAccountContactRoles(){
		return (List<AccountContactRole>) acrRecords.getRecords();
	}
}

 This is my Apex Class.

I have an  custom object called "position" .  Now i  want to retrieve only a particular field called status from another object called candidate,which is having many fields. I want to retrieve the status (picklist) field from candidate.

 

I have done with the lookup but i am getting the whole details but what i need is the particular status picklist information in position object

 

 

Thanks in advance....

  • April 01, 2013
  • Like
  • 0

Hi can anyone tell me why i am getting this error for this code? i am at my wits end. I have marked the line where i am getting the error

 

public class FindScope {
  list<list<opportunity>> theList;
  list<String> piclistVals = new list<string>();
  String s;
  list<string> pv;
  list<opportunity> listOfOpp; 
 
  public list<String> getPicklistVals(){
    Schema.DescribeFieldResult fieldResult = opportunity.stageName.getDescribe();
  for(Schema.PicklistEntry f :  fieldResult.getPicklistValues()){
    piclistVals.add(f.getValue());
   
  }
  return piclistVals;
  }
  public list<list<opportunity>> getOpportunities(){
         theList =  new list<list<opportunity>>();
         for(Integer i = 0; i < piclistVals.size(); i++){
         String pvalue = pv[i];  
       listOfOpp = [select id, name, stagename, amount from opportunity where stagename = :pvalue];
       thelist.add(listOfOpp);
         
   }
      return thelist;
  } 
   public list<opportunity> getProspecting(){
     
       oppProspecting = thelist[0];
        list<opportunity> myopp = new list<opportunity>();
         ;     
        return oppProspecting;
    }
     public list<opportunity> getQualification(){
      list<opportunity> oppQualification = new list<opportunity>();
       oppQualification = thelist[0];
        System.debug(oppQualification);       
        return oppQualification;
    }
      public list<opportunity> getNeedsAnalysis(){
      list<opportunity> oppNeedsAnalysis = new list<opportunity>();
       oppNeedsAnalysis = thelist[2];
        return oppNeedsAnalysis;
    } 
     public list<opportunity> getValueProposition(){
      list<opportunity> oppValueProposition = new list<opportunity>();
       oppValueProposition = thelist[3];
        return oppValueProposition;
    }       
    
}

  • March 29, 2013
  • Like
  • 0

Hello,

 

We've reached out limit of Rollups on our Project object. I need to code a roll up manually.

 

My goal is to calculate the total of all billing events per Project and update a field on Project called "Total Invoiced to Date". I'm trying to figure out the suedo code before I begin and would greatly appreciate any info more experienced coders can give. I believe it should look something like

 

trigger trg_RollupBillgEventsToProject on CCI_Invoice__c (after delete, after insert) {
	
	//*********************************
	//CCI_Project__c is parent (record to be updated)
	//CCI_Invoice__c is the roll-up object (counting the total invoiced to date and adding them to the parent record)
	
	//Create a variable to hold the total of billing events associated with the project
	double dblTotalBillingEvents = 0;
	
	//CCI_Project__c is Parent (record to be updated)
	//CCI_Invoice__c is the roll-up object (counting the sum of Total_Invoice_Value__c in all billing events)
	
	//Create a new instance of the Project Object
	CCI_Project__c [] projectToUpdate = new CCI_Project__c[]{};
	
	//******************************
	//New Records
	//******************************
	if(Trigger.isInsert||Trigger.isDelete){
		
		if(Trigger.isInsert){
			
			for(CCI_Invoice__c be: childObjectNew ){

				!!! How would I collect the billing events? !!!!

				dblTotalBillingEvents += be.Total_Invoice_Value__c;
			}

			projectToUpdate.Total_Invoiced_to_date = dblTotalBillingEvents;
		}
	}
}
                   

 Above I'm trying to figure out the insert first, than I'll move on to updates and deletes.

 

Thanks!

I have a class that is this:

 

public with sharing class Constants {
    public static final String NOZZLE = 'Nozzle'; 
    public static final String MANIFOLD = 'Manifold';
    public static final String INLET = 'Inlet';

 

 

I am attempting to write test code for it, test class looks like this:

 

@isTest
private class Test_Constants {

    static testMethod void myUnitTest() {
		Constants con = new Constants();
		System.assertEquals(Constants.ACTUATOR_COST,Constants.ACTUATOR_COST);

 For some reason I'm getting 0 test coverage.  For the Systerm.assert, I tried con. rather than constants. but got an error... Added in a System.Debug in the test as well and the string value for the variable is getting pulled, not sure why Salesforce is reporting 0 coverage.

I want to set the business hours on a Case in Apex, but am having trouble doing it - it appears that Apex lets me say, for example:

 

case.BusinessHours = businessHoursObject;

 

But it doesn't look like it's refelected on the case.  Also, I can't see any references to the BusinessHours field of a Case in the docs, yet it's available in the UI.

 

Has anyone done this?

Hi,

 

I have a trigger that ensures a delivery contact is added to the opportunity. I now want to make the trigger NOT fire when a Finance user edits the opportunity. So somehow I want to add NOT profileId = '00e20000000me3Q'. So that Finance users can go in and change stuff without having to add a delivery contact, but everyone else have to.

 

Where would I add this? Can you use NOT in apex code?

 

 

Here is my trigger:

trigger Opportunity_DeliveryContact_Required on Opportunity (before insert, before update) {

    //map to keep track of the contact_required = 1
    Map<String, Opportunity> oppy_contact = new Map<String, Opportunity>();

    //Trigger.new is an array of opportunities 
    //and adds any that have Contact_Required = 1 to the oppy_contact Map
    for (Integer i = 0; i < Trigger.new.size(); i++) {
        System.debug('*****Required? ' + Trigger.new[i].contact_required__c);
        if  (Trigger.new[i].contact_required__c == 1) {
            oppy_contact.put(Trigger.new[i].id,Trigger.new[i]);
        }
    }

    //map to keep track of the opportunity contact roles
    map<Id, OpportunityContactRole> oppycontactroles = new map<Id, OpportunityContactRole>();

    //select OpportunityContactRoles for the opportunities with contact role required 

    List<OpportunityContactRole> roles = [select OpportunityId, Role from OpportunityContactRole
        where (OpportunityContactRole.Role ='Delivery Contact') and OpportunityContactRole.OpportunityId
        in :oppy_contact.keySet()];


    for (OpportunityContactRole ocr : roles) {
        //puts the contact roles in the map with the Opportunity ID as the key
        oppycontactroles.put(ocr.OpportunityId,ocr);
    }

    // Loop through the opportunities and check if they exists in the contact roles map or contact role isn't required    
String OppRectypeId = [SELECT Id, Name FROM RecordType WHERE Sobjecttype = 'Opportunity' AND Name = 'License Opportunity'].Id;

for (Opportunity oppy : system.trigger.new) 
{
    if(Oppy.RecordTypeId == OppRectypeId)
    {
        if (oppy.contact_required__c ==1 && !oppycontactroles.containsKey(oppy.id))
        {
            oppy.addError('No Delivery Contact exists. Please go to the Contact Roles area and select a delivery contact before you can move on to stage "A6 - Closed Won".');
        }
    }
}   
 }

 

I am creating a test class and the scenario I am testing requires an older date for the created date. I know CreatedDate is an audit field and I can't write to it. Is there a workaround I could use for writing my test class?

Thanks.

Hello,

 

My goal is to keep only the most recent version of a chatter file.  When someone uploads a new version I want the old version to be deleted.  As far as I can tell this is not an option in salesforce.com.

 

My thoughts are creating a trigger on either a ContentDocument or ContentVersion that deletes the related ContentDocument or previous ContentVersion before the new version is uploaded, that way only one version will exist.  How can I accomplish this?

 

Thanks,

 

- Mike

 

 

trigger AutoNoOfStud on Hostel__c (After Insert,After Update,After Delete) 
{
if(trigger.isinsert)
{
Map<Id,number> map1=new Map<Id,Number>();
list<student__c> st1=new list<student__c>();
list<hostel__c> ht1=trigger.new;
for(hostel__c ht:ht1)
{
map1.put(ht.id,ht.no_of_stud__c);
}
if(map1.size()>0&&map1!=null)
{
for(Id hid:map1.keyset())
{
for(integer i=0;i<map1.get(hid);i++)
{
student__c st=new student__c();
st.name='Indian Student '+'i';
st.phone__c='0406666';
st.lagnguage__c='telugu';
st.ref_hostel__c=hid;
st1.add(st);
}
}
if(st1.size()>0&& size!=null)
{
insert st1;
}
}
}
}
 

Error: Compile Error: Invalid type: Number at line 5 column 32

Hi,

 

I am trying to modify one of my test methods to make sure that it complies with some validation rules I recently created.  I also added a lookup filter on the Decision_Maker__c field (lookup on the Contact) so users can only look up Contact that are related to Account that Opportunity is related to.  So if Account A had two contacts, if I create an Opportunity and want to add the Decision Maker field, I only want to be able to find the two contact that Account A has in the lookup filter.  Here's my logic for the filter:

 

Decision Maker: Account ID equals Field Opportunity: Account ID (required filter)

 

This is the error that I am getting:

 

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [Decision_Maker__c]

 

I'm confused because I am pretty sure the Contact that I create in the Unit Test is related the Account I create.  Then the Opportunity I create is related to the Account, so I'm confused on why it's tripping up the error since I related everything together on the original Account.

 

 

 

public static testMethod void TestCreateActualsAndTargets_Trigger(){
    
        Account l_oAccount = new Account(Name='TestAccount', Type='Eligible');
        insert l_oAccount;
        
        User testUser = TestFactory.buildTestASUser(0, 'Standard User');
        insert testUser;
        
        Contact testContact = new Contact ();
        testContact.FirstName='Testo';
        testContact.LastName='Westo';
        testContact.Account=l_oAccount;
        insert testContact;
        
        Opportunity l_oOpportunity = new Opportunity();
        l_oOpportunity.Name='Test Opportunity';
        l_oOpportunity.Type = 'New Ad Sales';
        l_oOpportunity.CloseDate=System.today();
        l_oOpportunity.StageName='Closed/Won';
        l_oOpportunity.AccountId=l_oAccount.Id;
        l_oOpportunity.ForecastCategoryName='Pipeline';
        l_oOpportunity.Contract_ID__c = '123173';
        l_oOpportunity.Multiple_Contract_IDs_at_Close__c = 'No - I have one single Contract';
        l_oOpportunity.Split__c = '50/50';
        l_oOpportunity.User__c = testUser.Id;
        l_oOpportunity.Report_Generation_Tools_Reviewed_withSP__c = 'Yes';
        l_oOpportunity.Personality_of_ServiceProvider__c = 'Yes';
        l_oOpportunity.SPs_Expectations__c = 'Yes';
        l_oOpportunity.Why_We_Gave_SpecialPricing__c = 'Yes';
        l_oOpportunity.UpsellOpportunities__c = 'Yes';
        l_oOpportunity.Advertising_Contact__c = testContact.Id;
        l_oOpportunity.SP_knows_grade_and_current_revie__c = 'Yes';
        l_oOpportunity.Decision_Maker__c = testContact.Id;
        l_oOpportunity.SP_verbally_agreed_to_specific_coupon__c = 'Yes';
        l_oOpportunity.Length_of_SalesCycle__c = 'Within a Week';
        insert l_oOpportunity;   
    }

 

trigger code:

 

trigger EB_Case_Owner_Trigger on Case (after insert, before update)
{
    public EB_SB_Builder__c EB_account {get; private set;}
    public RecordType rtype {get; private set;}
    integer icount;
    String xd12,xd13;
    icount = 0;
    ID related_to_id, Owner_Id;
    Set<Id> tasksInSet = new Set<Id> {};
    if (Trigger.isInsert)
    {
    for (Case t : Trigger.new)
    {
    tasksInSet.add(t.Id);
    icount = icount +1;
    }
    }
      
    if (Trigger.isUpdate)
    {
    for (Case t : Trigger.new)
    {
    tasksInSet.add(t.Id);
    icount = icount +1;
    }
    }
 
    if (icount<=1)
    {
        if (Trigger.isInsert)
        {
            Case[] accs;
            accs = Trigger.new;
            for (Case a:accs){
            Date myDate = Date.Today();
            Owner_Id = a.OwnerId;
            String Case_Sub = a.Subject;
            String Case_Desc = a.Description;
            String contact_id = a.ContactId;
            String Record_type_id = a.RecordTypeId;
            rtype = [Select r.Name, r.Id, r.Description From RecordType r where  r.Id =:Record_type_id];
            xd12= rtype.Description+'';
            xd13= xd12.substring(0,3);
            if (xd13 == '005')
            {
            if (contact_id != null)
            {
            Integer j = [Select count() from RecordType r where  r.Id =:Record_type_id];
            if(j==1)
            {
                for (Case tmp : [Select e.Event_Survey_Builder__c, e.OwnerId From Case e where e.id = :a.id limit 1]) {
                tmp.OwnerId = rtype.Description;
                tmp.Description = xd12;
                update tmp;
            }
            }
            
            Integer i = [select count() from EB_SB_Builder__c EB_SB where EB_SB.Contact__c = :contact_id and EB_SB.OwnerId = :rtype.Description];
            if(i==1)
            {
                EB_account = [select tmp2.Id from EB_SB_Builder__c tmp2 where tmp2.Contact__c = :contact_id and tmp2.OwnerId = :rtype.Description limit 1];
                for (Case tmp : [Select e.Event_Survey_Builder__c, e.OwnerId From Case e where e.id = :a.id limit 1]) {
                tmp.Event_Survey_Builder__c = EB_account.id;
                tmp.OwnerId = rtype.Description;
                update tmp;
                }
            }
         }
         Task ecs = new Task(Description= Case_Desc, Subject=Case_Sub, ActivityDate=myDate,Status ='Not Started', OwnerId=rtype.Description, WhatId=a.Id);
         insert ecs;
         icount = icount +1;
         }
         
         
            }
         
         
         
        }
        
        
        
        
        
        
        
        
        

    }
    }

 

 

 

test class:

 

    @isTest(SeeAllData=true)
private class EB_Case_Owner_Trigger_Test_Class {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        EB_SB_Builder__c ebsb = new  EB_SB_Builder__c ();
        Case accs1 = new Case();
        insert ebsb;
        Datetime dt = Datetime.now();
        Case accs = new Case(RecordTypeId='0120000000098Po',Event_Survey_Builder__c = ebsb.Id, Origin= 'Email', Subject='Testing Task', Minutesoncase__c =10, Reason='508 compliance', Product_Type__c = 'Event Tool');
       Subject='Testing Task', Minutesoncase__c =10, Reason='508 compliance', Product_Type__c = 'Event Tool' , AccountId='001P000000GF1fq');
            insert accs;
    }
    

 

 

 

M getting the following error...so code coverage is less than 75%...not able to deploy...Thanks in advance for help...

 

error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Minutescase: execution of AfterInsert caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com

 

 

 

@isTest(SeeAllData=true)
private class testMyTaskTrigger {
 
    public static testMethod void testTTrigger(){
      
        
        Account acc  = new Account();
        acc.name = 'Test';
        insert acc;

        Contact con = new Contact();
        con.LastName = 'Test Contact';
        insert con;
       
       
        Task t = new Task();
        t.OwnerId = UserInfo.getUserId();
        t.Subject='Donni';
        t.Status='Not Started';
        t.Priority='Normal';
        t.Minutes_on_tasks__c = 2000;
        t.status = 'Completed';
        insert t;
 
        Task tas = new Task();
        tas.OwnerId = UserInfo.getUserId();
        tas.Subject='Donni';
        tas.Status='Not Started';
        tas.Priority='Normal';
        tas.Minutes_on_tasks__c = 2000;
        tas.status = 'Completed';
        tas.whoid = con.id;

        Sales_Resources__c sr = new Sales_Resources__c ();
        sr.Name = 'Test Sales Resources';
        insert sr;
        
        Task p = [select id from task where Ownerid = '00500000006scDCAAY' limit 1];
         try{
        delete p;
        }
        Catch(Exception e)
        {

          system.debug('Error:'+e);
        }
 
       
        Test.startTest();
        insert tas;
        try{
        delete t;
        }
        Catch(Exception e)
        {

          system.debug('Error:'+e);
        }

        Test.stopTest();
       
     }

}

 

 

same error in this test class also...  Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, EB_Case_Owner_Trigger: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Minutescase

 

 

@isTest(SeeAllData=true)
private class EB_Case_Owner_Trigger_Test_Class {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        EB_SB_Builder__c ebsb = new  EB_SB_Builder__c ();
        Case accs1 = new Case();
        insert ebsb;
        Datetime dt = Datetime.now();
        Case accs = new Case(RecordTypeId='0120000000098Po',Event_Survey_Builder__c = ebsb.Id, Origin= 'Email', Subject='Testing Task', Minutesoncase__c =10, Reason='508 compliance', Product_Type__c = 'Event Tool');
        //Case accs = new Case(ContactId = '003P000000Cu7pU',RecordTypeId='0120000000095Nn',Event_Survey_Builder__c = ebsb.Id, Origin= 'Email', Subject='Testing Task', Minutesoncase__c =10, Reason='508 compliance', Product_Type__c = 'Event Tool' , AccountId='001P000000GF1fq');
            insert accs;
    }
    

}