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
LosintikfosLosintikfos 

trigger.new

Hi Experts,

I have this method that i am trying to use trigger to invoke byt keeps getting;
Save error: Method does not exist or incorrect signature: ServiceAccount.createServ(LIST:SOBJECT:Service__c)

Below is the method i am using to invoke my external webservice.
Code:
global class ServiceAccount{
   @future 
     static void createServ(){
  Service__c sd = new Service__c();
  
     Boolean rental = sd.Rental__c;
     String alias = sd.Billing_Alias__c;
     String freq  = sd.Frequency__c;
  
            wsServiceAccount.ServiceAccountHttpSoap11Endpoint stub = new wsServiceAccount.ServiceAccountHttpSoap11Endpoint();
                   String call = stub.CreateService(rental, alias, freq);  
                   //return call;
        }
   }

This is the trigger:
Code:
trigger ServiceAccount on Service__c (before insert, before update) {
 ServiceAccount.createServ(trigger.new);
}
I have tried passing Array Primitive to the method and tried several options but won't work. Do anyone know what to do? experts advice please.

My requirement is to use the trigger to automatically invoke the apex class for remote process before insert.



Need your help experts!:smileysad:
 

 

JimRaeJimRae
At first glance, I would say your issue is that you are passing an array of Service__c objects to the createserv method, which does not take any parameters.  Is your method supposed to process an existing Service__c object?  If so, you need to accept it as a parameter.  You also need to either set up your method to process an array of objects, or change the trigger code to cycle through the objects one at a time.
 
Without understanding exactly what you are trying to do, my best guess is that you are trying to do something like this:
 
Code:
global class ServiceAccount{
   @future 
     static void createServ(Service__c sd){

 //Service__c sd = new Service__c();
  
     Boolean rental = sd.Rental__c;
     String alias = sd.Billing_Alias__c;
     String freq  = sd.Frequency__c;
  
            wsServiceAccount.ServiceAccountHttpSoap11Endpoint stub = new wsServiceAccount.ServiceAccountHttpSoap11Endpoint();
                   String call = stub.CreateService(rental, alias, freq);  
                   //return call;
        }
   }

 
Code:
trigger ServiceAccount on Service__c (before insert, before update) {
 for(Service__c s : trigger.new){
  ServiceAccount.createServ(s);
 }
}

 
This will pass the new or updated Service__c objects to the createServ method one at a time for processing.
 
Good Luck!
LosintikfosLosintikfos
Quick one JimRae!
Your suggestion is exactly what i want to do but unfurtunatly keep getting error;

Save error: Unsupported parameter type SOBJECT:Service__c  

After going through the apex language reference, i realised you can't pass SObject to @ future method, which is why i am kinda struggling at the moment.

I know the summer 2008 has been released, do i need to download a new version of wsdl to get this to work?


Expert ideas pls.
JimRaeJimRae

Actually,

Winter 09 release (api version 14) is out now, and you should be using the updated WSDL for your webservice.

Does your external WebService need to be executed before the Service__c is inserted into Salesforce? If you could do it after the insert/update, you could extract the ID of the Service__c object from the trigger and pass it as a string to the future method, and have that method, look up the data to pass to your callout.

Something like this, maybe:

Code:
global class ServiceAccount{
   @future 
     static void createServ(List<String> sid){

 //Service__c sd = new Service__c();
 
     for(Service__c sd : [select id,Rental__c,Billing_Alias__c,Frequency__c from Service__c where id in :sid]){  
        Boolean rental = sd.Rental__c;
        String alias = sd.Billing_Alias__c;
        String freq  = sd.Frequency__c;
  
            wsServiceAccount.ServiceAccountHttpSoap11Endpoint stub = new wsServiceAccount.ServiceAccountHttpSoap11Endpoint();
                   String call = stub.CreateService(rental, alias, freq);  
                   //return call;
      }
   }
}


trigger ServiceAccount on Service__c (after insert, after update) {
   List<String> sid=new List<String>();
   for(Service__c s : trigger.new){
 sid.add(s.id);
   }
   ServiceAccount.createServ(sid);
 
}


 This should allow your code to be more bulk safe, and limits you to one SOQL query even when a batch of items is processed.

Hope that helps.

LosintikfosLosintikfos
JimRae!

I am getting some invokation to my external service following the guidance above!



:smileywink:


Message Edited by Losintikfos on 10-15-2008 03:20 AM
LosintikfosLosintikfos
Hi JimRae!

I am passing date  to the external method;

Code:
Date start = sd.Start_Date__c;

and then pass start to external service like this;

stub.createServ(start);

Unfurtunately i am getting exception:

Debug Log:

System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: NumberFormatException date string can not be less than 19 charactors faultcode=soapenv:Server faultactor=


I am pretty sure i need to do something to the raw value of date before passing it to the remote method.
Do anyone know what to do?
JimRaeJimRae
From what I have read, you need to pass the date in this format: YYYY-MM-DDTHH:MM:SSZ.
So you will need to reformat your system date into that string format to get it to work.
Since your original date is not a datetime, you will need to convert it first, then get it formatted correctly.
 
 
Code:
Datetime start = datetime.newInstance(sd.Start_Date__c.year(),sd.Start_Date__c.month(),sd.Start_Date__c.day());

//and then pass start to external service like this

stub.createServ(start.format('YYYY-MM-DDTHH:MM:SSZ'));

 
LosintikfosLosintikfos
I end up changing the recieving parameter to string and did something like this;

Code:
String start = String.valueOf(sb.Start_Date__c);
 stub.createServ(start);

Which is pretty much what you've suggested! and did the job.


Thanks JimRae:smileywink: