+ Start a Discussion
Horst SchusterHorst Schuster 

A custom Button calculates but not update the fieldvalues

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?


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")


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. 

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;