• the0nly0ne
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies
There is a particular line of code that seems to be tricky for me in test methods. I have used this in various triggers, most of which seem to cover this line of code automatically, without any intentional additional code; however, a couple of my test methods are not covering this line of code, and I am wondering if there is a technique for covering this. This can be problematic, especially in very small triggers, where this line of code could make or break the 75% coverage.
 

}Catch(Exception e){}

 
My second question is: Say you have a trigger that creates a new record when triggered; how would you go about querying that newly created record in a test method? I'm guessing there is a simple line of code to use, I just don't know that line of code.
 
Can anyone help me out? Thanks in advance!

Hi,

 

I have been working on "bulkifying" my Apex, and lowering overall SOQL usage. I am running into a slight problem with creating a new record.

 

Usually, I include the syntax to create a new record within a for loop, under the trigger.new record; however, when running mass updates, I get the 21 SOQL limit error. When I put the new-record syntax outside the for loop, I don't get the error; but, it only creates one record, which is related to the entire batch rather than creating a new entry for every record that passes through the update.

 

My original code creates a record for each entry being updated, but hits SOQL limits in bulk:

 

for(Lead l:trigger.new){ Custom_Object__c co = new Custom_Object__c(); insert co; l.Custom_Lookup__c=co.Id; }

 

My updated code is not getting the SOQL error, but only creates one record for the entire batch (rather than 200 records, one for each):

 

Custom_Object__c co = new Custom_Object__c(); insert co; for(Lead l:trigger.new){ l.Custom_Lookup__c=co.Id; }

 

Does anyone have any suggestions or ideas on how I can fix this issue, and still keep my code "bulk-safe". I need to create a record for each entry that passes through the update, without hitting the SOQL limit. Any help you can give me would be highly appreciated.

 

Thanks!

I am getting ready to begin an Apex project that involves very complex business logic. I am currently sitting on about 10,000+ characters (which I realize is not too high), but I expect to have a whole lot more before my project is finished.

 

I was curious as to what the character limit is for one Apex trigger. This will help me decide whether to proceed with only one trigger, or to find an alternate method of specifying the necessary logic.

 

Thank you, in advance!

I am new to Apex development, but for my first "real" programming language, I am picking it up quick. The only thing I have run into so far that is challenging is that I ran into a limitation: no more than 20 SOQLs per event.

 

I have several cross-object triggers that are designed to sometimes trigger each other. I believe I should be looking into Lists, Sets, and Maps to work around the only 20 SOQLs limitation. Currently, I start with Leads, automatically generating related custom objects. I then refer to these records much later in the process by using code that is similar to the following example:

 

Object o = [select field, secondObject from object where Id = lead.objectLookup__c];

secondObject so = [select field, antherField from secondObject where Id = o.secondObject__c];

 

Does anyone have some advice, a detailed introduction to Lists Maps and Sets, or example code? I have already looked at the Apex Guide, but it seems to leave out a lot of what could otherwise be very useful example code (unless, of course, I simply overlooked the example code section).

 

Thanks, in advance.

Hi,

 

I have been working on "bulkifying" my Apex, and lowering overall SOQL usage. I am running into a slight problem with creating a new record.

 

Usually, I include the syntax to create a new record within a for loop, under the trigger.new record; however, when running mass updates, I get the 21 SOQL limit error. When I put the new-record syntax outside the for loop, I don't get the error; but, it only creates one record, which is related to the entire batch rather than creating a new entry for every record that passes through the update.

 

My original code creates a record for each entry being updated, but hits SOQL limits in bulk:

 

for(Lead l:trigger.new){ Custom_Object__c co = new Custom_Object__c(); insert co; l.Custom_Lookup__c=co.Id; }

 

My updated code is not getting the SOQL error, but only creates one record for the entire batch (rather than 200 records, one for each):

 

Custom_Object__c co = new Custom_Object__c(); insert co; for(Lead l:trigger.new){ l.Custom_Lookup__c=co.Id; }

 

Does anyone have any suggestions or ideas on how I can fix this issue, and still keep my code "bulk-safe". I need to create a record for each entry that passes through the update, without hitting the SOQL limit. Any help you can give me would be highly appreciated.

 

Thanks!

I am getting ready to begin an Apex project that involves very complex business logic. I am currently sitting on about 10,000+ characters (which I realize is not too high), but I expect to have a whole lot more before my project is finished.

 

I was curious as to what the character limit is for one Apex trigger. This will help me decide whether to proceed with only one trigger, or to find an alternate method of specifying the necessary logic.

 

Thank you, in advance!

Hi,

 

I am trying to create a task on creation of an account in a specific industry.

 

When I try to link the account and Task by putting the account id in the WhoID field of the task, I get a exception when the trigger fires.

 

CreateTaskWhenAccountCreated: execution of AfterInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Contact/Lead ID: id value of incorrect type: 0014000000NKcUBAA1: [WhoId]

Trigger.CreateTaskWhenAccountCreated: line 46, column 1

 

How do I link a task to an Account differently to avoid getting this exception?

 

Thanks!!

When trying to change the recordtype of a person account to normal business account, I get the following error: "insufficient access rights on cross-reference id".

 

However, it works fine when I change it to a different person account record type. According to the documentation, it should also work across recordtype families.

I do have access to the recordtype I want to change to in the profile settings and can create a account with that recordtype manually in the GUI and with apex, so it's not an actual access rights issue as the error message suggests.

 

Any ideas what could be the problem here?

 

Thanks

Hi.  I need to trigger an auto email when specific type of Event is scheduled for a lead.  I am unable to write a worflow rule to accomplish this because the lead object workflow rules cannot see the Event fields.  To get around this I believe I need to copy the Event Start date/time for this specific type of Event to a Lead custom field.  I can then trigger a workflow rule to send an email to the lead based on that Lead custom field being populated. 

 

Does this seem to be the best way to accomplish this?  Can I get some help writting the Apex trigger?  Thanks!