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
tlaurietlaurie 

How to Update an Opportunity

Could you point me in the right direction.  I am able to query opportunities using a line of code like
 

Dim qr As apex.QueryResult = binding.query("Select Name, StageName, ProjectID__c from Opportunity Where StageName = 'Signed Engagement'")

 

Now I simply want to Update an opportunity using a query like

 

("UPDATE Opportunity SET ProjectID__c = '80xxx' WHERE Name = '" & opportunity.Name.ToString & "'")

 

but I am really stuck on the syntax.  What might it look like?

SuperfellSuperfell
query is just that, query. See the API docs for details on how to make data changes.
ad75ad75
SOQL is not as powerful as SQL.  Your example UPDATE syntax above is OK in SQL, but this type of syntax is not supported in SOQL.  If you think about it, behind the scenes your SQL example is doing two things.  Firstly it queries the database to find opportunities that match your WHERE clause.  Secondly it updates the ProjectID__C field on those records.  In SOQL you cannot do two things in one statement.  You have to query for the records first, then use the results of that to update the records in a second, separate update statement.

Hope this helps.  If you are new to SOQL it's well worth reading the 'Force.com webservices API developer's guide'.  It's a long doc but full of useful info.  You can find it using the search box at the top of this page.

Raj_SRaj_S
hi, U can try this code as it's working fine in for me but it is written in C#.

//In this first section i tried to retrieve id using some known information :
        #region Section 1
            WebReference.QueryResult queryResult = new Test_ExpocadProject.WebReference.QueryResult();
            queryResult = binding.query("select id from Account where name = 'XYZ', AccountNumber = '1', BillingAddress = ''");
            WebReference.Account acc_getid = new Test_ExpocadProject.WebReference.Account();
            acc_getid = (WebReference.Account)queryResult.records[0];
            string id = acc_getid.Id;
       #endregion

//In this section you can update using known id which u want
         #region Section 2
           Account acc_Object = new Account()  //But here i think u need to create Opportunity object in the same way.
            acc_Object.Note__c = txt_Note.Text;   //Here Note__c is my custom field which i want to update.
            acc_Object.Id = id;                                //this id is the known value.
         
            try
            {
                WebReference.SaveResult[] srArray1 = binding.update(new WebReference.sObject[] { acc_Object });
               
            }
        #endregion

** I thinkit should work... Just change it to VB code.



Raj S
boihueboihue
I'm also looking for some VB .NET codes to update the Salesforce object. Since I have started working in Salesforce, I found the inconvenience of the Salesforce system is Salesforce only pickup some pieces of others technologies to build its own system, the Apex Codes looks like C# and Java but not really C# nor Java, the SOQL looks like SQL but not a really SQL, too bad.
SuperfellSuperfell
There are samples in the API docs, and a quickstart guide for VB.net. see the API section of the wiki.
boihueboihue

Here're the codes how to update the Salesforce Account object using VB .NET:

' Create the new Account object to hold our changes

Dim upAccount As Account = New Account

' Need to have the Id so that the system knows which Account to update

upAccount.Id = "0015000000Oyn1A"

' Set a new value for the Billing City property

upAccount.BillingCountry = "Canada"

' Call the update passing an array of object

Dim SaveResults() As SaveResult = binding.update(New apex.sObject() {upAccount})