You need to sign in to do that
Don't have an account?
tyler_jennings
Problem updating affected record from Trigger
This trigger does _not_ save 'Hello!' to the Area__c field on the case, I can't figure out why. There are no errors. Here's the log output:
Thanks!
*** Beginning copyFieldsOnCreate on Case trigger event bulk AfterInsert for 500T0000000n9TfCan anyone point out my flaw?
20070731134615.308:Trigger.copyFieldsOnCreate: line 1, column 1: TriggerBody: copyFieldsOnCreate
20070731134615.308:Trigger.copyFieldsOnCreate: line 2, column 3: SelectLoop:Static: name: Trigger.new, type: LIST:SOBJECT:Case
20070731134615.308:Trigger.copyFieldsOnCreate: line 2, column 31: Block with 3 statements
20070731134615.308:Trigger.copyFieldsOnCreate: line 6, column 5: DeclareVar: Local: name: c, type: SOBJECT:Case with initial value(s): InlineQuery: [select c.id, c.Area__c from Case c where c.Id = :ca.Id]
20070731134615.308:Trigger.copyFieldsOnCreate: line 6, column 14: SOQL query with 1 row finished in 13 ms
20070731134615.308:Trigger.copyFieldsOnCreate: line 6, column 5: initial value: Case:{Id=500T0000000n9TfIAI}
20070731134615.308:Trigger.copyFieldsOnCreate: line 7, column 5: SOBJECT:Case.Area__c assigned Literal: Hello!
20070731134615.308:Trigger.copyFieldsOnCreate: line 8, column 5: Update: SOBJECT:Case
20070731134615.308:Trigger.copyFieldsOnCreate: line 8, column 5: DML Operation executed in 352 ms
Cumulative resource usage:
Number of SOQL queries: 1 out of 20
Number of query rows: 1 out of 1000
Number of DML statements: 1 out of 20
Number of DML rows: 1 out of 100
Number of transaction control statements: 0 out of 0
Number of script statements: 3 out of 10200
Maximum heap size: 0 out of 100000
*** Ending copyFieldsOnCreate on Case trigger event bulk AfterInsert for 500T0000000n9Tf
Thanks!
I discovered is that reference IDs are not yet populated on a before insert event. If you look at the three commented
lines in the tigger you'll see what I'm really trying to do.
Thanks for the help!
grab the account with your field
the ca variable already has the new (yet to be created) case
so just assign the account value to the case member.
and note, no need for update() this occurs automaticaly
note: this code does a query for each case that you insert, so probably needs to be optimized to get all
the accounts that it needs in one query not N queries.
Code:
It does indeed work for me when I create a new case or update an existing one. However,
This trigger throws an exception when inserting a new case from the customer portal. I apologize for
not mentioning our use of the customer portal earlier, I thought it was irrelevant. From what I can gather
from the exceptions / logs the Account is not defined when the before insert event fires the trigger.
So, that's what lead me toward the after insert approach. I *think* the Account should be defined at that point.
So I think we're back to square one: How do I get an after insert trigger working that updates the trigger-firing
object?
Apex trigger copyFieldsOnCreate_test caused an unexpected exception, contact your
administrator: copyFieldsOnCreate_test: execution of BeforeInsert caused by:
System.QueryException: List has no rows for assignment to SObject:
Trigger.copyFieldsOnCreate_test: line 3, column 17
i'm not sure why the account id is empty when entering the trigger, probably because the contact needs to be matched up, and this may be happening after the before trigger.
can you check for that ID in the after triger
something like this:
system.assert(ca.accountId != null) ;
Also, find out if the ContactId is set or empty in your trigger?
it's possible is the portal is creating the record with this empty, then calling 'update' to write in the account ID
I've just hit something very similar. The APEX code works when creating a Case from the salesforce interface, but it fials to select objects when called from the self-service portal.
My code is (for debugging my issue is):
trigger Azuro_auto_assign_case on Case (before insert) {
For (Case c : Trigger.new) {
//based on the AccountID, assign to that Accounts creator
c.addError('Everything is ok');
system.assert(c.AccountId != null);
ID account_creator_id=[SELECT CreatedById FROM account WHERE Id= :c.AccountId].CreatedById;
If(account_creator_id!= null) {
c.OwnerId=account_creator_id;
} else {
c.addError('Did not find a account_creator_id');
}
//c.addError('account_id='+c.AccountId);
}
}
When creating from in salesforce I get the following error (effectively a pass!):
Error: Invalid Data.
Review all error messages below to correct your data.
Everything is ok
When creating a case from the self-service api I get:
Error:
Apex trigger Azuro_auto_assign_case caused an unexpected exception, contact your administrator: Azuro_auto_assign_case: execution of BeforeInsert caused by: System.Exception: Assertion Failed: Trigger.Azuro_auto_assign_case: line 5, column 9
Message Edited by TheBomb on 09-07-2007 07:17 AM
The following code:
trigger Azuro_auto_assign_case on Case (before insert) {
For (Case c : Trigger.new) {
//based on the Contact, assign to the contact Account's creator
c.addError('Everything is ok');
system.assert(c.ContactId != null);
ID account_id=[SELECT AccountId FROM Contact WHERE Id=:c.ContactId].AccountId;
system.assert(account_id != null);
ID account_creator_id=[SELECT CreatedById FROM account WHERE Id=:account_id].CreatedById;
If(account_creator_id!= null) {
c.OwnerId=account_creator_id;
} else {
c.addError('Did not find a account_creator_id');
}
}
}
Gives me an ok from in Salesforce:
Error: Invalid Data.
Review all error messages below to correct your data.
Everything is ok
But an error of having no rows from the self-service portal:
Error:
Apex trigger Azuro_auto_assign_case caused an unexpected exception, contact your administrator: Azuro_auto_assign_case: execution of BeforeInsert caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.Azuro_auto_assign_case: line 6, column 23