You need to sign in to do that
Don't have an account?

Trigger needs modification: Help
trigger UpdateRemitUsedStatus on Account (after insert, after update) {
for (Account act: Trigger.new) {
Update act.RemitfromUsedStatus == True from act
where act.Enterprise_ID__C in (select Remit_From__c from Account)
}
Please help me modify the above code in trigger which i wrote in simple SQL. I want to update RemitfromUsedStatus == True on account object when account Enterprise_ID is a RemitFrom ID( RemotFrom_ID is a look up to account object on enterprise ID) for some records.
for (Account act: Trigger.new) {
Update act.RemitfromUsedStatus == True from act
where act.Enterprise_ID__C in (select Remit_From__c from Account)
}
Please help me modify the above code in trigger which i wrote in simple SQL. I want to update RemitfromUsedStatus == True on account object when account Enterprise_ID is a RemitFrom ID( RemotFrom_ID is a look up to account object on enterprise ID) for some records.
Try with belwo code it will help !!
Let me know if it helps !!
Thanks
Manoj
All Answers
Try with belwo code it will help !! If it will not help then explain your requirment so that I can help you .
For some concepts of trigger check belwo link it will help !!
http://manojjena20.blogspot.in/2013/03/manojs-trigger-blog.html
Let me know if it helps !!!
Thanks
Manoj
Hi Swayam Pati,
I hope the below code snippet will help you.
Thanks,
Karthick.S
Appreciate your reply. But unfortunately i think both of your code is not fitting into my requirement. Let me explain with Example.
EnterpriseID RemitFromID(look up to EnterpriseID) RemitfromUSed Status
------------- --------------------------------------------------------- ------------------------------------
2000
EnterpriseID RemitFromID(look up to EnterpriseID) RemitfromUSed Status
------------- --------------------------------------------------------- ------------------------------------
2000 3000 False
3000 - True
4000 - False
5000 3000 False
Basically Remitfrom is an account which Pays of other account. So i want to know who are the Remitfrom or Payer for other account, then make that Remitfromusedstatus True.
Manoj, in your code If enterpriseID is null then Make remitfromused status = True, i can make that in workflow. I don't need trigger.
Kartik, in your code if remitfromID = Enterprise iD then make status true. that also can be done in workflow.
I am specifically looking for trigger because this can't be done in formula or in workflow. If i am 2nd record which i want to make true, i want put the logic that find this enterpriseID (3000) which is a RemitfromID from some other records, then make that record's RemitfromStatus = True.
Please help me in this trigger as i am very new to writing codes.
I really appreciate your help.
Thanks
trigger UpdateRemitUsedStatus on Account (before insert, before update) {
if(trigger.isBefore && trigger.isUpdate){
for (Account act: Trigger.new) {
if(act.Enterprise_ID__C in (select act.RemotFrom_ID from acc )){
act.RemitfromUsedStatus = true ;
}
}
}
}
trigger UpdateRemitUsedStatus on Account (before insert, before update) {
if(trigger.isBefore && trigger.isUpdate){
for (Account act: Trigger.new) {
if(act.Enterprise_ID__c = Null){
interger s = 0;
s = [select count() from account t where t.Remit_From__c = act.Enterprise_ID__c];
if (s > 0)
{
act.RemitfromUsedStatus = true ;
}
}
}
Hi Swayam,
Still your explanation is not clear to give you solution .What I understand is In account you have 3 Fields
1.Remit_From__c
2.RemitfromUsedStatus __c
3.Enterprise_ID__c
Remit_From__c is the look up to account means to other account .Each account have two field called Enterprise_ID__c && RemitfromUsedStatus __c ,Here you want to write trigger in account to check if parent account 's Enterprise_ID__c is equal with child then you want RemitfromUsedStatus __c to true .else false .Correct me if I am wrong .
Else please explain your requirment clearly .
As per my understanding the below code will help you.
Thanks,
Karthick.S
Thanks for your reply. let me explain the requirement clearly. I have account object which has 3 fields
1.Enterprise_ID__c (Unique)
2.RemitfromUsedStatus __c
3.Remit_From__c (look up to Enterprise_ID__c)
Now there is no parent child relationship, it is more of account -payer relationship. We have otherfields to establish parent-child relationships. So one account may be a payer for another account but not parent.
Here, Remit_From__c accounts are payer of Enterprise_ID_c accounts, If Remit_From__c on any record is blank that means two cases
1- Either it pays for itself ( like the account 4000 above)
2- Or the account is a Remit_From__c for some other accounts (like the account 3000 above)
So i want the accounts which are Remit_from_c for some otheraccounts, in those records Remitfromusedstatus__c to be populated as 'True'.
So lets say there is a account with 'Enterprise_Id_c' has a value 7000 and it's Remifrom_C is blank, and 7000 has not been a payer for any other account ,that means it pays for itself (So remitifromusedstatus = false). Now a user goes and create a new account record with 'Enterprise_id_c' as 8000 and select "Remitfrom_c on that record as '7000', then on record where enterprise_id_c is 7000, on that record the Remitfromusedstatus_c should be changed as 'True' thru trigger. Record with with 'Enterprise_id_c' as 8000 Remitfromusedstatus still should be 'False'.
So bottomline is any Enterprise_ID that is being used as a payer (Remit_From_c) for any other Enterprise_Id, then those Payer should be flagged with a Status =' 'True'/
Hope this expains it.
You want to update status of the records which are used for another records of same object.
The following code will suit your requirement.
Please mark this post as solved .
Thanks,
Karthick.S
Thank for helping me out but i still have issues. I am getting error with your code. Since i am new to trigger, not sure how to debug. THe error i get is -
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UpdateRemitUsed_Status caused an unexpected exception, contact your administrator: UpdateRemitUsed_Status: execution of BeforeUpdate caused by: System.StringException: Invalid id: 48000: Trigger.UpdateRemitUsed_Status: line 8, column 1
The other thing i believe which is not right in your code is : - You are holding acclist with list of records where remitfrom is not null.and asssigning those to OldAcc.
So to me this should be the code
if(act.Remit_From__c == oldAcc.Enterprise_Id_c){09 oldAcc.RemitfromUsedStatus__c=true;
10 payerAccList.add(oldAcc);
So to me this should be the code:
trigger UpdateRemitUsed_Status on Account (before insert, before update) {
if(trigger.isbefore && trigger.isUpdate){
List<Account> accList=[select id,Enterprise_ID__c,RemitfromUsed_Status__c from account where id!=null];
List<Account> payerAccList = new List<Account>();
for (Account act: Trigger.new){
if(accList.size()>0)
for(Account oldAcc : accList){
if(act.Enterprise_ID__c == oldAcc.Remit_From__c){
act.RemitfromUsed_Status__c=true;
payerAccList.add(act);
}
}
}
//Update remittance status in payer account list records
update payerAccList;
}}
for(Account oldAcc : accList){
if(act.Enterprise_ID__c == oldAcc.Remit_From__c){
act.RemitfromUsed_Status__c=true;
payerAccList.add(act);
Can you connect in skpe so that you can share your screen which wil be good to check the relation ship and your requirment .
If possible connect me in my skype Id : manoj.jena19 .So that I will help you to resolve your issue .
Try with belwo code it will help !!
Let me know if it helps !!
Thanks
Manoj