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
Rolando EstevesRolando Esteves 

Problem updating Fields

Hi,

 

I have a string field on the opportunity object that I am trying to update with the salesforce Enterprise API. My opportunity is Closed Won. For some reason I do not see the update on the field.

 

Heres my VB Code:

 

    Private Sub queryProject()

        Dim oppProjectQuery As String
        Dim cnct As String

        oppProjectQuery = "Select B.AccountId, B.OpportunityID__c, B.Name, B.CloseDate, B.Account_Manager_Name__c, B.Sales_Location2__c, B.PO__c, Amount, B.Total_Opp_Profit_Amount__c, B.Total_Quantity__c, B.TaxAmount__c From Opportunity B "
        oppProjectQuery = oppProjectQuery & " WHERE B.StageName = 'Closed Won' AND B.TransferContract2GP__c = false"
        'get a list of acctIds


        Dim a_Opp(0) As netxarEE.sObject
        'Sql(Connection & Statements)
        Try
            con.ConnectionString = constr
            con.Open()
        Catch ex As Exception
            MsgBox("Error while establishing connection..." & ex.Message & "Insert Records")
        End Try

        Try
            'get a list of oppLineItems
            Dim oppQR As QueryResult = Nothing
            oppQR = binding.query(oppProjectQuery)
            For i As Integer = 0 To oppQR.records.Length - 1
                Dim opp As Opportunity = oppQR.records(i)
                Dim insProjectQuery As String

                'Obtaining Contact Name
                Dim contactName As String
                cnct = "SELECT A.NAME FROM CONTACT A "
                cnct = cnct & " Where A.AccountId IN ('" & opp.AccountId & "') LIMIT 1"
                Dim contacto As QueryResult = Nothing
                contacto = binding.query(cnct)
                Dim cnt As Contact = contacto.records(i)
                contactName = cnt.Name

                'Obtaining Customer Number
                Dim custNum As String
                custNum = "SELECT A.Customer_ID__c FROM Account A "
                custNum = custNum & " Where A.Id IN ('" & opp.AccountId & "') LIMIT 1"
                Dim customer As QueryResult = Nothing
                customer = binding.query(custNum)
                Dim cus As Account = customer.records(i)
                custNum = cus.Customer_ID__c

                'Forming Insert Query in order Fill PROJECTQTBLE
                insProjectQuery = "INSERT INTO PROJECTQTBL VALUES ('"
                insProjectQuery = insProjectQuery & custNum & "'" & ","
                insProjectQuery = insProjectQuery & "'" & opp.OpportunityID__c & "'" & ","
                insProjectQuery = insProjectQuery & "'" & opp.OpportunityID__c & "'" & ","
                insProjectQuery = insProjectQuery & "'" & opp.Name & "'" & ","
                insProjectQuery = insProjectQuery & "'" & opp.CloseDate & "'" & ","
                insProjectQuery = insProjectQuery & "'" & opp.CloseDate & "'" & ","
                insProjectQuery = insProjectQuery & "'" & opp.Total_Quantity__c & "'" & ","
                insProjectQuery = insProjectQuery & "'" & opp.Amount & "'" & ","
                insProjectQuery = insProjectQuery & "'" & opp.Total_Opp_Profit_Amount__c & "'" & ","
                insProjectQuery = insProjectQuery & "'" & contactName & "'" & ","
                insProjectQuery = insProjectQuery & "'" & opp.Sales_Location2__c & "'" & ","
                insProjectQuery = insProjectQuery & "'" & opp.TaxAmount__c & "'" & ","
                insProjectQuery = insProjectQuery & "'" & uFlag & "'" & ")"
                cmd = New SqlCommand(insProjectQuery, con)
                'Executing Dynamic Query
                cmd.ExecuteNonQuery()
                ReDim a_Opp(i)
                'Code in order to update the account
                Dim oppor As New Opportunity
                oppor.Id = oppQR.records(i).Id
                oppor.TransferProject2GP__c = "Sucess"
                a_Opp(i) = oppor
            Next
            login()
            binding.update(a_Opp)
            con.Close()
        Catch ex As Exception
            MsgBox("Project do not meet criteria or System is already Synced..." & ex.Message & "Querying Records")
        Finally
            con.Close()
        End Try

    End Sub