+ Start a Discussion
Gareth DaviesGareth Davies 

c# API 5.0: Problem Updating Custom (calculated) Field in Opportunity. (Urgent)


I am currenlty participating in a proof of concept with a potential Enterprise Client.

Problem: Want to Create custom fields in an Opportunity that are calculated from other fields.

Proposed Solution: Write a web service sitting at client site, triggered from a web-link which passes Opportunity ID.

Q1: How do I pass the OpporunityID as a parameter, from a web-link on the Opportunity Page?

Q2: I have written a c# test client. (currently searches for Opportunity by Name, to get hold of the object).

This works, allows me to gain access to the opportunity. I can query the values of two of the custom fields and from that calculate the other two.

When I set the value of the other two and update (using the API update method). The  custom fields do not update.

As a test I tried to update the NextStep attribute of the same object before calling update. This worked fine for the next step update, but still nothing on the custom fields.

I beleive that the downloaded WSDL file generates the proxy classes in VS OK as

a: the VS.NET intellisense contains the custom fields and

b: I can retreive custom values fine.


Any Suggestions much appreciated

Thanks, Gareth.



-- This is the Update Routine.




public static ArrayList oppList = new ArrayList();


oppList = connection.queryOpportunity (txtOppName.Text,howMany);




private void btnUpdateOp_Click(object sender, System.EventArgs e)


Opportunity opp;


opp=(Opportunity) oppList[0];

opp.PFM__c= System.Convert.ToDouble(txtPFM.Text);

opp.Commission__c =System.Convert.ToDouble(txtCom.Text);







public bool updateOpportunity(Opportunity pOp)



SaveResult[] saveResults = binding.update(new WebReference.sObject[] { pOp});



(Note SaveResult[0].Success == True)



Hi Gareth,

For double type fields you need to also set opp.PFM__cSpecified = true.  This is the case for any fields of type number or date and is only the case in .NET.  So for each double field you need to set the value as you are doing and also set this "sister" field to true to indicate to .NET the the value contained in your custom field is one that you have set (and not the default value) and you want it included in the soap message.

For any fields that you cannot set to null you will see a "sister" field xxxSpecified.  This will need to be set for your value to be sent to the web service.



Gareth DaviesGareth Davies


Fantastic. This will really help tomorrow's session. Fantastic answer and really quick!!!


Do you have any advice on triggering this calculation ?

Current proposed method is to wrap this up in a webservice which will be sent a message containing an Opportunity ID. Don't know how to pick that up and wrap into a dynamic URL yet.

Could we do this as an ActiveX control or something sitting in SF.com and executed in the browser? If this is a better way to do it where do I look for further reading on it?




Hi Gareth,

If I were you, I would do it as simply as possible.  This may preclude an activeX control depending on your proficiency with vb and the office toolkit.  The office toolkit is a com dll that "wraps" the web service and makes it easily useable from script and vb/vba.

If you were to go with an activeX control, I'd actually just look at doing it in vbscript using MSXML, and sorry, no -  I don't have a sample at hand.

The reason why I suggest you put no more effort into it than absolutely required to meet the minimum requirement is that we will soon (3-5 months) have calculated fields built into the app that will do exactly what you are trying to do and be triggered when a record is saved.

In the mean time you will want to "go" to a page that does the computation and the update then redirects you back to the page that you were on initially.  Don't be tempted to a "back" or anything that won't refresh the data on the page.


Gareth DaviesGareth Davies

Thanks Dave,

I had heard that calculated fields were in the pipeline. Therefore will take your advice and go with this solution.

Am I right in thinking that the weblink that would pass the ID for the opportunity as a parameter would look like:

href="http://somewere.com/?myvar={!ID" target=_blank>http://somewere.com?myvar={!ID}



Message Edited by Gareth Davies on 03-29-2005 04:39 PM


Hi Gareth,

Yes, but the syntax of the id field is important.  I believe for Opportunity it is {!Opportunity_ID}.

hold on, check precise syntax....

Yeah, that's the correct syntax.  To see what the syntax is for other fields, login to salesforce.com and click the Setup link.  It's in the upper right hand corner of the screen.

On the left side of the page, expand the Extend menu in the Studio section.  Click the sforce Controls item.  Click on New Item (big blue button at top of list).  You will see a UI that allows you to pick the object that you want to include as a merge field on your link.  So, if you pick Opportunity Fields in the drop down and then expand the drop down immediately to the right, you will see all the fields that you can send on the link. 

You should be able to send the fields that your calculation is based on, the Id of the oppty and the sessionId and server url.  These are the fields you will need to do the calculation and also to set up your connection back to salesforce.com web services for the update.


Gareth DaviesGareth Davies


Thanks a million.