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
sfdcianesfdciane 

webservice class to insert a record in the Account Object

Hi All,

 

 

I need to create a webservice class which need to be  invoked and an account should be created in the account object..

 

 

Thanks In Advance,

SFDCIANE

 

Shivaji SShivaji S

Hi sfdciane

 

You can directly use standard API provided by Salesforce to create Account and that is

 

'/services/data/v20.0/sobjects/Account' and set Account fields as key value pair in Http request body.

 

Thanks,

Shivaji S

sfdcianesfdciane

Thanks for ur reply i dont have much knowledge  can you please eloborate it

Madhu3006Madhu3006

Once u generate the stubs using axis

Pl add this code  and it wil inser the record

 

package com.sforce.soap.classes;

//import com.org.salesforce.Login.Insertrecords;
import java.rmi.RemoteException;

import javax.mail.Session;
import javax.xml.rpc.ServiceException;
import javax.xml.ws.soap.SOAPBinding;

import org.apache.woden.wsdl20.xml.ServiceElement;

import com.sforce.bulk.UpdateResult;
import com.sforce.soap.enterprise.LoginResult;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.SaveResult;
import com.sforce.soap.enterprise.SforceServiceLocator;
import com.sforce.soap.enterprise.SoapBindingStub;
import com.sforce.soap.enterprise.AssignmentRuleHeader;
import com.sforce.soap.enterprise.SessionHeader;
import com.sforce.soap.enterprise.SforceServiceStub.DeleteResult;
import com.sforce.soap.enterprise.fault.LoginFault;
import com.sforce.soap.enterprise.fault.UnexpectedErrorFault;
import com.sforce.soap.enterprise.sobject.Account;
import com.sforce.soap.enterprise.sobject.Lead;
import com.sforce.soap.enterprise.sobject.SObject;
import com.sforce.ws.wsdl.Binding;

public class Insertaccount {

    private static final SObject Insertaccount = null;
    /**
     * @param args
     */
    static Insertaccount _Accountinsert;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        _Accountinsert=new Insertaccount();
        try{
            _Accountinsert.createAccountInsert();
        }catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }
    public void createAccountInsert() throws UnexpectedErrorFault, LoginFault,
    RemoteException
    {
        try {
            SoapBindingStub binding= (SoapBindingStub) new SforceServiceLocator().getSoap();
            LoginResult lr=binding.login("XX", "XX");
            //Reset the binding to use the endpoint returned from login
            
            String Seid=lr.getSessionId();
            System.out.println("seesion Id is"+Seid);
            binding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, lr.getServerUrl());
            //Create the session id header, and add it to the proxy binding
            SessionHeader sh=new SessionHeader();
            /*SessionHeader shd=new SessionHeader();
            shd.setSessionId(sessionId)*/
            sh.setSessionId(lr.getSessionId());
            
            System.out.println();
            binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(),"SessionHeader",sh);
        
            
            //create a account
            Account _acct = new Account();
            _acct.setName("WEBSERVICERECORD1");
            _acct.setWebsite("www.abc.com");
            _acct.setAccountNumber("123");
            //String obs = new s.sOfobject[] {newaccount};
            SObject account = new Account();
            
            SaveResult[] sr = binding.create(new SObject[] {_acct});
            //com.sforce.soap.enterprise.SaveResult[] sr =binding.create((new SObject[] {Account}));
            //com.sforce.soap.enterprise.DeleteResult[] sr=binding.delete("0019000000Lp1jM");
            
            
                    for (int i=0;i<sr.length;i++) {
                            if (sr[i].isSuccess()) {
                    System.out.println("Successfully created lead with id of: "+_acct.getId());
                    //sr[i].getId().getValue() + ".");
                    }
                    else {
                    System.out.println("Error creating lead: " +sr[i].getErrors(0).getMessage());
                    }
                    }
            
            //String acctid=_acct.getId();
            //System.out.println("Acctid"+acctid);
            System.out.println("Accounr Crceated Sucefully!!");
            
            binding.clearHeaders();
            binding.setHeader(
            new SforceServiceLocator().getServiceName().getNamespaceURI(),
            "SessionHeader", sh);
            } catch (ServiceException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println("Error Occured"+e);
            
        }
            
    }
}

 

Pl let me know if it works

 

Regards

Madhu

sfdcianesfdciane

Thanks fr ur reply    how to genarate the stubs

Madhu3006Madhu3006

Download the axis 1.2 jar from tomcat website and go to windows and preference's search for axis add the jar once u add the jar you will be displayed with message like successfully or not

and the enterprise wdl and generate the client.

That will create all the stubs .

 

Regards

Madhu