You need to sign in to do that
Don't have an account?
Apex Trigger in Live Causing Errors
BeforeUpdate:
MutualClientUpdates: execution of BeforeUpdatecaused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call Class.MutualClientApex.beforeinsertupdate1:
Afterupdate:
MutualClientUpdates: execution of AfterUpdate caused by: System.ListException: Duplicate id in list: Class.MutualClientApex.afterinsertupdate1:
beforeinsert and afterinsert classes also contains the same code. This should be resolved ASAP as this is in Live and we have lot of issues from this morning. Please Advice!!!
There is a custom object (related) under the Account Object. When a new custom record is inserted or updated few fields on the Account object need to be updated by checking some conditions.
trigger MutualClientUpdates on Mutual_Client__c (before insert,before update,after insert,after update) { if(trigger.isBefore) { if(trigger.isinsert){ Mutual_Client__c[] m=Trigger.new; MutualClientApex.beforeinsertupdate(m); } if(trigger.isupdate){ Mutual_Client__c[] m=Trigger.new; MutualClientApex.beforeinsertupdate1(m); } } if(trigger.isafter) { if(trigger.isinsert) { Mutual_Client__c[] m=Trigger.new; MutualClientApex.afterinsertupdate(m); } if(trigger.isupdate) { Mutual_Client__c[] m=Trigger.new; MutualClientApex.afterinsertupdate1(m); } } }
Apex Class
public class MutualClientApex { public static void beforeinsertupdate(Mutual_Client__c [] m){ List<Account> acctList = new List<Account>(); for( Mutual_Client__c o: m){ if(o.Wholesale_Relationship__c==true) { Account a=new Account(Id = o.client_prospect_account__c); o.Client_Authorization__c=true; a.Client_type__c = 'Wholesale'; acctList.add ( a ); } else { Account a=new Account(Id = o.client_prospect_account__c); a.Client_type__c = ''; acctList.add ( a ); }update acctList; } }
public static void afterinsertupdate1(Mutual_Client__C[] m){ List<Account> acctList = new List<Account>(); for( Mutual_Client__c o: m) { Mutual_Client__c[] az=[select Id from Mutual_Client__c where Accounting_Provider__c=.Accounting_Provider__c and Wholesale_Relationship__c =true]; Account ac =[select Id from Account where Id=.Accounting_Provider__c]; if(az.size()>0) { ac.Status__c='Wholesale'; } else { ac.Status__c=''; } acctList.add(ac); } update acctList; } }
Thanks for the response. client_prospect_account__c is the required field on the custom object. It does not allow to save the record if this fied is empty. Please advise!!!!!
These are the test cases i wrote. Should these tests satisfy the above issues you mentioned.
static testMethod void beforeinsertupdatetest13() {
Account firmAccount=new Account(Name='UnitTest9',RecordTypeId='0123000000005QBAAY',Division='02d30000000000rAAA');
insert firmAccount;
Account clientAccount =new Account(Name='UnitTest1',RecordTypeid='0123000000002GvAAI');
insert clientAccount ;
Mutual_Client__c mc=new Mutual_Client__c(client_prospect_account__c=clientAccount .id,Wholesale_Relationship__c=true,Accounting_Provider__c=firmAccount.id);
insert mc;
ID key = mc.id;
Mutual_Client__c val=[select id,Client_Authorization__c,Wholesale_Relationship__c from Mutual_Client__c where id= :key];
//System.assert(val.Wholesale_Relationship__c==true);
//System.assert(val.Client_Authorization__c==true);
ID key1 =clientAccount.id;
Account val1=[select id,Client_type__c from Account where id=:key1];
//System.assert(val1.Client_type__c=='wholesale');
Mutual_Client__c[] dd=[select Wholesale_Relationship__c,client_prospect_account__c,Accounting_Provider__c from Mutual_Client__c where id=:mc.id];
MutualClientApex.beforeinsertupdate1(dd);
}
static testMethod void beforeinsertupdatetest23() {
Account firmAccount=new Account(Name='UnitTest9',RecordTypeId='0123000000005QBAAY',Division='02d30000000000rAAA');
insert firmAccount;
Account clientAccount =new Account(Name='UnitTest2',RecordTypeid='0123000000002GvAAI');
insert clientAccount;
Mutual_Client__c mc=new Mutual_Client__c(client_prospect_account__c=clientAccount.id,Wholesale_Relationship__c=false,Accounting_Provider__c=firmAccount.id);
insert mc;
ID key = mc.id;
Mutual_Client__c val=[select id,Wholesale_Relationship__c from Mutual_Client__c where id= :key];
//System.assert(val.Wholesale_Relationship__c==false);
ID key1 =clientAccount.id;
Account val1=[select id,Client_type__c from Account where id=:key1];
//System.assert(val1.Client_type__c=='');
Mutual_Client__c[] ff=[select Wholesale_Relationship__c,client_prospect_account__c,Accounting_Provider__c from Mutual_Client__c where id=:mc.id];
MutualClientApex.beforeinsertupdate1(ff);
}
static testMethod void afterinsertupdatetest133() {
Account firmAccount=new Account(Name='UnitTest44',Status__c='Wholesale',RecordTypeId='0123000000005QBAAY',Division='02d30000000000rAAA');
insert firmAccount;
//ID key2=firmAccount.id;
Account clientAccount =new Account(Name='UnitTest43',RecordTypeid='0123000000002GvAAI');
insert clientAccount;
//ID key1=clientAccount.id;
Mutual_Client__c mc=new Mutual_Client__c(client_prospect_account__c=clientAccount.id,Accounting_Provider__c=firmAccount.id,Wholesale_Relationship__c=true);
Mutual_Client__c[] case6=[select id from Mutual_Client__c where Accounting_Provider__c=:mc.Accounting_Provider__c and Wholesale_Relationship__c=true];
MutualClientApex.afterinsertupdate1(case6);
}
static testMethod void afterinsertupdatetest221() {
Account firmAccount=new Account(Name='UnitTest5',Status__c='',RecordTypeId='0123000000005QBAAY',Division='02d30000000000rAAA');
insert firmAccount;
Account clientAccount =new Account(Name='UnitTest3',RecordTypeid='0123000000002GvAAI');
insert clientAccount;
Mutual_Client__c mc=new Mutual_Client__c(client_prospect_account__c=clientAccount.id,Accounting_Provider__c=firmAccount.id,Wholesale_Relationship__c=false);
Mutual_Client__c[] case1=[select id from Mutual_Client__c where Accounting_Provider__c=:mc.Accounting_Provider__c and Wholesale_Relationship__c=true];
MutualClientApex.afterinsertupdate1(case1);
}
Message Edited by renu on 08-20-2008 03:17 PM
Thanks for the reply. Here is the Renaming version of my code. Apologize for this lenghty code. Please Advise!!!!!
Trigger
Apex Class
//--------------------Start BeforeInsertCheck----------------------------------------------------------------------
public static void BeforeInsertCheck(Mutual_Client__c [] m){
List<Account> acctList = new List<Account>();
for( Mutual_Client__c o: m){
if(o.Wholesale_Relationship__c==true)
{
Account a=new Account(Id = o.client_prospect_account__c);
o.Client_Authorization__c=true;
a.Client_type__c = 'Wholesale';
acctList.add ( a );
}
else
{
Account a=new Account(Id = o.client_prospect_account__c);
a.Client_type__c = '';
acctList.add ( a );
}update acctList;
}
}
static testMethod void BeforeInsertTest1() {
Account firmAccount=new Account(Name='Sample1',RecordTypeId='0123000000005QBAAY',Division='02d30000000000rAAA');
insert firmAccount;
Account clientAccount =new Account(Name='Sample2',RecordTypeid='0123000000002GvAAI');
insert clientAccount ;
Mutual_Client__c mc=new Mutual_Client__c(client_prospect_account__c=clientAccount .id,Wholesale_Relationship__c=true,Accounting_Provider__c=firmAccount.id);
insert mc;
ID key = mc.id;
Mutual_Client__c val=[select id,Client_Authorization__c,Wholesale_Relationship__c from Mutual_Client__c where id= :key];
System.assert(val.Wholesale_Relationship__c==true);
System.assert(val.Client_Authorization__c==true);
ID key1 =clientAccount.id;
Account val1=[select id,Client_type__c from Account where id=:key1];
System.assert(val1.Client_type__c=='wholesale');
Mutual_Client__c[] cc=[select Wholesale_Relationship__c,client_prospect_account__c,Accounting_Provider__c from Mutual_Client__c where id=:mc.id];
MutualClientApex.BeforeInsertCheck(cc);
}
static testMethod void BeforeInsertTest2() {
Account firmAccount=new Account(Name='Sample3',RecordTypeId='0123000000005QBAAY',Division='02d30000000000rAAA');
insert firmAccount;
Account clientAccount =new Account(Name='Sample4',RecordTypeid='0123000000002GvAAI',Client_type__c='');
insert clientAccount;
Mutual_Client__c mc=new Mutual_Client__c(client_prospect_account__c=clientAccount.id,Wholesale_Relationship__c=false,Accounting_Provider__c=firmAccount.id);
insert mc;
ID key = mc.id;
Mutual_Client__c val=[select id,Wholesale_Relationship__c from Mutual_Client__c where id= :key];
//System.assert(val.Wholesale_Relationship__c==false);
ID key1 =clientAccount.id;
Account val1=[select id,Client_type__c from Account where id=:key1];
//System.assert(val1.Client_type__c=='');
Mutual_Client__c[] dd=[select Wholesale_Relationship__c,client_prospect_account__c,Accounting_Provider__c from Mutual_Client__c where id=:mc.id];
MutualClientApex.BeforeInsertCheck(dd);
}
//--------------------End BeforeInsertCheck-------------------------------
//----------------------Start AfterInsertCheck-----------------------------
public static void AfterInsertCheck(Mutual_Client__C[] m){
List<Account> acctList = new List<Account>();
for( Mutual_Client__c o: m)
{
Mutual_Client__c[] az=[select Id from Mutual_Client__c where Accounting_Provider__c=:o.Accounting_Provider__c and Wholesale_Relationship__c =true];
Account ac =[select Id from Account where Id=:o.Accounting_Provider__c];
if(az.size()>0)
{
ac.Status__c='Wholesale';
}
else
{
ac.Status__c='';
}
acctList.add(ac);
}
update acctList;
}
static testMethod void AfterInsertTest1() {
Account firmAccount=new Account(Name='Sample5',Status__c='Wholesale',RecordTypeId='0123000000005QBAAY',Division='02d30000000000rAAA');
insert firmAccount;
//ID key2=firmAccount.id;
Account clientAccount =new Account(Name='Sample6',RecordTypeid='0123000000002GvAAI');
insert clientAccount;
//ID key1=clientAccount.id;
Mutual_Client__c mc=new Mutual_Client__c(client_prospect_account__c=clientAccount.id,Accounting_Provider__c=firmAccount.id,Wholesale_Relationship__c=true);
Mutual_Client__c[] case2=[select id from Mutual_Client__c where Accounting_Provider__c=:mc.Accounting_Provider__c and Wholesale_Relationship__c=true];
MutualClientApex.AfterInsertCheck(case2);
}
static testMethod void AfterInsertTest2() {
Account firmAccount=new Account(Name='Sample7',Status__c='',RecordTypeId='0123000000005QBAAY',Division='02d30000000000rAAA');
insert firmAccount;
//ID key2=firmAccount.id;
Account clientAccount =new Account(Name='Sample8',RecordTypeid='0123000000002GvAAI');
insert clientAccount;
//ID key1=clientAccount.id;
Mutual_Client__c mc=new Mutual_Client__c(client_prospect_account__c=clientAccount.id,Accounting_Provider__c=firmAccount.id,Wholesale_Relationship__c=false);
Mutual_Client__c[] case1=[select id from Mutual_Client__c where Accounting_Provider__c=:mc.Accounting_Provider__c and Wholesale_Relationship__c=true];
MutualClientApex.AfterInsertCheck(case1);
}
//----------------------------End AfterInsertCheck----------------------------
//----------------------------End BeforeUpdateCheck----------------------------
public static void BeforeUpdateCheck(Mutual_Client__c [] m){
List<Account> acctList = new List<Account>();
for( Mutual_Client__c o: m){
if(o.Wholesale_Relationship__c==true)
{
Account a=new Account(Id = o.client_prospect_account__c);
o.Client_Authorization__c=true;
a.Client_type__c = 'Wholesale';
acctList.add ( a );
}
else
{
Account a=new Account(Id = o.client_prospect_account__c);
a.Client_type__c = '';
acctList.add ( a );
}update acctList;
}
}
static testMethod void BeforeUpdateTest1() {
Account firmAccount=new Account(Name='Sample9',RecordTypeId='0123000000005QBAAY',Division='02d30000000000rAAA');
insert firmAccount;
Account clientAccount =new Account(Name='Sample10',RecordTypeid='0123000000002GvAAI');
insert clientAccount ;
Mutual_Client__c mc=new Mutual_Client__c(client_prospect_account__c=clientAccount .id,Wholesale_Relationship__c=true,Accounting_Provider__c=firmAccount.id);
insert mc;
ID key = mc.id;
Mutual_Client__c val=[select id,Client_Authorization__c,Wholesale_Relationship__c from Mutual_Client__c where id= :key];
//System.assert(val.Wholesale_Relationship__c==true);
//System.assert(val.Client_Authorization__c==true);
ID key1 =clientAccount.id;
Account val1=[select id,Client_type__c from Account where id=:key1];
//System.assert(val1.Client_type__c=='wholesale');
Mutual_Client__c[] dd=[select Wholesale_Relationship__c,client_prospect_account__c,Accounting_Provider__c from Mutual_Client__c where id=:mc.id];
MutualClientApex.BeforeUpdateCheck(dd);
}
static testMethod void BeforeUpdateTest2() {
Account firmAccount=new Account(Name='Sample11',RecordTypeId='0123000000005QBAAY',Division='02d30000000000rAAA');
insert firmAccount;
Account clientAccount =new Account(Name='Sample12',RecordTypeid='0123000000002GvAAI');
insert clientAccount;
Mutual_Client__c mc=new Mutual_Client__c(client_prospect_account__c=clientAccount.id,Wholesale_Relationship__c=false,Accounting_Provider__c=firmAccount.id);
insert mc;
ID key = mc.id;
Mutual_Client__c val=[select id,Wholesale_Relationship__c from Mutual_Client__c where id= :key];
//System.assert(val.Wholesale_Relationship__c==false);
ID key1 =clientAccount.id;
Account val1=[select id,Client_type__c from Account where id=:key1];
//System.assert(val1.Client_type__c=='');
Mutual_Client__c[] ff=[select Wholesale_Relationship__c,client_prospect_account__c,Accounting_Provider__c from Mutual_Client__c where id=:mc.id];
MutualClientApex.BeforeUpdateCheck(ff);
}
//--------------------------End BeforeUpdateCheck----------------------------------------------
//---------------------AfterUpdateCheck---------------------------------------------
public static void AfterUpdateCheck(Mutual_Client__C[] m){
List<Account> acctList = new List<Account>();
for( Mutual_Client__c o: m)
{
Mutual_Client__c[] az=[select Id from Mutual_Client__c where Accounting_Provider__c=:o.Accounting_Provider__c and Wholesale_Relationship__c =true];
Account ac =[select Id from Account where Id=:o.Accounting_Provider__c];
if(az.size()>0)
{
ac.Status__c='Wholesale';
}
else
{
ac.Status__c='';
}
acctList.add(ac);
}
update acctList;
}
static testMethod void AfterUpdateTest1() {
Account firmAccount=new Account(Name='Sample13',Status__c='Wholesale',RecordTypeId='0123000000005QBAAY',Division='02d30000000000rAAA');
insert firmAccount;
Account clientAccount =new Account(Name='Sample14',RecordTypeid='0123000000002GvAAI');
insert clientAccount;
Mutual_Client__c mc=new Mutual_Client__c(client_prospect_account__c=clientAccount.id,Accounting_Provider__c=firmAccount.id,Wholesale_Relationship__c=true);
Mutual_Client__c[] case1=[select id from Mutual_Client__c where Accounting_Provider__c=:mc.Accounting_Provider__c and Wholesale_Relationship__c=true];
MutualClientApex.AfterUpdateCheck(case1);
}
static testMethod void AfterUpdateTest2() {
Account firmAccount=new Account(Name='Sample15',Status__c='',RecordTypeId='0123000000005QBAAY',Division='02d30000000000rAAA');
insert firmAccount;
//ID key2=firmAccount.id;
Account clientAccount =new Account(Name='Sample16',RecordTypeid='0123000000002GvAAI');
insert clientAccount;
//ID key1=clientAccount.id;
Mutual_Client__c mc=new Mutual_Client__c(client_prospect_account__c=clientAccount.id,Accounting_Provider__c=firmAccount.id,Wholesale_Relationship__c=false);
Mutual_Client__c[] case2=[select id from Mutual_Client__c where Accounting_Provider__c=:mc.Accounting_Provider__c and Wholesale_Relationship__c=true];
MutualClientApex.AfterUpdateCheck(case2);
}
//--------------------------End AfterUpdateCheck------------------------------
}
Hi -
I am trying to put the system.debug statements but i am understanding the debug log.
Please guide me how to write/use system.debug log. Also seen the documentation for this .But really i am uabale to follow.
please advise