function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rafael.Martins.SantosRafael.Martins.Santos 

How get the data of the fields of an Opportunity Updated?

Hi,

I creating a trigger, that when an Opportunity are closed, I get some of the data of the fields of that opportunity and send these informations to another system.
But I don't know how get theses fields with APEX.

Can someone help me?

Best Regards
Rafael


 
Best Answer chosen by Rafael.Martins.Santos
rajat Maheshwari 6rajat Maheshwari 6

Rafael,

Please utilize below code :  -

trigger CriarProjeto on Opportunity (after update) {
Opportunity opty ;



opty = new Opportunity([SELECT Id, Name, Proposal_Number__c, StageName FROM Opportunity WHERE Id IN : Trigger.newMap.keyset() limit 1]);

    System.debug('Name: '+ opty.Name);
    System.debug('ID: '+ opty.Id);
    System.debug('Proposal Number: '+ opty.Proposal_Number__c);
    System.debug('Stage Name: '+ opty.StageName);
    
}

 

Thanks

All Answers

rajat Maheshwari 6rajat Maheshwari 6

Hi Rafael,

Please do soql query to fetch fields from opportunity where isClosed equals true : -  below is sample code and let me know if any questions

trigger OpportunityUpdatedTrigger on Opportunity (After Update)
  {
      if(Trigger.isAfter && Trigger.isUpdate)
          {
              
               List<Opportunity> opp_List = new List<Opportunity>([Select Id,Name,AccountId from Opportunity where isClosed = true]);
                    system.debug('aaaaa'+opp_List);
           }
  }

Thanks
Rajat Maheshwari
                     
                      

 

Rafael.Martins.SantosRafael.Martins.Santos
Hi Rajat,

Thanks for your help, but I need get the current opportunity.
For example:
The sales rep update the opportunity and change the StageName for "Closed", After that I have to get the Id of this opportunity and get some fields of that opportunity to create a new record in another system.

Until now I can get these fields but I need especify the Opportunity Id, but I don't know how get the especific Id of that opportunity that was updated.

My code is like this:

trigger CriarProjeto on Opportunity (after update) {
Opportunity opty = new Opportunity();

opty = [SELECT Id, Name, Proposal_Number__c, StageName FROM Opportunity WHERE Id = ??????];

    System.debug('Name: '+ opty.Name);
    System.debug('ID: '+ opty.Id);
    System.debug('Proposal Number: '+ opty.Proposal_Number__c);
    System.debug('Stage Name: '+ opty.StageName);
    
}

Do you know how I do that?

Best Regards
Rafael.
rajat Maheshwari 6rajat Maheshwari 6

Rafael,

Please utilize below code :  -

trigger CriarProjeto on Opportunity (after update) {
Opportunity opty ;



opty = new Opportunity([SELECT Id, Name, Proposal_Number__c, StageName FROM Opportunity WHERE Id IN : Trigger.newMap.keyset() limit 1]);

    System.debug('Name: '+ opty.Name);
    System.debug('ID: '+ opty.Id);
    System.debug('Proposal Number: '+ opty.Proposal_Number__c);
    System.debug('Stage Name: '+ opty.StageName);
    
}

 

Thanks

This was selected as the best answer
rajat Maheshwari 6rajat Maheshwari 6
Please let me know, if you still have issue.

Thanks
Rafael.Martins.SantosRafael.Martins.Santos
Hi Rajat,

Thanks for your help. Now its work :)

For me I have to make some change to work, but works kkkkkk.

Thanks again for your help and atention.
rajat Maheshwari 6rajat Maheshwari 6

Rafael,

Please let me know in case of any help :)

Email Id : rajatzmaheshwari@gmail.com

Thanks

siva krishna 61siva krishna 61
Hi santosh 

 will share your code where you are make changes in your requirements. advance thanks for your kindness


regards
krishna