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
Brad007Brad007 

Apex callout to .Net Webservice.

Hi,

 

I added the .net WSDL file to my Apex project and also added the endpoint URL in Salesforce remote settings.

So now in the following class below i have a list of objects APImageslist.

So the WSDL2Apex calss is called as AJAXOrg and has a method GAPNetworkInages().

This is the method i need to calla and pass the APImageslist to check for the images.

Can any one suggest what to be done after and how would i be able to connect the Wsdl2apex class.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

public  class APImageUpdates {
  
  public static void APImagesMissing()
  {
    List<Contact> Apcontact = new List<Contact>();  
      
    // Create a List to store the Au Pair contacts who are missing image files
    List<AP_Application__c> APImageslist = new List<AP_Application__c>();  
      
    //Loop through Contacts for Available AuPairs 
    for(Contact contact: Apcontact) 
    {
      system.debug('Entered the List');      
      if(contact.AP_Status__c =='Available' && contact.RecordTypeId =='012300000000AHhAAM')
      {              
        for(AP_Application__c APApp: [Select Id,Au_Pair__c,IsExist_Photo1__c,IsExist_Photo2__c,IsExist_Photo3__c,IsExist_Photo4__c From AP_Application__c where Au_Pair__c =: contact.Id])
        {
          if(APApp.IsExist_Photo1__c == false || APApp.IsExist_Photo2__c == false || APApp.IsExist_Photo3__c == false || APApp.IsExist_Photo4__c == false)
          {
            System.Debug('AP missing an Image with contact id' +contact.id);
              APImageslist.add(APApp);
          }
          update APImageslist;
        }
      }
    }
     System.debug('List of APs missing images:' +APImageslist);  
    // AJAXOrg.AjaxSoap service = new AJAXOrg.AjaxSoap();  
    
  }
}

 

sdetweilsdetweil

edit the apex wsdl class source and look at the method parameters, its just like any other class..

 

create an instance of the class, then call the method thru the instance..

 

my calling code to my wsdl created web service looks like this

 

 wwwRtcdefectNew4.RTCDefect ws = new wwwRtcdefectNew4.RTCDefect();

                        String rc = ws.CreateItem(
                                       Synch,
                                       changedObjectNew.name,
                                       p.name,
                                       changedObjectNew.priority__c,
                                       changedObjectNew.severity__c,
                                       changedObjectNew.description__c, // should be description
                                       changedObjectNew.summary__c,
                                       u.pmfkey__c,               changedObjectNew.impact__c,                                            changedObjectNew.Circumvention__c,                                        changedObjectNew.HowToReproduce__c,                                       
                                       datetime.now() );   

and the wsdl class method prototype looks like this

public String CreateItem(Boolean calltype,
String problem,
String product,
String priority,
String severity,
String description,
String summary,
String author,
String impact,
String howtorecreate,
String circumvention,
DateTime created);
    

 

Brad007Brad007

HI, 

 

thank you for your response.

 

Yes i have instantiated the method as you suggested. And i am calling the method passing a dummy string as the method in the service is declared to take a string. My objectiuve here is once i update the list APImagefiles with the records . Should they be passed as a string or can they be also passed as a list object(if i would change the return type in the service to List object too).

what should be the practice if i wanna pass a list object with records to services and if they shold be passed only as strings what should i do next to convert the list object to strings. Also how would i be able to debug with my service once its passed.

 

Please suggest..

 

}

public  class APImageUpdates {
  
  public void APImagesMissing()
  {
    string Test;
    List<Contact> APContacts = new List<Contact>();
    List<AP_Application__c> APImagefiles = new List<AP_Application__c>();  
      
    //Loop through Contacts for Available AuPairs 
    for(Contact contact: APContacts) 
    {
      system.debug('Entered the List');      
      if(contact.AP_Status__c =='Available' && contact.RecordTypeId =='012300000000AHhAAM')
      {              
        for(AP_Application__c APAppObj: [Select Id,Au_Pair__c,IsExist_Photo1__c,IsExist_Photo2__c,IsExist_Photo3__c,IsExist_Photo4__c From AP_Application__c where Au_Pair__c =: contact.Id])
        {
          if(APAppObj.IsExist_Photo1__c == false || APAppObj.IsExist_Photo2__c == false || APAppObj.IsExist_Photo3__c == false || APAppObj.IsExist_Photo4__c == false)
          {
            System.Debug('AP missing an Image with contact id' +contact.id);
              APImagefiles.add(APAppObj);
          }
          update APImagefiles;
        }
      }
    }
     System.debug('List of APs missing images:' +APImagefiles);  
     
     //Create the Stub
     AJAXOrg.AjaxSoap service = new AJAXOrg.AjaxSoap();  
     
     // Make the Web service call      
       String output = service.GAPNetworkImages(Test);
    
  }

 


sdetweilsdetweil

as long as u never need to call this web service from a trigger, you can pass a List of objects.

 

here is how the web service was created with the Wsdl Import tool in SFDC

public String UpdateItem(String problem,String status,String severity,String priority,String impact,String circumvention,String howtoreproduce,wwwCaComRtcdefectNew4.wsCase[] cases,wwwCaComRtcdefectNew4.wsComment[] comments,wwwCaComRtcdefectNew4.wsAttachment[] attachments) {

 

 

note that last three parms are defined as 'arrays' of objects.

 

calling a future method does not support complex objects.. so I had to build these IN the future method..

my wsdl defined those object definitions.

 

    private static List<wwwCaComRtcdefectNew4.wsAttachment> attachmentList(String problem_number)
    {
          List<wwwCaComRtcdefectNew4.wsAttachment> attachmentlist = new List<wwwCaComRtcdefectNew4.wsAttachment>();
          integer i = 1;
          for (Attachment a:[select Description, CreatedDate,CreatedbyID, isDeleted,Name  from Attachment where parentid =:[select id from Problem__c where name=:problem_number ].id and isDeleted = false order by CreatedDate asc])
          {

               wwwRtcdefectNew4.wsAttachment ac= new wwwRtcdefectNew4.wsAttachment();
               ac.Name = a.Name;
               ac.DateTime_x = a.CreatedDate;
               ac.description=a.Description;
               attachmentlist.add(ac)  ;
            
          }
          return attachmentlist;        
    }

 here is the WSDL type

      <xsd:complexType name="wsAttachment">
      	<xsd:sequence>
      		<xsd:element maxOccurs="1" minOccurs="1" name="DateTime" type="xsd:dateTime"/>
      		<xsd:element maxOccurs="1" minOccurs="1" name="name" type="xsd:string"/>
      		<xsd:element maxOccurs="1" minOccurs="0" name="description" type="xsd:string"/>
      	</xsd:sequence>
      </xsd:complexType>

 and the method in the WSDL

      <xsd:element name="UpdateItem">
      	<xsd:complexType>
      		<xsd:sequence>
      			<xsd:element maxOccurs="1" minOccurs="1" name="problem" type="xsd:string">
      			</xsd:element>
      			<xsd:element maxOccurs="1" minOccurs="1" name="status" type="xsd:string"/>
      			<xsd:element maxOccurs="1" minOccurs="0" name="severity" type="xsd:string">
      			</xsd:element>
      			<xsd:element maxOccurs="1" minOccurs="0" name="priority" type="xsd:string">
      			</xsd:element>

      			<xsd:element maxOccurs="1" minOccurs="0" name="impact" type="xsd:string">
      			</xsd:element>
      			<xsd:element maxOccurs="1" minOccurs="0" name="circumvention" type="xsd:string">
      			</xsd:element>
      			<xsd:element maxOccurs="1" minOccurs="0" name="howtoreproduce" type="xsd:string"/>
                        <xsd:element maxOccurs="unbounded" minOccurs="1" name="cases" type="dft:wsCase"/>
                        <xsd:element maxOccurs="unbounded" minOccurs="0" name="comments" type="dft:wsComment">
      			</xsd:element>
      			<xsd:element maxOccurs="unbounded" minOccurs="0" name="attachments" type="dft:wsAttachment"> </xsd:element>
      		</xsd:sequence>
      	</xsd:complexType>
      </xsd:element>