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

Adding Opportunities

Hi, firstly let me say that i have been thrown in at the deep end by my boss and given a task that i dont have a clue how to complete!! any help would be great!

The task is to create a procedure that allows me to enter oppurtunities into our salesforce database using script. I've looked all around for examples of how to do this, but cant find anything that could help. I'm a complete first timer when it comes to anything like this and i dont have a clue what i'm doing.

Is there anyone who could help me by giving me a sample procedure that enters an opportunity?



Hi andyex,

First, clarify what your environment is.  In your post you request a script.  ????  Are you looking for a vb .Net sample or a vbscript sample?  Or maybe something else altogether?

sorry, been ill. i'd like a sample. i'm using the ide

just had it changed by my boss. could i have a sample in C# now? i cant an example anywhere




Hi andyex, we have plenty of samples in the Toolkits & Samples section of this site.


yeah, i've downloaded that, but there's no sample for adding a new opportunity in that download. I've looked at the online help aswell, and i cant see how to addapt the sample files so that they add an opportunity instead of a contact or account etc.

Any help or pointers would be gratefully recieved


Hi andyex,

The samples are meant to demonstrate a common methodology rather than a specific sample for each kind of entity.

To create an opportunity using the c# samples as a starting point you would create Opportunity object like so:

sforce.Opportunity oppty = new sforce.Opportunity;

Then set the field values on the opportunity like so:

oppty.Name = "My Opp";

and so on till you have set all the available data on the opportunity.

From here it is exactly like the sample (I don't have the code in front of me so be kind).

sforce.SaveResult saveresult = binding.create(new sforce.SObject[] {oppty});


It doesn't matter which object you are creating, the pattern is the same.  This web service is very, very flexible and straightforward.  Its the operations or methods that you need to wrap your head around, not the specific objects themselves.


thanks alot for your help!

I'm also floundering in the deep end with this task. In trying to follow the advice above I've come up with this code whichis an attempt to clone from a routine that creates a new Contact:

//salesForce.sforce.Contact contact = new salesForce.sforce.Contact();     
// code above is from a successful Contact creation routine
salesForce.sforce.Opportunity oppty = new salesForce.sforce.Opportunity();

oppty.Name="Zee Basic";
oppty.Type="New Subscriber";
oppty.StageName="New Subscriber";
oppty.Description="Created at signup";

// Add the opportunity to an array of SObjects
salesForce.sforce.sObject[] opptyRecords = new salesForce.sforce.sObject[] {oppty};

//salesForce.sforce.SaveResult[] saveContactResults = binding.create(contactRecords);
salesForce.sforce.SaveResult[] saveOpptyResults = binding.create(opptyRecords);

That's as far aas I've gotten. The code doesn't produce an error but it also doesn't seem to add a new Opportunity to the Contact or their Account



you need to examine the saveOpptyResults[0] object to find out the status of your create call.

Dont you have to set a CloseDate attribute? I think this one is obligatory.