You need to sign in to do that
Don't have an account?
Apex on a trigger problem... (BTW I am new to Salesforce and Apex....)
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!
I think the main problem here is your if statement, it's not using the correct syntax.
Try doing this first, and then see if you still get teh error regarding the variable declaration:
All Answers
I think the main problem here is your if statement, it's not using the correct syntax.
Try doing this first, and then see if you still get teh error regarding the variable declaration:
Hi SLockard,
Thank you very much!