Salesforce Certified Application Architect

Thursday 26 December 2013

Unsupported parameter type in @future Method Using Trigger

Hi, Friends you can't pass Sobjects as parameters into asynchronous methods. "Methods with the future annotation cannot take sObjects or objects as arguments." You can pass a list or set of ID's and then query for the objects inside the method. shown in below..


Trigger:

  1. trigger test on Book__c (before Update) {  
  2.     if(Trigger.isUpdate){  
  3.         LIST<String> myOldObjectststId = new LIST<String>();  
  4.         LIST<String> myNewObjectststId = new LIST<String>();  
  5.           
  6.         Set<String> opportunitysalesids = new Set<String> ();          
  7.   
  8.         for (Book__c  b1 : [Select Id from Book__c where id in :Trigger.old]) {   
  9.            myOldObjectststId.add(b1.id);           
  10.         }  
  11.         for (Book__c  b2 : [Select Id from Book__c where id in :Trigger.new]) {   
  12.            myNewObjectststId.add(b2.id);           
  13.         }  
  14.         MyObjectUpdateAfter.testMethodFuture(myOldObjectststId ,myNewObjectststId );  
  15.     }  
  16. }  


Class with Future Method:

  1. public class MyObjectUpdateAfter{  
  2.     @future  
  3.     public static void testMethodFuture(LIST<String> myOldObjectstst,LIST<String> myNewObjectstst){  
  4.         //Now use these Id of  myOldObjectstst & myNewObjectstst  
  5.   
  6.     }  
  7. }  

1 comment:

  1. Thanks Gaurav.. Its pretty easy to understand with ur example

    ReplyDelete

Salesforce Certified Application Architect & Certified Data Architecture and Management Designer Exam

How to pass Salesforce Certified Data Architecture and Management Designer Exam This exam was 1st architect exam for me. Its not that muc...