3

I created the APEX class from the WSDL of an ASP.NET asmx service, this now gives me access to the types and methods provided by my service.

One of the methods takes in a List of objects described by the method: (ex: ASP.NET method)

[XmlInclude(typeof(List))]
[WebMethod(Description = "Consumes a list of changes from Salesforce.")]
        public void NotifyChanges(List<SalesforceChangeType> changes)
        {
            foreach (var changeType in changes)
            {
                log.Info(string.Format("Type:{0}, Id:{1}", changeType.ChangeType, changeType.EntityId));
            }
        }

I am trying to call this web service but when the APEX class was generated it created a type of ArrayOfSalesforceChangeType which is also the argument for the method.

TriggerService.SalesforceChangeType change = new TriggerService.SalesforceChangeType();

TriggerService.ArrayOfSalesforceChangeType changes = new TriggerService.ArrayOfSalesforceChangeType();

TriggerService.TriggerServiceSoap svc = new TriggerService.TriggerServiceSoap();

changes.add(change) <-- doesn't work, reports "Method doesn't exist or incorrect signature" 

// changes[0] = change; <-- doesn't work either "Expression must be a list type: Service.ArrayofSalesforceChangeType"

svc.NotifyChanges(changes);

So my question is how do I add items to a custom List that was generated from the APEX generated WSDL..

Hope this makes sense to someone..

Thanks

  • Can you post a link to a Gist of the WSDL and the generate Apex class please? – Andrew Fawcett Apr 24 '13 at 0:04
2

The apex class for ArrayOfSalesforceChangeType will appear something like:

public class ArrayOfSalesforceChangeType {
    public ApexClassForWSDL.SalesforceChangeType[] SalesforceChangeType;
    private String[] SalesforceChangeType_type_info = new String[]{'SalesforceChangeType','http://webservice/api','SalesforceChangeType','0','-1','true'};
    private String[] apex_schema_type_info = new String[]{'http://webservice/api','true','false'};
    private String[] field_order_type_info = new String[]{'SalesforceChangeType'};
}

You will need to add the records to the SalesforceChangeType member.

E.g.

TriggerService.ArrayOfSalesforceChangeType changes = new TriggerService.ArrayOfSalesforceChangeType();
TriggerService.SalesforceChangeType change = new TriggerService.SalesforceChangeType();
changes.SalesforceChangeType = new List<SalesforceChangeType>();
changes.SalesforceChangeType.add(change);
  • Thanks... exactly what I was looking for, got caught up with the naming convention ArrayOf and stopped there. – Rick Apr 24 '13 at 15:28
  • @FishOfPrey I have been facing the same issue, Thanks for the solution. But for the line, changes.SalesforceChangeType.add(change); I am getting an exception, 'Attempt to de-reference a null object'. I am unable to add the change in SalesforceChangeType. – logan Jan 5 '18 at 8:21
  • @logan the internal list/array needs to be initialized before adding the new change instance. – Daniel Ballinger Jan 7 '18 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.