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
Kumar5Kumar5 

onClick Exectue Java script button to update contact feilds

Hello Team,

I want to update contact fields of phone ane email from associated account fields of phone and emal using onlcik java script buttong.

Please provide me few inputs to achieve this.

Thanks,
Kumar
Nayana KNayana K
Assuming button is on Account record and you want to update child contacts from there :
{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")}
var __sfdcSessionId = '{!GETSESSIONID()}';

try 
{
var strQuery="Select Id, Phone, Email from Contact where AccountId = '" +'{!Account.Id}'+"'";
var childCons = sforce.connection.query(strQuery);
var records = childCons.getArray("records");

if (records.length > 0) 
{
    var recordsToUpdate = [];
	for(var i=0; i < records.length ; i ++) 
	{
		var ob = new sforce.SObject("Contact");
		ob.Id = records[i].Id;
		ob.Phone= "{!Account.Phone}";
		ob.Email= "{!Account.Email}";
		recordsToUpdate.push(ob);
	}
	var result = sforce.connection.update(recordsToUpdate);
	location.reload(true);
}

}
catch(er) 
{
	alert(er);
}