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
RedSalesRedSales 

Passing An Object From A Trigger To A WebService

Hi,

 

I wish to instantiate a webservice call after I insert data into an object. I wondered how do I retrieve and pass a full object from within  a trigger to my webservice method call.

 

I had thought I could do something like this.

 

trigger MyObjDataAfterInsert on MyObjData__c (after insert) { 

  ProcessingService.processObjData(Trigger);

}

 

Where  "ProcessingService" is my webservice name (I changed the name for this forum)

However it does not compile ok.

 

How do i enter the pass my object within the   ProcessingService.processObjData(Trigger) method?

The Trigger.new method returns a list but I don't think this is what I need. I need to pass the full object within my method call.

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
RedSalesRedSales

Hi, I resolved this using the following

 

trigger MyObjDataAfterInsert on MyObjData__c (after insert) {   for(Integer i=0;i<Trigger.new.size();i++){    MyObjData__c objData=(MyObjData__c)Trigger.new[i];    ProcessingService.processObjData(objData);  }}

 

 

Thanks again for the help!

All Answers

EalesieEalesie

Are you trying to call a Salesforce webservice from an Apex Trigger - or are you calling a method that consumes an exteranal service ?

RedSalesRedSales

Hi Ealesie, thanks for the help.

 

I'm calling an Apex/Salesforce webservice from an Apex Trigger.

 

Thanks!

RedSalesRedSales

Hi, I resolved this using the following

 

trigger MyObjDataAfterInsert on MyObjData__c (after insert) {   for(Integer i=0;i<Trigger.new.size();i++){    MyObjData__c objData=(MyObjData__c)Trigger.new[i];    ProcessingService.processObjData(objData);  }}

 

 

Thanks again for the help!

This was selected as the best answer
EalesieEalesie
Hi RedSales I understand now that you are not calling an internal webservice but a utility method. Does your utility method perform any DML - if so please note that as you are calling this utility method from a trigger the approach you have used to implement will not scale if the trigger is called by a bulk insert . Cheers Ealesie