+ Start a Discussion


I am receiving this error when trying to save a trigger to my production SF account:

 Run test failure marker: resource '': 'System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, opportunityContactRoleUpdate: execution of BeforeInsert

Here is my trigger. I've tried it on after insert as well:

trigger opportunityContactRoleUpdate on Opportunity (before Insert, before Update)

 // Loop over the Opportunities in the 'new' list of the
 for(Opportunity o : Trigger.new)
  // Here we need to do the contsraint check
  if((o.StageName == 'Closed Won (Recurring)' || o.StageName == 'Pilot (Recurring)') && o.Recurring_Opportunity__c=='Yes' && o.Probability>=90.0 && o.Client_Id__c==4944)
   // We need yesterdays Date. First go to the start of the current Month just to be safe.
   // Then subtract one day.
   Date a = System.today();
   Date b = a.toStartOfMonth();
   Date c = b.addDays(-1);
   // Get the Opportunity that this one was created from using
   // the client id and a close date of before the first of last month
   // We are getting a limit of 1, to get the latest. It might not have been
   // From the last month per se, but the latest excluding this one.
   List<Opportunity> oldOpps = [SELECT id FROM opportunity WHERE Client_Id__c = :o.Client_Id__c AND closedate <= :c ORDER BY closedate DESC LIMIT 1];
   // Get any OpportunityContactRoles attached to the old Opportunity
   List<OpportunityContactRole> ocrs = [SELECT id, OpportunityId FROM OpportunityContactRole WHERE OpportunityId=:oldOpps[0].id];
   // Loop through any found OpportunityContactRole objects and set the OpportunityId
   // to the OpportunityId of the new Opportunity
   for(integer i=0; i<ocrs.size(); i++)
    OpportunityContactRole new_ocr = new OpportunityContactRole(OpportunityId = o.id,ContactId = ocrs[i].ContactID,Role = ocrs[i].Role);
    insert new_ocr;

 I've checked my profile permissions and I have 'Modify All' set...any reason why I shouldn't be able to create this new opportunityContactRole? I can't find anything about why I wouldn't with the 'Modify All' permissions set...

Best Answer chosen by Admin (Salesforce Developers) 
And I just went through and mass deleted a bunch of records and then tried to reupload code and it worked! Thanks!

All Answers


Hi , Did you you find a solution for this. I am getting the same error message CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Protected_Parts_update: execution of AfterUpdate
caused by: System.QueryException: List has no rows for assignment to SObject


I am having a similar issue with uploading code. It says my triggers are failing for the same reason you had. This trigger and its test class havent been messed with at all so I am not sure that this is something I could have done.

I have a call into the premier support and will update this if they actually have an answer...
Are you facing issue while deployment..  this happens if we are trying to access or modify the record which doesnt exist in Live Enviornment..
Is Test Method and Coverage working fine in SandBox..
Yes they are working in sanbox, I also made sure the records are in the live site..

Then, there might be issue with your Access or Privilege in Live Enviornment. Do you have the permission to Modify All Data or Records in Live Enviornment. IF not than Admin needs to set this one..  also check if recor exist. Would you mind pasting the Test Method..in post..so we can tell you problem if any


Here it is, its pretty basic and has worked fine for a couple months... I do have admin rights..

@IsTest private class triggerLicenseTests {

    public static testmethod void triggerLicenseTest() {
    LicenseKey__c keys = [select name, Seats_Allowed__c, BOM_Item__c from LicenseKey__c where name = :'1234567890'];
    keys.Seats_Allowed__c = 3;
    License__c ano = [select name, license_size__c from License__c where name = :'61'];  
    ano.license_size__c = 'A6';

I can see the problem with SOSL,  Why do you have : before Constant.. '1234567890'
like where name = :'1234567890'
it should be where name = '1234567890'
We dont need to resolve the Constant value with :
they are used for Variable.. change this and try,.,
That may be an issue, but after refreshing the package in eclipse I am not getting an error on that trigger(At least its not showing it). These error themselves seemed to be as confused as I am.. The error below shows that an Insert failed in LicenseCheck but there are no inserts in that trigger or its test class(and it says it has too many rows from query but that I had hard coded in to select 1 record). Then it shows the trigger that does have the failing insert, Registration_CheckTest. So what I am getting from this is that maybe the original trigger we discussed may have somehow caused too many rows to be returned and then this other trigger cant work because of that...? I put the second trigger and the error in question below. Thanks for the help..

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

caused by: System.Exception: Too many query rows: 501

Trigger.licenseCheck: line 13, column 9

Class.Registration_CheckTEST.test1: line 8, column 9

Cumulative resource usage:

Resource usage for namespace: (default)
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 500
Number of SOSL queries: 0 out of 20
Number of DML statements: 1 out of 100
Number of DML rows: 1 out of 500
Number of script statements: 2 out of 200000
Maximum heap size: 0 out of 500000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 10
Number of record type describes: 0 out of 10
Number of child relationships describes: 0 out of 10
Number of picklist describes: 0 out of 10
Number of future calls: 0 out of 10
Number of find similar calls: 0 out of 10
Number of System.runAs() invocations: 0 out of 20

Total email recipients queued to be sent : 0
Stack frame variables and sizes:

*** Ending Test Registration_CheckTEST.public static testMethod void test1()

public class Registration_CheckTEST {
    public static testmethod void test1() {
        Registered_Pen__c pens = new Registered_Pen__c(Name='Test Oppt', key_registered_with__c='a0o700000007FfBAAU', product_pen_registered_for__c='xxxxxxx');
        insert pens;

Message Edited by James_Adapx on 12-02-2008 01:24 PM

It might have too many records in Live Enviorment.. not sure what exactly your trigger contains. can you past trigger as well as Method.

one more thing you can use LIMIT 1  in SOQL to restrict just one rows..

Yeah I think there may be too many records, we did just add a bunch of stuff. But how do I change the trigger when it wont let me upload code..?
Would this return 1 row or many?

cellx = [select count() from LicenseKey__c where OrderDetail__c = null and BOM_Item_Name__c = :setting.Cellx_BomItemName__c];

count will return one row only..  if you add LIMIT 1 in query you can restrict to one row only
But I dont want a count of 1, I need an accurate count of whats in there. So that query shouldnt be a problem, I think.

no it wont have  an issue,. do a count to see how much comes.. 

anyway Gud luck.. deployment is really fun.  In last project I spent more time in Test Method and Deployment rather than Development

Yeah i know, thanks for the help..
No problem and all the best..  by the way which location and place you are working currenty
Seattle, I am not normally a salesforce guy but our company needed the work done and I was the junior guy here so I got stuck with it. Hasnt been too bad except for a few issues like this..
And I just went through and mass deleted a bunch of records and then tried to reupload code and it worked! Thanks!
This was selected as the best answer
Congratulation, by the way how do you mass delete the data in live enviornment
Mass update Anything 1.0.5, http://wiki.apexdevnet.com/index.php/Mass_Update_Anything

Really helpfull tool..