• EUS
  • NEWBIE
  • 10 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 18
    Replies
I am trying to build a List of records from a List of other objects. Afterwards I need to insert the new List created. However I get the error List Index out of bounds. Here follows the code:

             
List<Line__c> LMELI  = new List<Line__c>();

List<TX__c> Trx     = [SELECT  Id,  Amount__c
                                      FROM TX__c

integer i = 0;

for (TX__c PMT : Trx) {
            
            LMELI[i].MB__c                  = Ref__c;            //  I get the error  LIST INDEX out of bounds (0)      
            LMELI[i].Tx__c                     = PMT.Id;                                      
            LMELI[i++].Amount__c      = PMT.Amount__c;  
                        
    }  // for PMT ends here

   INSERT LMELI;
  • April 18, 2014
  • Like
  • 0
I have an object that is filled from fields from another object. I created  a list of the same object type and I need to add the records to it. However it is giving me the Index out of bounds error when I add the record to the list. Here follows the code:

Line__c MELI                = new Line__c();                
List<Line__c> LMELI  = new List<Line__c>();

List<TX__c> Trx     = [SELECT  Id,  Amount__c
                                      FROM TX__c 

integer i = 0;

for (TX__c PMT : Trx) {
             
            MELI.MB__c             = Ref__c;                
            MELI.Tx__c                = PMT.Id;                                       
            MELI.Amount__c      = PMT.Amount__c;   
            LMELI.add(i++, MELI);                                               // The error is on this line                               
                          
    }  // for PMT ends here


I would greatly appreciate any help!

Thank you!
  • April 18, 2014
  • Like
  • 0

Hi,

 

I have created a list (RDML) based on a custom sObject (Rdm_Line__c) to populate  with fields from another custom sObject  (Pocket__c).  When I finish iterating over the Pocket__c object from which I also create a Map, I add the records to the RDML list.

No matter what I do (add, set) it would always failed with fatal error  List index out of bounds.....

I don't see the error, ... Can someone help me understand how should I add elements to the list avoiding such error? ...

Here follows the sample code:

 

List<Rdm_Line__c>  RDML     = new List<Rdm_Line__c>();                // Rdm_Line List.

Rdm_Line__c    lrdm                = newRdm_Line__c();                          // New Line Rdm_Line record.

Map<Id, Rdm_Line__c> mIdRL = new Map<Id, Rdm_Line__c>();         // Map that holds...

 

I checked on the Developer Console that mIdRL Map is well constructed and all records are correctly stored there.

 

so at the end of the iteration over Pocket__c I do the following:

 

if (!mIdRL.isEmpty()) {

          RDML.clear();                // Clear Rdm List.                                  

           i = 0;                             //  RDML array index is initialized.

             

for (ID pIds : mIdRL.KeySet()) {                                 // KeySet from Pocket Id Map.

              

             if (RDML.isEmpty()) {                                     // RDML List is empty so I add a new element i.

                   RDML.add(i++, mIdRL.get(pIds));                 // Populate Rdm_Line List from Pocket Map.

               }

              

             else {RDML.set(i++, mIdRL.get(pIds));}       // RDML List is NOT empty so I set the element i.

 }

             

insert RDML;                                                             // Rdm_Line records are inserted.

 

The Fatal error is on the red line above where the message reads:

System.ListException: List index out of bounds: 0

 

I would appreciate if someone could explain to me what I am doing wrong, and how List indexes should be managed....

 

Thanks a lot!

  • September 22, 2013
  • Like
  • 0

Hi,

 

I needed to sort a custom sObject Pocket__c by a date field, (Pocket_Date__c) however since the SELECT also needs to use a WHERE condition based ID from a Master Relationship I was not able to use ORDER BY.  I followed the example of the Wrapper using COMPARABLE and after loading the Wrapper list and having SORT  the resulting list Pl ,  I need to CAST back the List to the original sObject type Pocket__c. Can someone help me do that or suggest another way of accomplishing the ORDER BY in this context?  Follows the code I used:

 

List<Pocket__c> pKo  = [SELECT p.Id, p.Pocket_Balance__c, p.certRed_Ref__c, p.certRedValue__c, p.certRedDT__c
                                 FROM Pocket__c p
                                 WHERE Wallet__r.Member__c   =: sList.rId_Ref__c
                                 AND   Wallet__r.Merchant__c =: sList.rId2_Ref__c 
                                // ORDER BY p.Pocket_Date__c    It doesn't allow me to use the ORDER BY ....
                                 FOR UPDATE ];
        PocketWrapper[] Pl = new List<PocketWrapper>();
        for (integer i=0; i>pKo.size(); i++) {
         
         Pl.add( new PocketWrapper(pKo[i]));
        }
        Pl.sort();

 

***  I now need to return  PocketWrapper  Pl  back to  sObject  Pocket__c ...... and update the pKo List of sObjects Pocket__c ....

 

 

This is the PocketWrapper class:

 

global class PocketWrapper implements Comparable {
 public Pocket__c expDT;
 // Constructor
 public PocketWrapper(Pocket__c eD) {
 expDT = eD;
 }
 // Compare Pockets based on the expiration Date (Pocket_Date__c).
 global integer compareTo(Object compareTo) {
  // Cast argument to PocketWrapper
  PocketWrapper compareToExpDT = (PocketWrapper)compareTo;
  // The return value of 0 indicates that both elements are equal.
  Integer returnValue = 0;
  if (expDT.Pocket_Date__c > compareToExpDT.expDT.Pocket_Date__c) {
  // Set return value to a positive value.
  returnValue = 1;
  } else if (expDT.Pocket_Date__c < compareToExpDT.expDT.Pocket_Date__c) {
  // Set return value to a negative value.
  returnValue = -1;
  }
  return returnValue;
 }
  }

 

I would appreciate any help! ....

 

 

  • September 14, 2013
  • Like
  • 0

Hi,

 

I have a trigger after insert and after update for an sObject which I would like to process with a Class Method and not at the trigger itself.  So I am passing the trigger.new list to the method and I also need to compare the previous fields on the oldMap structure to confirm whether or not the fields have been updated.  Can I pass the trigger.oldMap Map to the method? Also the method is a webservice method.

 

I tried to pass the map with no luck! ... Also just tried to use the oldMap in the webservice, assuming the Map would be available and it does not work! However the same statement used in the trigger snippet works.... Only I'd rather process all code at the class instead of the trigger.

 

Any ideas or suggestions?

 

Here is the trigger code that works:

 

for (Member__c Mbr : Trigger.new) {
      Member__c oldMember = Trigger.oldMap.get(Mbr.ID);
       if (Mbr.Merchant__c != oldMember.Merchant__c) {  // Merchant Id has changed so I need to process it.
               // more code here...
       }

rList =  Member.memberUpdate(trigger.new);                 // Here I call the webservice method and pass the trigger.new List

 

The same code would not work at the webservice method (I think it losses context of trigger.oldMap there)...

 

Here is the websercie code:

 

 webservice static void memberUpdate(list<Member__c> nMb) {
     
      for (Member__c MBR : nMb) {
       Member__c oldMember  = Trigger.oldMap.get(MBR.ID);
       //

 

The error I get from force.IDE is the following:

Save error: Illegal assignment from SObject to SOBJECT:Member__c

 

Thanks!

 

  • August 02, 2013
  • Like
  • 0

Hi,

 

I am trying to call a webservice method from whithin another webservice method from other class. I have tested the werbservices on Developer Console  and work fine. However the Apex code does not compile when adding the call from a webservice method class. Is there any restrinctions I am not aware of?

Here follows the webservices code:

 

 webservice static string batchTrxnLoadValidaion() {
             
    List<TRXN__c> oTxIt =
    [SELECT tx.Name, tx.Amount__c, tx.Type__c, tx.IMEI_IMEISV__c, tx.Mrch_Contract__c   
      FROM TRXN__c tx
      WHERE tx.id IN : Trigger.new 
      FOR UPDATE]; 
    for (TRXN__c Trx : oTxIt)   {
           id trxMember = Member.getMember(Trx.Mrch_Contract__c);
      //  more code here  .....

  

 

This is the Force.IDE message I get:

Save error: Method does not exist or incorrect signature: [String].getMember(String)

 

If I remove this statement the webservice compiles ok.

 

The method called getMember() follows:  (BTW: I tested it on Development Console and works fine)

 

 webservice static ID getMember(string mbContract) {
        ID mbMember = null;
        List<Member__c> activeMembers = [SELECT mb.Name, mb.Contract__c
                                         FROM Member__c mb WHERE mb.Status__c = 'Active'
                                         AND mb.Contract__c =: mbContract LIMIT 1];
        if (!activeMembers.isEmpty()) { mbMember = activeMembers[0].id;
                                      return mbMember;             
        }
        else { return null; }
   } 

 

Thanks for your help!

 

 

 

 

 

 

  • July 24, 2013
  • Like
  • 0

Hi,

 

I have a trigger which checks whether two fields in different objects have the same value in which case it should return to the Salesforce interface with the addError message inserted. However, it does not stop the DML operation nor returns with the Error Message.  I placed the addError message statement everywhere testing, but it doesn't work. I might be missing something important! .... 

 

Here follows the trigger code:

 

trigger languageLangMessageInsertion on LANG__c (before insert) {
    List<SetUp__c> SU = [SELECT Msgs_Lang__c FROM SetUp__c LIMIT 1];
       if (SU.size()>0) {     //  Country/Region record Exists whithin sObject SetUp__c                
        for (SetUp__c usu : SU) {
            List<LANG__c> LG = [SELECT Language__c FROM LANG__c  WHERE id IN :Trigger.new];
               for (LANG__c aLG : LG) {
               if (usu.Msgs_Lang__c == aLG.Language__c) {  //  SetUp Msgs_Lang__c equals this selection .... Not Valid   
                  aLG.Language__c.addError('message language not valid.');
              }
              else {
                  aLG.Language__c.addError('B .. message language not valid.');
              }
            }    
           }   
      }   // if SU.size()>0
    else {
                //  Country/Region record does not Exist yet ...
               for (LANG__c aLG : trigger.new) {
                   aLG.Language__c.addError('First you need to create the Region record and default language.');
                  } 
             }  //  else
}

 

Any suggestions?

Thanks a lot!

 

  • July 22, 2013
  • Like
  • 0

Hi,

 

I wrote a Trigger to prevent the insertion of a new record whithin an SetUp__c  sObject if already exists ANY active records in there (the idea is that only one record should exist in that sObject). However the new record is inserted no matter what.

Here is the trigger code:

 

 

trigger NewSetUpRecord on SetUp__c (before insert) {

      List<SetUp__c> SUR = [SELECT Id, Name, IsDeleted FROM SetUp__c WHERE IsDeleted = false AND  id  IN :Trigger.new];

      boolean exists = false;

      if (SUR.size()>0) {

                      for (SetUp__c sr : SUR) {

                                 if (sr.IsDeleted) {}

                                 else {

                                   exists = true;

                                   break;

                                 }

                      }

                      if (!exists) {

                         insert SUR;

                      }

     }

}

 

Any ideas why this might be happening?

 

Thanks!

  • July 19, 2013
  • Like
  • 0

Hi,

 

I am using a validation rule to check that a picklist selection does not match an sObject field (which also is a picklist field).

 

Here is the formula I am using:

 

(ISPICKVAL(Language__c,'English')   &&  $ObjectType.SetUp__c.Fields.Msgs_Lang__c = 'English')

 

The error message is not triggered so I checked and the problem is with the object  $ObjectType.SetUp__c.Fields.Msgs_Lang__c which is not returning its true value (the problem might be it is a picklist field).

I tried with VLOOKUP instead, however it does not support  picklist fields.

 

Any suggestions as to how could I compare a picklist selection to an other custom field on other sObject?

 

Thanks a lot!

  • July 19, 2013
  • Like
  • 0

Hi, I am new to SF and Apex and I am in need to understand what I am doing wrong on this trigger...

 

I have an object TRXN that holds transactions records. Some ot them are loaded from a legacy system (via batch) which sends a field called Contract__c  This field lets me search on a MEMBER__c object the corresponding Member__c lookup field that should be updated on the TRXN.Member__c  lookup relationship field.

 

I have a method whithin MEMBER getMember() that returns an ID primitive type field with the lookup Id that should be updated on the TRXN.Member__c lookup field.  The following code should be accomplishing that simply task, however,  I am not even able to compile (thru force.IDE) the trigger. The error I get is the following:

 

Save Error: Illegal variable declaration: Trx.Member__c

 

on this statement:  if (trxMember != null) then Trx.Member__c = trxMember;

 

Follows the trigger:

 

trigger TrxnBatchLoad on TRXN__c (after insert) {

 

List<TRXN__c> oTxIt =

[SELECT  tx.Mrch_Contract__c, tx.Merchant__c, tx.Member__c

   FROM TRXN__c tx

   WHERE tx.id IN : Trigger.new 

   FOR UPDATE];

 

  for (TRXN__c Trx : oTxIt)   {

    id trxMember = Member.getMember(Trx.Mrch_Contract__c);

       if (trxMember != null) then Trx.Member__c = trxMember; 

       else {Trx.Member__c = null;

              }

    Update oTxIt;                  

    }

 }

 

The method getMember has the following:

 

public ID getMember(string mbContract) {

 ID mbMember = null;

 List<Member__c> M = [SELECT mb.Name, mb.Contract__c

               FROM Member__c mb WHERE mb.Contract__c =: mbContract LIMIT 1];

        mbMember = M[0].id;

        return mbMember;             

}

 

I have assumed the relatinship field (lookup) is just an ID primitive type that holds the id of the corresponding row whithin the related object and that I should be able to replace it if in need of.

 

I would appreciate any help on this. Thanks a lot!

 

 

 

 

 

 

  • July 17, 2013
  • Like
  • 0
I am trying to build a List of records from a List of other objects. Afterwards I need to insert the new List created. However I get the error List Index out of bounds. Here follows the code:

             
List<Line__c> LMELI  = new List<Line__c>();

List<TX__c> Trx     = [SELECT  Id,  Amount__c
                                      FROM TX__c

integer i = 0;

for (TX__c PMT : Trx) {
            
            LMELI[i].MB__c                  = Ref__c;            //  I get the error  LIST INDEX out of bounds (0)      
            LMELI[i].Tx__c                     = PMT.Id;                                      
            LMELI[i++].Amount__c      = PMT.Amount__c;  
                        
    }  // for PMT ends here

   INSERT LMELI;
  • April 18, 2014
  • Like
  • 0
I have an object that is filled from fields from another object. I created  a list of the same object type and I need to add the records to it. However it is giving me the Index out of bounds error when I add the record to the list. Here follows the code:

Line__c MELI                = new Line__c();                
List<Line__c> LMELI  = new List<Line__c>();

List<TX__c> Trx     = [SELECT  Id,  Amount__c
                                      FROM TX__c 

integer i = 0;

for (TX__c PMT : Trx) {
             
            MELI.MB__c             = Ref__c;                
            MELI.Tx__c                = PMT.Id;                                       
            MELI.Amount__c      = PMT.Amount__c;   
            LMELI.add(i++, MELI);                                               // The error is on this line                               
                          
    }  // for PMT ends here


I would greatly appreciate any help!

Thank you!
  • April 18, 2014
  • Like
  • 0

Hi,

 

I have created a list (RDML) based on a custom sObject (Rdm_Line__c) to populate  with fields from another custom sObject  (Pocket__c).  When I finish iterating over the Pocket__c object from which I also create a Map, I add the records to the RDML list.

No matter what I do (add, set) it would always failed with fatal error  List index out of bounds.....

I don't see the error, ... Can someone help me understand how should I add elements to the list avoiding such error? ...

Here follows the sample code:

 

List<Rdm_Line__c>  RDML     = new List<Rdm_Line__c>();                // Rdm_Line List.

Rdm_Line__c    lrdm                = newRdm_Line__c();                          // New Line Rdm_Line record.

Map<Id, Rdm_Line__c> mIdRL = new Map<Id, Rdm_Line__c>();         // Map that holds...

 

I checked on the Developer Console that mIdRL Map is well constructed and all records are correctly stored there.

 

so at the end of the iteration over Pocket__c I do the following:

 

if (!mIdRL.isEmpty()) {

          RDML.clear();                // Clear Rdm List.                                  

           i = 0;                             //  RDML array index is initialized.

             

for (ID pIds : mIdRL.KeySet()) {                                 // KeySet from Pocket Id Map.

              

             if (RDML.isEmpty()) {                                     // RDML List is empty so I add a new element i.

                   RDML.add(i++, mIdRL.get(pIds));                 // Populate Rdm_Line List from Pocket Map.

               }

              

             else {RDML.set(i++, mIdRL.get(pIds));}       // RDML List is NOT empty so I set the element i.

 }

             

insert RDML;                                                             // Rdm_Line records are inserted.

 

The Fatal error is on the red line above where the message reads:

System.ListException: List index out of bounds: 0

 

I would appreciate if someone could explain to me what I am doing wrong, and how List indexes should be managed....

 

Thanks a lot!

  • September 22, 2013
  • Like
  • 0

Hi,

 

I needed to sort a custom sObject Pocket__c by a date field, (Pocket_Date__c) however since the SELECT also needs to use a WHERE condition based ID from a Master Relationship I was not able to use ORDER BY.  I followed the example of the Wrapper using COMPARABLE and after loading the Wrapper list and having SORT  the resulting list Pl ,  I need to CAST back the List to the original sObject type Pocket__c. Can someone help me do that or suggest another way of accomplishing the ORDER BY in this context?  Follows the code I used:

 

List<Pocket__c> pKo  = [SELECT p.Id, p.Pocket_Balance__c, p.certRed_Ref__c, p.certRedValue__c, p.certRedDT__c
                                 FROM Pocket__c p
                                 WHERE Wallet__r.Member__c   =: sList.rId_Ref__c
                                 AND   Wallet__r.Merchant__c =: sList.rId2_Ref__c 
                                // ORDER BY p.Pocket_Date__c    It doesn't allow me to use the ORDER BY ....
                                 FOR UPDATE ];
        PocketWrapper[] Pl = new List<PocketWrapper>();
        for (integer i=0; i>pKo.size(); i++) {
         
         Pl.add( new PocketWrapper(pKo[i]));
        }
        Pl.sort();

 

***  I now need to return  PocketWrapper  Pl  back to  sObject  Pocket__c ...... and update the pKo List of sObjects Pocket__c ....

 

 

This is the PocketWrapper class:

 

global class PocketWrapper implements Comparable {
 public Pocket__c expDT;
 // Constructor
 public PocketWrapper(Pocket__c eD) {
 expDT = eD;
 }
 // Compare Pockets based on the expiration Date (Pocket_Date__c).
 global integer compareTo(Object compareTo) {
  // Cast argument to PocketWrapper
  PocketWrapper compareToExpDT = (PocketWrapper)compareTo;
  // The return value of 0 indicates that both elements are equal.
  Integer returnValue = 0;
  if (expDT.Pocket_Date__c > compareToExpDT.expDT.Pocket_Date__c) {
  // Set return value to a positive value.
  returnValue = 1;
  } else if (expDT.Pocket_Date__c < compareToExpDT.expDT.Pocket_Date__c) {
  // Set return value to a negative value.
  returnValue = -1;
  }
  return returnValue;
 }
  }

 

I would appreciate any help! ....

 

 

  • September 14, 2013
  • Like
  • 0

Hi,

 

I have a trigger after insert and after update for an sObject which I would like to process with a Class Method and not at the trigger itself.  So I am passing the trigger.new list to the method and I also need to compare the previous fields on the oldMap structure to confirm whether or not the fields have been updated.  Can I pass the trigger.oldMap Map to the method? Also the method is a webservice method.

 

I tried to pass the map with no luck! ... Also just tried to use the oldMap in the webservice, assuming the Map would be available and it does not work! However the same statement used in the trigger snippet works.... Only I'd rather process all code at the class instead of the trigger.

 

Any ideas or suggestions?

 

Here is the trigger code that works:

 

for (Member__c Mbr : Trigger.new) {
      Member__c oldMember = Trigger.oldMap.get(Mbr.ID);
       if (Mbr.Merchant__c != oldMember.Merchant__c) {  // Merchant Id has changed so I need to process it.
               // more code here...
       }

rList =  Member.memberUpdate(trigger.new);                 // Here I call the webservice method and pass the trigger.new List

 

The same code would not work at the webservice method (I think it losses context of trigger.oldMap there)...

 

Here is the websercie code:

 

 webservice static void memberUpdate(list<Member__c> nMb) {
     
      for (Member__c MBR : nMb) {
       Member__c oldMember  = Trigger.oldMap.get(MBR.ID);
       //

 

The error I get from force.IDE is the following:

Save error: Illegal assignment from SObject to SOBJECT:Member__c

 

Thanks!

 

  • August 02, 2013
  • Like
  • 0

Hi,

 

I am trying to call a webservice method from whithin another webservice method from other class. I have tested the werbservices on Developer Console  and work fine. However the Apex code does not compile when adding the call from a webservice method class. Is there any restrinctions I am not aware of?

Here follows the webservices code:

 

 webservice static string batchTrxnLoadValidaion() {
             
    List<TRXN__c> oTxIt =
    [SELECT tx.Name, tx.Amount__c, tx.Type__c, tx.IMEI_IMEISV__c, tx.Mrch_Contract__c   
      FROM TRXN__c tx
      WHERE tx.id IN : Trigger.new 
      FOR UPDATE]; 
    for (TRXN__c Trx : oTxIt)   {
           id trxMember = Member.getMember(Trx.Mrch_Contract__c);
      //  more code here  .....

  

 

This is the Force.IDE message I get:

Save error: Method does not exist or incorrect signature: [String].getMember(String)

 

If I remove this statement the webservice compiles ok.

 

The method called getMember() follows:  (BTW: I tested it on Development Console and works fine)

 

 webservice static ID getMember(string mbContract) {
        ID mbMember = null;
        List<Member__c> activeMembers = [SELECT mb.Name, mb.Contract__c
                                         FROM Member__c mb WHERE mb.Status__c = 'Active'
                                         AND mb.Contract__c =: mbContract LIMIT 1];
        if (!activeMembers.isEmpty()) { mbMember = activeMembers[0].id;
                                      return mbMember;             
        }
        else { return null; }
   } 

 

Thanks for your help!

 

 

 

 

 

 

  • July 24, 2013
  • Like
  • 0

Hi,

 

I have a trigger which checks whether two fields in different objects have the same value in which case it should return to the Salesforce interface with the addError message inserted. However, it does not stop the DML operation nor returns with the Error Message.  I placed the addError message statement everywhere testing, but it doesn't work. I might be missing something important! .... 

 

Here follows the trigger code:

 

trigger languageLangMessageInsertion on LANG__c (before insert) {
    List<SetUp__c> SU = [SELECT Msgs_Lang__c FROM SetUp__c LIMIT 1];
       if (SU.size()>0) {     //  Country/Region record Exists whithin sObject SetUp__c                
        for (SetUp__c usu : SU) {
            List<LANG__c> LG = [SELECT Language__c FROM LANG__c  WHERE id IN :Trigger.new];
               for (LANG__c aLG : LG) {
               if (usu.Msgs_Lang__c == aLG.Language__c) {  //  SetUp Msgs_Lang__c equals this selection .... Not Valid   
                  aLG.Language__c.addError('message language not valid.');
              }
              else {
                  aLG.Language__c.addError('B .. message language not valid.');
              }
            }    
           }   
      }   // if SU.size()>0
    else {
                //  Country/Region record does not Exist yet ...
               for (LANG__c aLG : trigger.new) {
                   aLG.Language__c.addError('First you need to create the Region record and default language.');
                  } 
             }  //  else
}

 

Any suggestions?

Thanks a lot!

 

  • July 22, 2013
  • Like
  • 0

Hi,

 

I wrote a Trigger to prevent the insertion of a new record whithin an SetUp__c  sObject if already exists ANY active records in there (the idea is that only one record should exist in that sObject). However the new record is inserted no matter what.

Here is the trigger code:

 

 

trigger NewSetUpRecord on SetUp__c (before insert) {

      List<SetUp__c> SUR = [SELECT Id, Name, IsDeleted FROM SetUp__c WHERE IsDeleted = false AND  id  IN :Trigger.new];

      boolean exists = false;

      if (SUR.size()>0) {

                      for (SetUp__c sr : SUR) {

                                 if (sr.IsDeleted) {}

                                 else {

                                   exists = true;

                                   break;

                                 }

                      }

                      if (!exists) {

                         insert SUR;

                      }

     }

}

 

Any ideas why this might be happening?

 

Thanks!

  • July 19, 2013
  • Like
  • 0

Hi,

 

I am using a validation rule to check that a picklist selection does not match an sObject field (which also is a picklist field).

 

Here is the formula I am using:

 

(ISPICKVAL(Language__c,'English')   &&  $ObjectType.SetUp__c.Fields.Msgs_Lang__c = 'English')

 

The error message is not triggered so I checked and the problem is with the object  $ObjectType.SetUp__c.Fields.Msgs_Lang__c which is not returning its true value (the problem might be it is a picklist field).

I tried with VLOOKUP instead, however it does not support  picklist fields.

 

Any suggestions as to how could I compare a picklist selection to an other custom field on other sObject?

 

Thanks a lot!

  • July 19, 2013
  • Like
  • 0

Hi, I am new to SF and Apex and I am in need to understand what I am doing wrong on this trigger...

 

I have an object TRXN that holds transactions records. Some ot them are loaded from a legacy system (via batch) which sends a field called Contract__c  This field lets me search on a MEMBER__c object the corresponding Member__c lookup field that should be updated on the TRXN.Member__c  lookup relationship field.

 

I have a method whithin MEMBER getMember() that returns an ID primitive type field with the lookup Id that should be updated on the TRXN.Member__c lookup field.  The following code should be accomplishing that simply task, however,  I am not even able to compile (thru force.IDE) the trigger. The error I get is the following:

 

Save Error: Illegal variable declaration: Trx.Member__c

 

on this statement:  if (trxMember != null) then Trx.Member__c = trxMember;

 

Follows the trigger:

 

trigger TrxnBatchLoad on TRXN__c (after insert) {

 

List<TRXN__c> oTxIt =

[SELECT  tx.Mrch_Contract__c, tx.Merchant__c, tx.Member__c

   FROM TRXN__c tx

   WHERE tx.id IN : Trigger.new 

   FOR UPDATE];

 

  for (TRXN__c Trx : oTxIt)   {

    id trxMember = Member.getMember(Trx.Mrch_Contract__c);

       if (trxMember != null) then Trx.Member__c = trxMember; 

       else {Trx.Member__c = null;

              }

    Update oTxIt;                  

    }

 }

 

The method getMember has the following:

 

public ID getMember(string mbContract) {

 ID mbMember = null;

 List<Member__c> M = [SELECT mb.Name, mb.Contract__c

               FROM Member__c mb WHERE mb.Contract__c =: mbContract LIMIT 1];

        mbMember = M[0].id;

        return mbMember;             

}

 

I have assumed the relatinship field (lookup) is just an ID primitive type that holds the id of the corresponding row whithin the related object and that I should be able to replace it if in need of.

 

I would appreciate any help on this. Thanks a lot!

 

 

 

 

 

 

  • July 17, 2013
  • Like
  • 0