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
Horst SchusterHorst Schuster 

A custom Button calculates but not update the fieldvalues

Hi,
i have create an custom button to change (calculate) Values in my own object. It seems a very good solution, but "overnight" the calculated values are not updated in the formula. What can be the reason for this problem. Have i changed a special flag anywhere in Salesforce which prevented the correct functionality?

{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")}

var aw = confirm ("Wollen Sie die Anpassung von Schwellenwert und \nHöchstbetrag jetzt vornehmen?")

if (aw == true) {

var qr = sforce.connection.query("SELECT Inflationsfaktor__c FROM Inflationsrate__c WHERE Name = '{!Rueckzahlungsjahr__c.Inflationszeitraum__c}'");

var qr2 = sforce.connection.query("SELECT Schwellenwert_exkl_Inflation__c, Jaehrlicher_Hoechstbetrag__c FROM Contract WHERE ContractNumber = '{!Rueckzahlungsjahr__c.Vertrag__c}'");

var records = qr.getArray("records");
var records2 = qr2.getArray("records");


var tempOb = new sforce.SObject("Rueckzahlungsjahr__c");
tempOb.Id = "{!Rueckzahlungsjahr__c.Id}";



//Schwellenwert infaltionieren
tempOb.tempSchwellenwert__c = records[0].Inflationsfaktor__c * records2[0].Schwellenwert_exkl_Inflation__c;

//Jährlichen Höchstbetrag inflationieren
//alert (records2[0].Jaehrlicher_Hoechstbetrag__c)
tempOb.Jaehrlicher_Hoechstbetrag__c = records[0].Inflationsfaktor__c * records2[0].Jaehrlicher_Hoechstbetrag__c;

//Flag setzen das Inflationierung erfolgt ist
tempOb.Schwellenwert_aktualisiert__c = true;

alert("Faktor: " + qr.records.Inflationsfaktor__c + " * " + "Basis-Schwellenwert: " + qr2.records.Schwellenwert_exkl_Inflation__c + " = " + tempOb.tempSchwellenwert__c + " EUR")

sforce.connection.update([tempOb]);

window.location.reload();
 
Akhil MehraAkhil Mehra
hi Horst Schuster;
I have  used same approach in my org. with following code and it work for me 

Note you have to query for  valid data ,fields  shouldn't  be blank to which you are query. 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
var caseRecords = sforce.connection.query("SELECT Id from User Where Name = '{!Case.Original_Case_Owner__c}'");
var records = caseRecords.getArray("records");
caseObj.OwnerId = records[0].Id;
sforce.connection.update([caseObj]);
window.location.reload();