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

How to fire the below trigger only once.
trigger updateaccountstatus on Opportunity (after update) { for (Opportunity o : Trigger.new) { Opportunity opp =[select ID,Name, StageName,AccountId from Opportunity where ID =:o.id]; if (Trigger.isUpdate) { account acct=[select ID,Name,Status__c from account where id =:opp.AccountId]; if(opp.StageName=='Suspend') { acct.Status__c='Suspend'; update acct; } } } }
I want to fire the above trigger only once.
Got to know that by using static variables we can fire trigger only once but how to implement in my above code.
from opputunity trigger you are updating record of accounts so that wont call the oppurtunity trigger recirsively.
if you want to block recursing you can declare a static variable in a Apex class and check the value of the variable before doing any dml.
code inside trigger
Here im looking for once the condition is met i.e oop.stagename=='suspend', the account status will update. next If the same oop.stagename=='suspend' trigger should not fire bez already once the criteria is met and account got update. So, again if at all the status of opportunity is same the trigger should not fire.
Is my above code wrks for it?
trigger will always fire despite of the fact condiotion are met or not. But u can stop the updation of account record by checking the status field. You need the static variable only when there is a trigger in account object which again updates the oppurtunity object