Skip to main content

Hi,

Below is my trigger

string OnHold = 'On Hold';

       string HoldwithResume = 'Hold with Resume Date';

       string Finished = 'Finished';

       string OnProgram = 'On Program';

       //Loop through all records in the Trigger.new collection

       List<Opportunity> opportunity = [SELECT Id, Name, Account.Program_Status__c FROM Opportunity where Account.Id in :accountNewMap.keySet() Order By CreatedDate Desc LIMIT 1];

       for(Opportunity accountsWithOpps : opportunity)

       { 

            //opps.Id = accountsWithOpps.Id;

            if(accountsWithOpps.Account.Program_Status__c == OnHold || accountsWithOpps.Account.Program_Status__c == HoldwithResume) 

            { 

                accountsWithOpps.StageName = 'On Hold';

            }

            else if(accountsWithOpps.Account.Program_Status__c == Finished || accountsWithOpps.Account.Program_Status__c == 'Never Started') 

            {

                accountsWithOpps.StageName = 'Closed Lost';

                accountsWithOpps.CloseDate = Date.today();

            } 

            else if(accountsWithOpps.Account.Program_Status__c == OnProgram) 

            {

                accountsWithOpps.StageName = 'On Program';

            } 

       }

       update opportunity; 

Here Account is my parent object and Opportunity is my child object. What is my problem is If the record size is 1 means the update is working perfectly. But if we update from data loader it is updating the first record in file only. remaining records are not updated in child object. Thanks in advance
2 réponses
  1. 23 janv. 2015, 15:37
    Hi James,

    Yes my requirement is I want to update the latest opportunity alone. Thats i my problem now. Any ideas?

    Thanks,

    Vetri