You need to sign in to do that
Don't have an account?
How to update a checkbox field on a Custom object through a Custom button
Hi,
Can anyone correct the code? We are having two issues here.
1. The code is not checking the "IF" condition here. It is directly going to "ELSE" part.
2. We are not able to update a checkbox field from unchecked to checked.
---------------------------------------------------------------------------------------------------------------------------------------------------
var currurl = window.location.href;
var stc = new sforce.SObject("Sales__c");
if(stc.OppUpdate__c = 0){
window.location = 'http://xxx.yyy.com/Sales?OpenAgent&id={!Sales__c.OpportunityId__c}&oo={!Sales__c.OpportunityOwner__c...
stc.OppUpdate__c = 1;
result = sforce.connection.update([stc]);
}else{
alert('Already created. You should not create it again');
}
---------------------------------------------------------------------------------------------------------------------------------------------------
We are not very experienced in Salesforce and we have never used APEX, Javascript etc. So it is the tough one here.
We will really appreciate the help.
Thanks!
Regards
Try using this : if(stc.OppUpdate__c == 0) instead of if(stc.OppUpdate__c = 0)
Hi Deepa,
We have corrected it with the solution provided by you. But it is also not working.
---------------------------------------------------------------------------------------------------------------------------------------------------
var currurl = window.location.href;
var stc = new sforce.SObject("Sales__c");
if(stc.OppUpdate__c == 0){
window.location = 'http://xxx.yyy.com/Sales?OpenAgent&id={!Sales__c.OpportunityId__c}&oo={!Sales__c.OpportunityOwner__c...
stc.OppUpdate__c = 1;
result = sforce.connection.update([stc]);
}else{
alert('Already created. You should not create it again');
}
---------------------------------------------------------------------------------------------------------------------------------------------------
Thanks!
Regards
We have modified the code as following.
---------------------------------------------------------------------------------------------------------------------------------------------------
var currurl = window.location.href;
var stc = new sforce.SObject("Sales__c");
if(stc.OppUpdate__c == 1)
{
alert('Already created. You should not create it again');
}
else
{
stc.OppUpdate__c = 1;
result = sforce.connection.update([stc]);
window.location = 'http://xxx.yyy.com/Sales?OpenAgent&id={!Sales__c.OpportunityId__c}&oo={!Sales__c.OpportunityOwner__c...
}
---------------------------------------------------------------------------------------------------------------------------------------------------
Now, it is directly going to the URL of the external system. No matter if the stc.OppUpdate__c is checked (1) or unchecked (0). Also, if it is unchecked (0), the code is not updating it with checked (1) value.
Please help!
Thanks and regards
Hi ,
Duplicate,
http://boards.developerforce.com/t5/General-Development/How-to-update-a-field-on-a-custom-object-using-javascript-in-a/m-p/709451#M105727
Regards,
Ashish