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
AK_SmithAK_Smith 

Button to update checkbox if owner = current user

Hello!
I need to create a button that will update checkbox IsTarget__c on Contact if OwnerId = User.Id
Best Answer chosen by AK_Smith
AK_SmithAK_Smith
Hi, can you please help me to add this code to mine?
{!requireScript("/soap/ajax/40.0/connection.js")} 
{!requireScript("/soap/ajax/40.0/apex.js")}
{!requireScript("/resource/jquery321")} 
{!requireScript("/resource/blockui")}


$('.bodyDiv').block({ css: { 
    border: 'none', 
    padding: '15px', 
    backgroundColor: '#000', 
    '-webkit-border-radius': '10px', 
    '-moz-border-radius': '10px', 
    opacity: .5, 
    color: '#fff' 
}});

sforce.apex.execute("WebServiceProvider", "untargetContact", {contactId:'{!Contact.Id}'}, {
	onSuccess : function(result) {
		alert(result[0].message);
		$('.bodyDiv').unblock();
		document.location.reload(true)
	},
	onFailure : function(result) {
		alert(result);
		$('.bodyDiv').unblock();
		document.location.reload(true)
	}
});

 

All Answers

Raj VakatiRaj Vakati

Option 1 . Use this formula to do it .. You no need to create any field update 
OwnerId == $User.Id

Option 2. Update the values with workflow

User-added image
 
mukesh guptamukesh gupta
Hi Smith,

workflow will not support "OwnerId" isChanged function. so you need to create a Trigger for this process.

if you any assitanse or need trigger Please let me know. i will write a trigger for you.

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukes



 
Raj VakatiRaj Vakati
Hi Mukes , 

ISCHANGED will work on OwnerId changes and with  "Evaluate the rule when a record is created, and every time it's edited" Evaluation Criteria . 


No need for any trigger I believe 
Saravana Muthu 8Saravana Muthu 8
Hi,

You could also create a onclick javascript detail page button and use the below code.
 
{!REQUIRESCRIPT( "/soap/ajax/36.0/connection.js" )} 
{!REQUIRESCRIPT("/soap/ajax/36.0/apex.js")}; 

//Declare variable and match the record 

var leadtoUpdate = new sforce.SObject( "Contact" ); 
leadtoUpdate.Id = "{!Contact.Id}"; 
if('{!Contact.OwnerId}'=='{!User.Id}'){ 
leadtoUpdate.User_Same__c = true; 
} 
else 
{ 
alert('Please own the record to edit it'); 
} 

var result = sforce.connection.update( [leadtoUpdate] ); 
if ( result[0].getBoolean( "success" ) ) { 
window.location.reload(); 
} 
else { 
alert( "An error has occurred! Error:" + result[0].errors.message ); 
}


Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.

Thanks,
Sarav
Sweet Potato Tec
 
AK_SmithAK_Smith
Hi, can you please help me to add this code to mine?
{!requireScript("/soap/ajax/40.0/connection.js")} 
{!requireScript("/soap/ajax/40.0/apex.js")}
{!requireScript("/resource/jquery321")} 
{!requireScript("/resource/blockui")}


$('.bodyDiv').block({ css: { 
    border: 'none', 
    padding: '15px', 
    backgroundColor: '#000', 
    '-webkit-border-radius': '10px', 
    '-moz-border-radius': '10px', 
    opacity: .5, 
    color: '#fff' 
}});

sforce.apex.execute("WebServiceProvider", "untargetContact", {contactId:'{!Contact.Id}'}, {
	onSuccess : function(result) {
		alert(result[0].message);
		$('.bodyDiv').unblock();
		document.location.reload(true)
	},
	onFailure : function(result) {
		alert(result);
		$('.bodyDiv').unblock();
		document.location.reload(true)
	}
});

 
This was selected as the best answer
Saravana Muthu 8Saravana Muthu 8
Hi,

Can you please let me know what your code does?

Thanks;
Sarav
Sweet Potato Tec
AK_SmithAK_Smith
This code delete detail records and cannot be changed