You need to sign in to do that
Don't have an account?
MarkLevy
Dumbfounded: APEX updating Custom Object -- Invalid id
I'm getting this error when trying to run through the test of a trigger on my new custom object:
But furthermore, why is updating the object in the database throwing this error? why is it confusing the Name with the Id when updating??
Here's the code I have that causes the error (error caused by the line: 'update app;')
I'm completely dumbfounded here.
Why is APEX itself getting confused about what the Id is and what the Name is when it pulled all this information from the select statement that got the app in the first place?
Why is the Id auto incrementing every time I run through this test even though i'm using @isTest(seeAllData=false)?
Any help here is appreciated, I've been searching the forums heavily and can't find anything remotely like this problem.
Thanks!
System.DmlException: Update failed. First exception on row 0 with id a1O0S0000001QoIUAU; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, MasterBridgeApplicationTrigger: execution of BeforeUpdate caused by: System.StringException: Invalid id: BRAPP00019 External entry point Trigger.MasterBridgeApplicationTrigger: line 17, column 1: [] Stack Trace Class.BridgeApplicationProcessingTest.BridgeAppTest: line 44, column 1My custom object has an autoincrement Name (as you see, BRAPP00019) -- Which seems to keep autoincrementing in my test even though I'm using @isTest(seeAllData=false) for my test -- which is odd.
But furthermore, why is updating the object in the database throwing this error? why is it confusing the Name with the Id when updating??
Here's the code I have that causes the error (error caused by the line: 'update app;')
Contact ourContact = [SELECT Id, Email FROM Contact WHERE Email = 'test1@nope.com']; Bridge_Application__c app = new Bridge_Application__c( Applicant__c = ourContact.Id ); insert app; app = [SELECT Name, Id, Applicant__c, First_Decision__c, Second_Decision__c, Third_Decision__c, FROM Bridge_Application__c WHERE Applicant__c = :ourContact.Id]; app.First_Decision__c= 'Admit'; app.Second_Decision__c= 'Admit'; app.Third_Decision__c= 'Admit'; update app;
I'm completely dumbfounded here.
Why is APEX itself getting confused about what the Id is and what the Name is when it pulled all this information from the select statement that got the app in the first place?
Why is the Id auto incrementing every time I run through this test even though i'm using @isTest(seeAllData=false)?
Any help here is appreciated, I've been searching the forums heavily and can't find anything remotely like this problem.
Thanks!
Not tested but Map<Id,Bridge_Application__c> oldApps;
Regards
All Answers
The compiler can return one record but that seems unsecured if you don't limit the result.
Strengthen the unicity first (not the complete solution) and now look at the logs in detail (CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY is one of the most confusing error) with developer console opened:
Contact ourContact = [SELECT Id, Email FROM Contact WHERE Email = 'test1@nope.com' LIMIT 1];
system.debug('contact id :' + ourContact.Id);
app = [SELECT Name, Id, Applicant__c, First_Decision__c, Second_Decision__c, Third_Decision__c, FROM Bridge_Application__c WHERE Applicant__c = :ourContact.Id LIMIT 1];
Regards
Nevertheless I added the LIMIT 1 to the query, no change to the result. The debug info itself isn't particularly illuminating:
----------------------------------------------
09:44:12.76 (3323746405)|CODE_UNIT_FINISHED|MasterBridgeApplicationTrigger on Bridge_Application trigger event AfterInsert for [a1O0S0000001SZH] 09:44:12.76 (3325431826)|DML_END|[30] 09:44:12.76 (3325856411)|SOQL_EXECUTE_BEGIN|[32]|Aggregations:0|SELECT Name, Id, Applicant__c, First_Decision__c, First_Date_Updated__c, Second_Decision__c, Second_Date_Updated__c, Third_Decision__c, Third_Date_Updated__c FROM Bridge_Application__c WHERE Applicant__c = :tmpVar1 LIMIT 1 09:44:12.76 (3345371077)|SOQL_EXECUTE_END|[32]|Rows:1 09:44:12.76 (3345682520)|USER_DEBUG|[42]|DEBUG|Name: BRAPP00020, ID: a1O0S0000001SZHUA2 09:44:12.76 (3345731335)|DML_BEGIN|[44]|Op:Update|Type:Bridge_Application__c|Rows:1 09:44:12.76 (3401934019)|CODE_UNIT_STARTED|[EXTERNAL]|01q0S000000CkX1|MasterBridgeApplicationTrigger on Bridge_Application trigger event BeforeUpdate for [a1O0S0000001SZH] 09:44:12.76 (3402600262)|EXCEPTION_THROWN|[EXTERNAL]|System.StringException: Invalid id: BRAPP00020 09:44:12.76 (3402951346)|FATAL_ERROR|System.StringException: Invalid id: BRAPP00020 External entry point Trigger.MasterBridgeApplicationTrigger: line 17, column 1 09:44:12.76 (3402964681)|FATAL_ERROR|System.StringException: Invalid id: BRAPP00020
----------------------------------------------
I even pulled the name / ID out of the application object and it does show Name as name and Id as Id, but for some reason the "update" method is confusing them...
----------------------------------------------
09:44:12.76 (3345682520)|USER_DEBUG|[42]|DEBUG|Name: BRAPP00020, ID: a1O0S0000001SZHUA2
----------------------------------------------
Post the complete trigger source code of Bridge_Application.
MasterBridgeApplicationTrigger on Bridge_Application trigger event AfterInsert for [a1O0S0000001SZH]
Name: BRAPP00020, ID: a1O0S0000001SZHUA2
MasterBridgeApplicationTrigger on Bridge_Application trigger event BeforeUpdate for [a1O0S0000001SZH]
FATAL_ERROR|System.StringException: Invalid id: BRAPP00020 External entry point Trigger.MasterBridgeApplicationTrigger: line 17, column 1 09:44:12.76 (3402964681)|FATAL_ERROR|System.StringException: Invalid id: BRAPP00020
It seems that there is an error in the trigger Bridge_Application.
As soon as you will have post the complete trigger source code of Bridge_Application, many people here will understand at once the error in your code.
Regards
Here is my master trigger for that object:
the class called in insert / update is as follows:
Not tested but Map<Id,Bridge_Application__c> oldApps;
Regards
Yup.. That fixed it :)
It would be nice if the debugging gave more information as to where this errored exactly .. maybe that could be illuminated through a try/catch that displays further details about the error?
The main problem: Why does the compiler accept the mix of Id and String like here where it is obviously incorrect for standard fields like Id and Name?
While your class is compiled (100% correct for the compiler), you will believe that all is fine for the types of the parameters like in java.
I am learning myself a lot solving this kind of strange problems here.
I had just the advantage of fresh eyes.