+ Start a Discussion
bujjibujji 

Regarding Webservice

Hi Guys,

 

My requirement is like this i need to get all the updates contacts on the daily basis.

I have the qurey also can anybody send me the webservice class how it look like.

 

My query is SELECT Id,Name,LastModifiedDate  FROM Contact  WHERE LastModifiedDate = TODAY
                                                                                                                                   AND CreatedDate != TODAY

 

Thanks,

Bujji

Navatar_DbSupNavatar_DbSup

Hi,

 

First of all upload Partner API in the org where you need to access the code.

Here the when you click "Generate from WSDL" button (Setup-> App Setup->Develop->Apex Classes), then it generate 3 classes in your org .They are

 

1. faultPartnerSoapSforceCom

2. partnerSoapSforceCom

3. sobjectPartnerSoapSforceCom

 

Now Edit classes "sobjectPartnerSoapSforceCom" for the field that you need to access .Like add these statements to code in “sobjectPartnerSoapSforceCom” class.

 

public String Name;

        private String[] Name_type_info = new String[]{'Name','urn:partner.soap.sforce.com','string','1','1','true'};

        public String Languages;

        private String[] Languages_type_info = new String[]{'Languages__c','urn:partner.soap.sforce.com','string','1','1','true'};

        public String FirstName;

        private String[] FirstName_type_info = new String[]{'FirstName','urn:partner.soap.sforce.com','string','1','1','true'};

        public String LastName;

        private String[] LastName_type_info = new String[]{'LastName','urn:partner.soap.sforce.com','string','1','1','true'};

        public String Email;

        private String[] Email_type_info = new String[]{'Email','urn:partner.soap.sforce.com','Email','1','1','true'};

        public String LastModifiedDate  ;

        private String[] LastModifiedDate_type_info = new String[]{'LastModifiedDate','urn:partner.soap.sforce.com','DateTime','1','1','true'};

 

 

Now you can do query from this Partners WSDL.

Use the below code snippet as reference:

 

<apex:page controller="WSDLContacts" >

  <apex:form id="f1" >

 <div id="shw_con" style="display:block;" >

     <apex:outputpanel id="pp">

     <apex:pageMessages id="shwmsg"/>

         <table border="0">

         <caption><h3><font color="grey">Org 1 Contacts</font></h3></caption>

         <tr bgcolor="#d7ecf3">

             <th>FirstName</th>

             <th>LastName</th>

             <th>Email</th>

             <th>Language</th>

             <th>LastModifiedDate</th>

         </tr>

         <apex:repeat value="{!wrapList}" var="k">

         <tr bgcolor="#d9dff0">

             <td>{!k.fname}</td>

             <td>{!k.lname}</td>

             <td>{!k.Email}</td>

             <td>{!k.lang}</td>

             <td>{!k.lstModDte}</td>

             </tr>

       

       

         </apex:repeat>

     </table>

     </apex:outputpanel>

     </div>

     </apex:form>

</apex:page>

 

===============================Apex Controller===============================

 

public class WSDLContacts {

public List<Contact> ct1{get;set;}

public class WrapperContact

    {

         public string id{get;set;}

         public string fname{get;set;}

         public String lname{get;set;}

         public String email{get;set;}

         public String lang{get;set;}

         public String lstModDte{get;set;}      

    }

   

public List<WrapperContact> wrapList{get;set;}

 

public WrapperContact wrpCon{get;set;}  

  

public WSDLContacts()

{

    AccessDirectly();

}

 

public void AccessDirectly()

{

     try

     {

         string us='1DRR@abc.com';

         string ps='drr1test123';

         System.debug('________AccessDirectly_________usrnme______'+us+'____________passwrd______'+ps);

         partnerSoapSforceCom.soap conn1= new partnerSoapSforceCom.soap();

         conn1.SessionHeader = new partnerSoapSforceCom.SessionHeader_element ();

         partnerSoapSforceCom.LoginResult loginResult1 = new partnerSoapSforceCom.LoginResult();

         partnerSoapSforceCom.LoginScopeHeader_element ls1=new partnerSoapSforceCom.LoginScopeHeader_element();

         conn1.LoginScopeHeader=ls1;

         loginResult1 =conn1.login(us,ps);

         conn1.endpoint_x =loginResult1.ServerUrl;

         system.debug('_______AccessDirectly________loginResult1.ServerUrl________________________'+loginResult1.ServerUrl);

         conn1.Sessionheader.sessionid = loginResult1.sessionid;

         partnerSoapSforceCom.queryResult qr1 = new partnerSoapSforceCom.queryResult();

          system.debug('__________________________queryResult ____size1__________________'+qr1.size);

         qr1=conn1.query('SELECT id,Name,LastName,Email,Languages__c,LastModifiedDate  FROM Contact WHERE LastModifiedDate = TODAY AND CreatedDate != TODAY');

        

         wrapList=new List<WrapperContact>();

         wrapList.clear();

         system.debug('__________________________wrapList____size1__________________'+wrapList.size());

         system.debug('__________________________queryResult ____size2__________________'+qr1.size);

        

         for (sobjectPartnerSoapSforceCom.sObject_x obj : qr1.records)

            {

             //   system.debug('_______________Id_________' + obj.Id+'________Name______'+obj.Name+'___Lang____'+obj.Languages);

                 wrpCon=new WrapperContact();

                 wrpCon.id=obj.id;

                 wrpCon.fname=obj.Name;

                 wrpCon.lname=obj.LastName;

                 wrpCon.email=obj.Email;

                 wrpCon.lang=obj.Languages;

                 wrpCon.lstModDte=obj.LastModifiedDate;

                 wrapList.add(wrpCon);

                

            }

         system.debug('__________________________wrapList____size2__________________'+wrapList.size());

         system.debug('__________________________wrapList______________________'+wrapList);

        

     }

    catch(Exception e)

    {

        System.debug('________AccessDirectly_________Exception_________________________'+e.getMessage());

               

    }

}

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

bujjibujji

HI Navatar,

 

I generated partner wsdl and while trying to create apex class using 'generate wsdl' option than

it showing some error like ' unexpected token "delete" 672:51 and only two classes generated.

And i think it is like consuming wsdl in salesforce.

 

But what i want is salesforce apex class has to be exposed so that some datawarehousing guys can consume our wsdl.

 

Here I am sending my class, Please check whether it is correct or not. I have written this for getting updated contacts

on daily basis.

 

I want this to be expose and used by third party. Please tell me the procedure how it can be achieved and tested as well.

 

global class getUpdatedContact{

WebService static List<Contact> getContactInfoModifiedToday()
{

    List<Contact> Upcon = new List<Contact>();
    
    Upcon = [SELECT Id,Name,LastModifiedDate 
               FROM Contact 
               WHERE LastModifiedDate = TODAY
               AND CreatedDate != TODAY];
               
    return Upcon;
}
}
magulanmagulan

Hi,

Where should I add the following code

        //Start
        public String AcctName;
        private String[] AcctName_type_info = new String[]{'AcctName','urn:partner.soap.sforce.com','string','1','1','true'};
        public String ExtID;
        private String[] ExtID_type_info = new String[]{'ExtID','urn:partner.soap.sforce.com','string','1','1','true'};
        public String Phone;
        private String[] Phone_type_info = new String[]{'Phone','urn:partner.soap.sforce.com','string','1','1','true'};
        //end

 

 

Please tell me the exact class to add. i.e under partnerSoapSforceCom.soap class, where should I add.