function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
renuamirenuami 

compatable types Error URGENT!!!! please help

Hello

 

I am trying to update the Account field.

 

Initially i was getting system.list exception duplicate id in list error . When looked at the debug log it looks like there are duplicate Account ids. 

 

So what i am planning to do is first checkwhether Account id is already present in the list, if it is present do not add it again to the list. When comparing the Account id with the values in the list i am ending up with the error

Comparison arguments must be compatible types: Id, SOBJECT:Account 

 

 please help in solving this issue !!!

 

public static void BeforeInsertMethod(Travel__c [] tt)

{
 

List<Account> TravelAcctList = new List<Account>();

for( Travel__c t: tt)
{

TravelAccount Acct;
TravelAcct=new Account(Id = t.Travel_account__c);
if(t.Status__c==true)
{
t.Confirm__c=true;
TravelAcct.Send_Confirmation__c = 'OK';
Integer List_count=TravelAcctList.size();
for(Integer i=0;i<=List_count;i++)
{
//getting error here//if(TravelAcct.Id==TravelAcctList.get(i))
{
}
else
{
TravelAcctList.add ( TravelAcct );
}
}
}
else
{

}
}

}

 

hisrinuhisrinu
if(TravelAcct.Id==TravelAcctList.get(i).id)
renuamirenuami

Hi Srini

 

Thanks for the solution.

 

How ever the test class is not working. Any idea?

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Travel_Updates: execution of BeforeInsert caused by: System.ListException: List index out of bounds: 0 Class.Travel_Apexclass.BeforeInsertMethod: line 18, column 29 Trigger.Travel_Updates: line 11, column 13: []

 

public class Travel_Apexclass {

public static void BeforeInsertMethod(Travel__c [] tt)
{
List<Account> TravelAcctList = new List<Account>();

for( Travel__c t: tt)
{
TravelAccount Acct;
TravelAcct=new Account(Id = t.Travel_account__c);
if(t.Status__c==true)
{
t.Confirm__c=true;
TravelAcct.Send_Confirmation__c = 'OK';
Integer List_count=TravelAcctList.size();
for(Integer i=0;i<=List_count;i++)
{
if(TravelAcct.Id==TravelAcctList.get(i).Id)
{
}
else
{
TravelAcctList.add ( TravelAcct );
}
}
}
else
{
TravelAcct.Send_Confirmation__c = '';
for(Integer i=0;i<=List_count;i++)
{
if(TravelAcct.Id==TravelAcctList.get(i).Id)
{
}
else
{
TravelAcctList.add ( TravelAcct );
}
}
}
}
}

//-------Test Calss---------

static testMethod void Travel_TestMethod() {

Account Domestic_Account=new Account(Name='Test Account1',RecordTypeId='0123000000005QBAAY');
insert Domestic_Account;

Account Intl_Account =new Account(Name='Test Account 2',RecordTypeid='0123000000002GvAAI');
insert Intl_Account ;

Travel tl=new travel(Domestic_account__c=Domestic_Account.id,International_Account__c=Intl_Account.id,Confirm__c=true);
insert tl; //In test results it is showing error at this line

Travel[] tl2=[select id,Confirm__c,Status__c,Domestic_account__c,International_Account__c from Travel__c where id=:tl.id];

Travel_Apexclass.BeforeInsertMethod(tl2);

}
}

 

 

 

 

 

Message Edited by renuami on 06-18-2009 07:14 AM
sforce2009sforce2009

for(Integer i=0;i<=List_count;i++)
{
      if(TravelAcct.Id==TravelAcctList.get(i).Id)
      {
      }
      else
      {
      TravelAcctList.add ( TravelAcct );
}


Use it like this


Boolean isExist = false;
for(Integer i=0;i<=List_count;i++)
 {

      if(TravelAcct.Id==TravelAcctList.get(i).Id)
      {
               isExist = true;

               break;

     }
}
if(!isExist)
{
   
    TravelAcctList.add ( TravelAcct );
   
}

 

 

Cheers

renuamirenuami

hey thankyou..it worked

But still there is isuse with the AfterInsert block  :smileysad:

 

Here i need to loop through all the Travel__c Object records under particular International Account and update a field the International Account.

 

Below code is working fine for single record. But when i try to update records from data loader for all the Travel records,  Intl_Travel_Account__c is always updating with the last record Intl_Travel_Account__c value.

 

I understand that this is because, in the for loop it is getting the last value. I tried to achieve this in many ways but all the attempts were failed.

 

Any idea? Thanks

This is my first attempt to write Salesforce triggers and really getting confused with the governer limits 

 

public static void AfterInsertMethod(Travel[] tt) { List<Account> TravelAcctList = new List<Account>(); Account travelAcct; for( Travel__c t: tt) { travelAcct =new Account(Id=t.Intl_Travel_account__c); } Integer tcount=[select count() from Travel__c where Intl_Travel_account__c=:travelAcct.Id and t.status__c=true limit 10]; if(tcount>0) { travelAcct.Intl_Travelled__c='Travelled'; } else { travelAcct.Intl_Travelled__c=''; } TravelAcctList.add(travelAcct); update TravelAcctList ; }