You need to sign in to do that
Don't have an account?

A button to update a record based on a custom field of the owner.
Hi All
Full disclosure: Novice at JS.
Im trying to make a button which will check the Region of the Owner and based on that change the Status of the Lead and Change the owner.
Ive done simmilar things before an im trying to paste it all together but im stuck at the first step! Trying to check the region of the owner.
Is there a way that i can do this? I thoguht just Lead.OwnerId.Region__c would work but clearly not.
As for the rest of the button im sure there are tons of errors but this is where i need to started i think.
Full disclosure: Novice at JS.
Im trying to make a button which will check the Region of the Owner and based on that change the Status of the Lead and Change the owner.
Ive done simmilar things before an im trying to paste it all together but im stuck at the first step! Trying to check the region of the owner.
Is there a way that i can do this? I thoguht just Lead.OwnerId.Region__c would work but clearly not.
As for the rest of the button im sure there are tons of errors but this is where i need to started i think.
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} //Define the object var leadObj = new sforce.SObject("Lead"); //Define the IDs of things leadObj.Id = '{!Lead.Id}'; // IF APAC if(('{!Lead.OwnerId.Region__c}' == 'APAC') ,leadObj.Status = 'Marketing Qualified'; leadObj.Owner = '00520000003YH58'; , // IF EMEA if(('{!Lead.OwnerId.Region__c}' == 'EMEA') ,leadObj.Status = 'Marketing Qualified'; leadObj.Owner = '00520000003YH58'; , // IF Americas if(('{!Lead.OwnerId.Region__c}' == 'Americas') ,leadObj.Status = 'Marketing Qualified'; leadObj.Owner = '00520000003YH58'; ,enter your else-expression here (only for the last one) - 3))) as //update method takes an array of Leads; init to 1 element - 'leadObj' var result = sforce.connection.update([handObj]); if (result[0].success == 'false') { alert(result[0].errors.message); } else { location.reload(true); /* redisplay the detail page */ }
I missed to change the object name in second SOQL. Please use below mentioned code:
All Answers
Thanks for your update and thoughts on this! Truely greatful.
I have tried this and im getting an error (below), i have updated the fields to that they contain the Status and the ID of the users. I have checked the user object and the field is definaly labeled 'Region__c'.
I dont quite understand the entity 'Name' error because name isnt mentioned anywhere. This is quite a bit outside of my scope of understanding.
Region__c is a custom field created on User object which cannot be queried in SOQL. You can refer the below mentioned link for the permitted User fields that can be retrieved in SOQL:
http://skaruz.com/en/2015/03/english-salesforce-how-to-access-owner-custom-fields-in-a-soql-query/
I have just modified the above code a little:
I made the changes you suggested so now the ID of the owner is actually showing up in the error.
Am i right in understanding that what i want to do is not possiblebecause the custom field will not be readable, and there is no work around?
The current error i get is below, it mentions that the custom field is invalid leading me to think that based on the link you provided i will be unable to achieve what im trying to do.
Is this correct?
Dale
Ive put an alert in there to show where its getting up to. Now i get to an alert saying APAC but then it throws an error reading:
"Unable to Create/Update fields: LeadRegion__c" despite the fact that im not trying to update that field....
Frustrating!
I missed to change the object name in second SOQL. Please use below mentioned code:
Thanks so much