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

Salesforce to salesforce account creation

I want to create account or oppty from one salesforce account to another using apex class.


Pls help me.




You can create a trigger on account to create account.

trigger accountTrigger on account (after insert)


    // Define connection id

    Id networkId = ConnectionHelper.getConnectionId();

    system.debug('!!!!!!!!'+networkId );

    PartnerNetworkRecordConnection newConnection =  new PartnerNetworkRecordConnection( ConnectionId = networkId,  LocalRecordId =[0].Id, SendEmails = true);

    insert newConnection;





For this you first need to integrate the two salesforce org. Here you can make use of Partner WSDL (App Setup ->Develop -> API -> Partner WSDL). It will help you in creating connection also in accessing data from various objects.

Partner WSDL: A loosely typed WSDL for customers, partners, and ISVs who are building client applications for multiple organizations. It can be used to access data within any organization.


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




Hi ,

Suppose you want to create field on Account object in Org A from Org B.Get the Partner WSDL,Metadata WSDL of Org A , parse those and generate the apex classes.

Before generating the classes from Metadata WSDL ,n metadata WSDL,scroll down and change
        <port binding="tns:MetadataBinding" name="Metadata">
name attribute to a different name.Generate the class.


Go to the class genetated from the metadata wsdl.For creating field:go to the 'metadata' class..add virtual keyword to it(as it has the property of fullname which is the name of each field created and it has to be manually extended to the 'customfield' class).From  'customfield' class,extend the metadata class.override the fullname property by adding it,and its type info,and metadata attr info.


.Partner WSDL is required to make the connection.Use Login() of Partner WSDL to login into Org A ,get the sessionId.Create an instance of Metadata WSDL class and in its header set the sessionid as the above sessionid.

Instantiate the createfield class of the metadata class and create the field with the required fields value.and call it..Lastly dont forget to add the proper url to the remote site settings and..njoy  :)