+ Start a Discussion
b.gonzalezb.gonzalez 

Custom Button on Case object not updating record?

I have a custom button on the Case object. However when the users clicks on the button. The record is not updating.
 
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
if("{!Case.Status}" != "Closed"){ 
var record = new sforce.SObject("Case"); 
record.Id = "{!Case.Id}"; 
record.Status= 'Closed'; 
record.Product_Family__c= 'Unknown'; 
record.Product_Model__c= 'Unknown'; 
record.Problem_Code__c= 'Inquiry - Non-Technical'; 
record.Resolution_Code__c= 'Spam'; 
var result = sforce.connection.update([record]); 
} 
// check the result here 
window.location.reload();

 
Himanshu ParasharHimanshu Parashar
Hi,

1. Your code looks fine, you might be missing correct api name so try to execute following code with standard field only.

 
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
if("{!Case.Status}" != "Closed"){ 
var record = new sforce.SObject("Case"); 
record.Id = "{!Case.Id}"; 
record.Status= 'Closed'; 
//record.Product_Family__c= 'Unknown'; 
//record.Product_Model__c= 'Unknown'; 
//record.Problem_Code__c= 'Inquiry - Non-Technical'; 
//record.Resolution_Code__c= 'Spam'; 
var result = sforce.connection.update([record]); 
} 
// check the result here 
window.location.reload();

2. Try to run your code in firefox or in chrome with firebug open so that you can see if sfdc is throwing any error.


Thanks,
Himanshu
 
b.gonzalezb.gonzalez
H Himanshu,

I update my code to the following and the case record is now updating:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
var record = new sforce.SObject("Case"); 
if(record.Status != "Closed") { 
record.Id = "{!Case.Id}"; 
record.Status= 'Closed'; 
record.Product_Family__c= 'Unknown'; 
record.Product_Model__c= 'Unknown'; 
record.Problem_Code__c= 'Inquiry - Non-Technical'; 
record.Resolution_Code__c= 'Spam'; 
record.Resolution_Descriptions__c= 'Spam'; 
} 
var result = sforce.connection.update([record]); 
if (result[0].success=='false') { 
alert(result[0].errors.message); 
} else { 
location.reload(true); 
}
However, I need to modify the record to update the Account field (lookup field) on the case record. In addition, I need the Account field to be updated on the contact record as well. Is this possible?
 
Himanshu ParasharHimanshu Parashar
Hi Gonzalez,

Yes you can update the account lookup field with above values and if you want to update any other value of Account object on the basis of Case object update you can user process builder to achieve the same without writing the code.

Makes sense ?

Thanks,
Himanshu
b.gonzalezb.gonzalez
I created the flowing process using the process builder:
User-added image

User-added image

User-added image

User-added image


However, when a user clicks on the custom button on the case: They recieve the following error message: 
User-added image
I am not sure why. Please help!

Beth
 
Himanshu ParasharHimanshu Parashar
Hi Beth,

Process builder generally throw errors when fields value returns null. i.e. if you have null Account id or Contact id it will throw or any other field so you need to add all null check while creating process.

Kindly check process with a single records where you have all values filled.

Thanks,
Himanshu
b.gonzalezb.gonzalez
I selected a contact record and account that would be consider complete. All required fields on the contact and accoutn record has values. In addition, I turned off all validation rules for contact and account object to see if that was preventing custom button and process from working. 

I am still receiving the same error. In addition, I recieved the following email error notification:

Sandbox: Unhandled process fault from QLogic Corporation : Spam_Button_on_Case_Object : UPSERT --- UPSERT FAILED --..

Sandbox
 
Encountered unhandled fault when running process Spam_Button_on_Case_Object/301f00000000boE exception by user/organization: 00Df0000003cHuJ/{4} Source organization: 00D00000000hbaA (null) UPSERT --- UPSERT FAILED ---  ERRORS :  (FIELD_CUSTOM_VALIDATION_EXCEPTION) <div style="background-color: red; height: 20px; color: white; line-height: 20px;">Duplicates for Account</div><table width="80%" cellspacing="0" cellpadding="0" class="list"><thead class="rich-table-thead"><tr class="headerRow"><th class="headerRow" width="40">Score</th><th class="headerRow">Account Name</th><th class="headerRow">Billing City</th><th class="headerRow">Billing Country</th><th class="headerRow">Account Phone</th><th class="headerRow">Account Number</th></tr></thead><tbody><tr class="dataRow" onfocus="if (window.hiOn){hiOn(this);}" onblur="if (window.hiOff){hiOff(this);}" onmouseout="if (window.hiOff){hiOff(this);}" onmouseover="if (window.hiOn){hiOn(this);}"><td class="dataCell" style="text-align: left; font-weight: normal;">75</td><td class="dataCell" style="text-align: left; font-weight: normal;"><a href="/00180000010CVOvAAO">Unclassified Customer - Minnetonka</a></td><td class="dataCell" style="text-align: left; font-weight: normal;"><a href="/00180000010CVOvAAO"></a></td><td class="dataCell" style="text-align: left; font-weight: normal;"><a href="/00180000010CVOvAAO">United States</a></td><td class="dataCell" style="text-align: left; font-weight: normal;"><a href="/00180000010CVOvAAO"></a></td><td class="dataCell" style="text-align: left; font-weight: normal;"><a href="/00180000010CVOvAAO"></a></td></tr></tbody></table></br> ---  for SFDC record with ID : null,
 
caused by element : FlowRecordUpdate.myRule_1_A1
 
caused by: UPSERT --- UPSERT FAILED ---  ERRORS :  (FIELD_CUSTOM_VALIDATION_EXCEPTION) <div style="background-color: red; height: 20px; color: white; line-height: 20px;">Duplicates for Account</div><table width="80%" cellspacing="0" cellpadding="0" class="list"><thead class="rich-table-thead"><tr class="headerRow"><th class="headerRow" width="40">Score</th><th class="headerRow">Account Name</th><th class="headerRow">Billing City</th><th class="headerRow">Billing Country</th><th class="headerRow">Account Phone</th><th class="headerRow">Account Number</th></tr></thead><tbody><tr class="dataRow" onfocus="if (window.hiOn){hiOn(this);}" onblur="if (window.hiOff){hiOff(this);}" onmouseout="if (window.hiOff){hiOff(this);}" onmouseover="if (window.hiOn){hiOn(this);}"><td class="dataCell" style="text-align: left; font-weight: normal;">75</td><td class="dataCell" style="text-align: left; font-weight: normal;"><a href="/00180000010CVOvAAO">Unclassified Customer - Minnetonka</a></td><td class="dataCell" style="text-align: left; font-weight: normal;"><a href="/00180000010CVOvAAO"></a></td><td class="dataCell" style="text-align: left; font-weight: normal;"><a href="/00180000010CVOvAAO">United States</a></td><td class="dataCell" style="text-align: left; font-weight: normal;"><a href="/00180000010CVOvAAO"></a></td><td class="dataCell" style="text-align: left; font-weight: normal;"><a href="/00180000010CVOvAAO"></a></td></tr></tbody></table></br> ---  for SFDC record with ID : null,
 
Salesforce Error ID: 943214442-28408 (1820369309)



Beth
b.gonzalezb.gonzalez
Hi Himanshu,

I figured it out. I have Duplicate Checker installed package in my instance. The settings on this package was preventing the button and the process from working.

Beth
b.gonzalezb.gonzalez
Hi Himanshu,

I just realized instead of the procss re-associating the contact record to the "Unclassified Customer – Minnetonka' account record. It is overrding the account record the contact is related to and renaming the account to 'Unclassified Customer – Minnetonka' . 

Is there a way around this with the Process Builder?

Beth
Himanshu ParasharHimanshu Parashar
Hey Beth,

I think you should check your process for this and add logic  to avoid this.

Himanshu