1

I have written a webservice to be called from salesforce. I generated a class from wsdl:

//Generated by wsdl2apex

public class SFtoACSApex {    

    public class ArrayOfAccountInfo {
        public SFtoACSApex.AccountInfo[] AccountInfo;
        private String[] AccountInfo_type_info = new String[]{'AccountInfo','http://tempuri.org/',null,'0','-1','true'};
        private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true','false'};
        private String[] field_order_type_info = new String[]{'AccountInfo'};
    }
    public class AccountInfo {
        public String AccountNumber;
        public String AccountName;
        private String[] AccountNumber_type_info = new String[]{'AccountNumber','http://tempuri.org/',null,'0','1','false'};
        private String[] AccountName_type_info = new String[]{'AccountName','http://tempuri.org/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true','false'};
        private String[] field_order_type_info = new String[]{'AccountNumber','AccountName'};
    }
    public class AccountSelect_element {
        public String sAccount;
        private String[] sAccount_type_info = new String[]{'sAccount','http://tempuri.org/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true','false'};
        private String[] field_order_type_info = new String[]{'sAccount'};
    }
    public class AccountSelectResponse_element {
        public SFtoACSApex.ArrayOfAccountInfo AccountSelectResult;
        private String[] AccountSelectResult_type_info = new String[]{'AccountSelectResult','http://tempuri.org/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true','false'};
        private String[] field_order_type_info = new String[]{'AccountSelectResult'};
    }
    public class SFtoACSSoap {
        public String endpoint_x = 'http://mywebsite.com/WebServices/myservice.asmx';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://tempuri.org/', 'SFtoACSApex'};
        public SFtoACSApex.ArrayOfAccountInfo AccountSelect(String sAccount) {
            SFtoACSApex.AccountSelect_element request_x = new SFtoACSApex.AccountSelect_element();
            request_x.sAccount = sAccount;
            SFtoACSApex.AccountSelectResponse_element response_x;
            Map<String, SFtoACSApex.AccountSelectResponse_element> response_map_x = new Map<String, SFtoACSApex.AccountSelectResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://tempuri.org/AccountSelect',
              'http://tempuri.org/',
              'AccountSelect',
              'http://tempuri.org/',
              'AccountSelectResponse',
              'SFtoACSApex.AccountSelectResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.AccountSelectResult;
        }

    }
}

Then I created a controller class:

public class SFCallWebService
{
    SFtoACSApex.ArrayOfAccountInfo dc = new SFtoACSApex.ArrayOfAccountInfo();
    public List<SFtoACSApex.AccountInfo> getAccInfo() 
    {        
        SFtoACSApex.SFtoACSSoap sf = New SFtoACSApex.SFtoACSSoap();
        dc = sf.AccountSelect('10272');        
        List<SFtoACSApex.AccountInfo> al = new List<SFtoACSApex.AccountInfo>();        
        al.add(dc.AccountInfo[0]);      
        return al;
    }

     public String getAName() {        
          Account sAcct = [select Retailsite_ID__c from Account
                         where id = 
                         :System.currentPageReference().getParameters().get('id')];   
        SFtoACSApex.SFtoACSSoap sf = New SFtoACSApex.SFtoACSSoap();
        SFtoACSApex.ArrayOfAccountInfo dc;
        dc = sf.AccountSelect(sAcct.Retailsite_ID__c);

        return dc.AccountInfo[0].AccountNumber + ' ' + dc.AccountInfo[0].AccountName;
    }
}

I can retrieve info from both on my VF page:

 <apex:page controller="SFCallWebService" tabStyle="Account">
    This is the info {!aname}
    This is the detailed info {!AccInfo}    
    </apex:page>

But when I do:

 <apex:page controller="SFCallWebService" tabStyle="Account">
    This is the info {!aname}
    This is the detailed info {!AccInfo.AccountName}    
    </apex:page>

I get error:

Unknown Property 'VisualforceArrayList.AccountNumber'

I would like to display the info on a VF page - and ultimately have much more info displayed - in a table or something...I don't know what yet, but I figured I will decide that once I can access the properties.

I think I have looked at it too long and it is something obvious, but now I cannot see it. This is my first time posting here and second day working with Salesforce so I apologize if this post is a mess!

Thank you for your help!

Edit: Thanks Scott! I thought of the AccountName as being a property of AccountInfo...Is this just a syntax thing? Like I said, I am new to this (bear with me) so I am trying to wrap my brain around how to access it. Am I allowed to return a List of objects and then access the items of the object? Much like using a datatable and getting the columns from it. Is that not how it is done here? If so, could you please provide an example...I have tried every possibility that I can think of...

This is the detailed info {!AccInfo[0].AccountName} does not throw an error in the Developer Console, but it does on the VF page...

  • The variable AccInfo on your VF is getting assigned as a List<SFtoACSApex.AccountInfo>, the property AccountNumber doesn't exist. You need to access the element within the array first. – ScottW Sep 19 '14 at 19:34
  • ScottW, you can make an answer out of that. Doing so will allow others to upvote :-) – Samuel De Rycke Sep 22 '14 at 19:48
2

Looks like WSDL2Apex does not generate the Setters and the Getters. Try setting them manually. This is what solved it for me

public class SFtoACSApex {

public class ArrayOfAccountInfo {
    public SFtoACSApex.AccountInfo[] AccountInfo;

becomes:

public class SFtoACSApex {    

public class ArrayOfAccountInfo {
    public SFtoACSApex.AccountInfo[] AccountInfo{get;Set;}

and so on for each property.

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.