@future method: Unsupported parameter type

I am trying to copy records from one org to other via web services. I am calling a class which has logic written into a trigger. But @ future method is not taking sObject list as a parameter. Can someone suggest me an alternative?

The Code:

public class webServicesTriggerClass  
  @future public static void webServicesMethod(list<MyFriend__c> mfList)  
   partnerSoapSforceCom.Soap sp = new partnerSoapSforceCom.Soap();   
   partnerSoapSforceCom.LoginResult lr = sp.login('hitesh.kumar.singh@accenture.com.varun','4Rajyavardhan');  
   soapSforceComSchemasClassNiralaapp.SessionHeader_element ses = new soapSforceComSchemasClassNiralaapp.SessionHeader_element();  
   ses.sessionId = lr.sessionId;   
   soapSforceComSchemasClassNiralaapp.MyFriendsDetailSoapApi vNapp=new soapSforceComSchemasClassNiralaapp.MyFriendsDetailSoapApi();  
   for(MyFriend__c mf:mfList)  
     string  s1= mf.myEmail__c;  
     string  s2=mf.friendName__c;   
     string  s3=mf.friendEmail__c;  
     string  s4=mf.aboutFriend__c;  
     integer i1=Integer.ValueOf(mf.age__c);  
     boolean result=vNapp.addFriendDetails(s1,s2,s3,s4,i1);  
     system.debug('################' +result);      


trigger webServicesTrigger on MyFriend__c (after insert)   


Error: Compile Error: Unsupported parameter type LIST at line 3 column 30


As per documentation

You can’t pass sObjects to @future methods:

Methods with the future annotation must be static methods, and can
only return a void type. The specified parameters must be primitive
data types, arrays of primitive data types, or collections of
primitive data types. Methods with the future annotation cannot take
sObjects or objects as arguments.

The reason why sObjects can’t be passed as arguments to future methods
is because the sObject might change between the time you call the
method and the time it executes. In this case, the future method will
get the old sObject values and might overwrite them. To work with
sObjects that already exist in the database, pass the sObject ID
instead (or collection of IDs) and use the ID to perform a query for
the most up-to-date record. The following example shows how to do so
with a list of IDs.

So I would suggest passing a Set<ID> & requerying for the sObject records in your @future method.

Source : Link , Question Author : pluto , Answer Author : Keith C

Leave a Comment