2

How to solve above solution please give some ideas.

1
  • "salesforce", please do some effort in your question. Try to explain us your context and what is not clear to you. The question in it's current state is barely understandable and/or very hard to answer due to it's vagueness. Jul 14, 2015 at 11:57

3 Answers 3

1

As an example, you may use global static variable to skip self-run trigger. But it's not the best solution:

trigger OppFieldUpdate on Opportunity (after insert, after update) {
 if (!GlobalClass.runOnce){
    Opportunity[] updates = new Opporunity[] {};
    for (Opportunity opp: Trigger.new) {
        if (opp.StageName == 'Qualification') {
            updates.add(new Opportunity(Id = opp.Id, Opp.OppStatus__c = 'Won'));
        }
    }
    GlobalClass.runOnce = true;
    update updates;
 }
GlobalClass.runOnce = false;
}
0

If you have a strong reason to do this in an "after" trigger and not by any other means:

trigger OppFieldUpdate on Opportunity (after insert, after update) {
    Opportunity[] updates = new Opporunity[] {};
    for (Opportunity opp: Trigger.new) {
        if (opp.StageName == 'Qualification') {
            updates.add(new Opportunity(Id = opp.Id, Opp.OppStatus__c = 'Won'));
        }
    }
    update updates;
}
0

Here is the pseduo code for the same

trigger OppFieldUpdate on  Opportunity (before insert, before update) {

for(Opportunity Opp: trigger.new)
{
 if(Opp.StageName == 'Qualification')
 {
 
  Opp.OppStatus__c = 'Won';
 }
}

}

However by using Salesforce work flow field update we can achieve the same.

2
  • i need for (after insert, after update)
    – salesforce
    Jul 14, 2015 at 9:56
  • trigger myTrigger on Account (after insert) { Account myAccount=trigger.new[0]; Account updacc=[select id from account where id = :myAccount.id]; updacc.type='Enterprise Customer'; update updacc; } Salesfore URL for Trigger events, please click on the below link and see the event after update: salesforce.com/us/developer/docs/apexcode/Content/…
    – Asha
    Jul 14, 2015 at 10:25

Not the answer you're looking for? Browse other questions tagged .