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
Jancy MaryJancy Mary 

Simple Apex SOAP web service

Hi,

I am newbie to web services, I wrote a simple Apex class and made it as Apex SOAP web service, I tried to import the WSDL for my web service after importing the enterprise WSDL for my salesforce org on SOAP UI. Unfortunately I get the error as below,

Source: file:/C:/Users/Mvision/Desktop/New%20folder/SOAPTEST1.xml
Error: type 'RecordTypesSupported@http://soap.sforce.com/schemas/class/SOAPTEST1' not found.
Source: file:/C:/Users/Mvision/Desktop/New%20folder/SOAPTEST1.xml
Error: type 'RelationshipReferenceTo@http://soap.sforce.com/schemas/class/SOAPTEST1' not found.
Source: file:/C:/Users/Mvision/Desktop/New%20folder/SOAPTEST1.xml
Error: type 'SearchLayoutButtonsDisplayed@http://soap.sforce.com/schemas/class/SOAPTEST1' not found.
Source: file:/C:/Users/Mvision/Desktop/New%20folder/SOAPTEST1.xml
Error: type 'SearchLayoutFieldsDisplayed@http://soap.sforce.com/schemas/class/SOAPTEST1' not found.


Here is my code:

global with sharing class SOAPTEST1
{
webservice static List<Contact> OneCon(List<Contact> Con)
{
List<Contact> cc=[select Id, Name from Contact where SystemModStamp >=LAST_N_DAYS:30];
return cc;
}
}

I tried the same code last week and was able to get the expected result on SOAP UI, I remember that I did not make any changes to the code, not sure what went wrong since then I am unable to import the wsdl for this. I followed the below blog which gave me all clear explainations, but I am stuck with my code.

http://blog.deadlypenguin.com/blog/2012/02/03/salesforce-and-soapui/

Any help is much appreciated, thanks in advance:-)
James LoghryJames Loghry
If you include standard objects, sometimes it brings in dependencies on the enterprise wsdl that are difficult to resolve.  An easy solution to this would be to create a global inner class as a way to wrapper your results.  See below for an idea of how this would work:
 
global with sharing class SOAPTEST1{
    webservice static List<ContactWrapper> OneCon(List<Contact> Con){
        List<ContactWrapper> ans = new List<ContactWrapper>();
        for(Contact c : [select Id, Name from Contact where SystemModStamp >=LAST_N_DAYS:30]){
            ans.add(new ContactWrapper(c);
        }
        return ans;
     }

    global class ContactWrapper{
        webservice String contactId;
        webservvice String contactName;
        global ContactWrapper(Contact c){
            contactId = c.Id;
            contactName = c.Name;
        }
    }
}

 
pconpcon
To echo what James says, a wrapper class is the way to go.  I'd recommend reading over this [1] to learn more

[1] http://blog.deadlypenguin.com/blog/2015/03/09/web-services-development-salesforce/
Jancy MaryJancy Mary
Hi James & Patrick,

I tried the above code, I think I understood the line which you mentioned "define a global inner class as a way to wrapper your results", unfortunately I still get the same error even after trying with this updated code.

I went through Patrick's blog, but could not gather the information required for my understaing. May be it is higher level code or I am missing on something. I need your help on this again.  

Thank you very much for your time & response on this:-)
pconpcon
Once you used the updated code that James provided, did you regenerate your WSDL and update your definition inside of SoapUI?
Jancy MaryJancy Mary
Hi Patrick,

Yes, I regenerated the WSDL after saving the updated code in my org, then tried importing this new WSDL file on the SOAP UI. Unfortunately I got the same error again. I tried importing the new WSDL file while I have the enterprise wsdl already imported on the SOAP UI project.

I did the above after deleting all the existing wsdl files in my computer thinking if that matter for this issue.
 
Madhu 3027Madhu 3027
I want to insert multiple products and pricebooks and Pricebookentries in a single request using soap webservices.I tried with wrapper class .But not able create records in junction object.Here product and pricebook are(PARENTS) having many to many relationship.Pricebookentry(Child) is junction Object.Here is my code please help me.....
=================================================================================
global with sharing class PriceBookentry2 {
global class pricebookentryWrapper{
webservice product2 productid;
webservice pricebook2 pricebookid;
webservice double unitprice; }
global class productWrapper{
webservice String productName;
webservice boolean isActive;
webservice String ProductCode;
webservice String type;
webservice String category;
webservice Double price; }
global class pricebookWrapper{
webservice String pricebookName;
webservice boolean isActive;}
webservice static List<productwrapper> createProductPricebookPricebookEntry(List<productwrapper> productWrapperr,List<pricebookwrapper> pricebookWrapperr,List<pricebookentrywrapper> pricebookentryWrapperr){
List<product2> productsList=new List<product2>();
for(productWrapper product:productWrapperr){
Product2 products =new Product2();
products.name=product.productName;
products.Product_Type__c= product.type;
products.Product_Category__c= product.category;
products.Product_Price__c=product.price;
products.IsActive=true;
productsList.add(products);}
insert productsList;
List<pricebook2> priceBooks = new List<pricebook2>();
for(pricebookWrapper pricebook:pricebookWrapperr){
Pricebook2 pricebookss=new Pricebook2();
pricebookss.name=pricebook.pricebookName;
pricebookss.IsActive=true;}
priceBooks.add(pricebookss);
}
insert priceBooks;
/* Map<product2,pricebook2> ProductAndPricebookIDs=new Map<product2,pricebook2> ();
Product2 productIDs=[select id from product2 WHERE CreatedDate >:Datetime.now().addMinutes(-15)];
pricebook2 pricebookIDs=[select id from Pricebook2 WHERE CreatedDate >:Datetime.now().addMinutes(-15)];
ProductAndPricebookIDs.put(productIDs,pricebookIDs );
set<id> pid=new set<id>();
pid.addAll(ProductAndPricebookIDs.keySet());
List<pricebookentry> priceBookEntries = new List<pricebookentry>();
for(Map<product2,pricebook2> eachproductAndPricebook:ProductAndPricebookIDs){
PricebookEntry pbe=new PricebookEntry();
pbe.Pricebook2Id=eachproductAndPricebook.k
pbe.Product2Id=pricebookentry.productid;
pbe.UnitPrice=pricebookentry.unitprice;
}
} */
}
}