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
Sakthi169Sakthi169 

How to update Lead Owner(standard field) in custom page using mobile.

I need to update owner(Standard Field) name on custom page(Buyer) using Referral Id(mobile of Lead owner)..
The Referral Id(Mobile No) already present in user details.
For example the buyer is created by me but i put the Referral Id was my manager mobile no.After created the Buyer i need to updated owner as my manager name not mine.Now it show my name.I don't want trigger without trigger,if there is any another way is possible???
Nirmala  KuchiNirmala Kuchi
If you can retreive the manager Id before inserting a record, you may set the OwnerId of the record at the time insertion it self.

OR

You can use update DML, just after insertion to update OwnerId.

Thanks,
Nirmala
Sakthi169Sakthi169
Hi Nirmala,

I did it by before insert,before update trigger and it was working fine in my sandbox and i create test class. when i move this to production it interfer the existing trigger.??? that's why i dont want trigger ??
when i click the deploy i will get the following error.
Your organization's code coverage is 2%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
Nirmala  KuchiNirmala Kuchi
Hi Umadevi,

You need to write unit test classes for the classes you are trying to deploy.

Org code coverage must be 75% overall, and  Each trigger must have at least 1% code coverage.
Sakthi169Sakthi169
Hi Nirmala,

I am new to salesforce and i write trigger and test class.Both are working fine in sandbox when i deploy it will interfer the existing test class.
 
Parker EdelmannParker Edelmann
Alternatively, an admistrative solution would be to use Process Builder. For all buyers you create, you can reassign the owner to your manager with an immediate action.
Sakthi169Sakthi169
Hi Parkar,

I dont know how to do it
Parker EdelmannParker Edelmann
Sorry for the delay, when you posted I wasn't notified as usual. In setup, search for Process Builder and create a new process. If I understand everything correctly, set the process object to Buyer, or whichever object you need to update, and set it to run on record create only. For the criteria node, if all users need to have the buyer owner updated to their manager, the only criteria is that their manager is not blank. If only a few users need this update, put the other criteria in as well. For the action, select update a record as the type, and the Buyer record that started the process as the target. For the fields to update, have the OwnerId Reference the User's ManagerId. That should cover everything. If you need anymore help or have anymore questions about it, just post below.

Thanks,
Parker
Sakthi169Sakthi169
Hi Parkar,

There is three condition
1.Buyer is not available record will not create,and throw the error msg like,"Referral id is not found"
2.Buyer(Referral Id) is inactive record will not create,and throw the error msg like,"User is Inactive"
Parker EdelmannParker Edelmann
I assume that Referral Id is a lookup to user, right? If not you may want to consider making it a lookup to user. For your two conditions, simply make Referral Id a required field and make a validation rule to make sure that it doesn't lookup an inactive user. If it's not a lookup to user, we'll need a more robust tool called Visual Workflow. Take the general idea of the above process I've outlined, and try to create it. If you can create it just fine, then please mark it as best answer. If you need some help, post some screenshots of the process you have, and I can help you further.

Thanks,
Parker
Sakthi169Sakthi169
Hi Parkar,

It is the input field not lookup fields. I write the trigger and test class it was working fine(sandbox). but when i move to production it shows theUser-added imageUser-added image

It was affected existing test class.Thats why i avoid the trigger and workflow....
Parker EdelmannParker Edelmann
Declaritive automation tools such as Process Builder, Visual Workflow, Workflow, and Approvals don't need unit tests or code. By input field, what field type is that?
Parker EdelmannParker Edelmann
BTW, it looks like your unit tests are failing because you didn't provide values for necessary fields when you inserted the record.
Sakthi169Sakthi169
input type is phone
Parker EdelmannParker Edelmann
So you have two options, the first is simpler than the second.
  1. Create a process that when the Buyer is created, it re-populates the owner field with the manager of the user that created the record, if they have a manager. I have already outlined this in my second reply.
  2. Create a process that launches a flow. When the Buyer is created, it immediately goes to the actions and calls a flow. You will need to create within the flow an sObject variable and pass the record that started the process to it. For the purpose of this outline, we'll call it "Buyer." The flow should start with a Record Lookup Element, and lookup a user that has a phone number equal to the Reference Id. Save the user that was found to a new sObject variable. The flow will then need to use a Record Update Element that looks up a Buyer record with an Id equal to {!Buyer.Id}, or the Id of the record that started the process. To set the new owner, Owner must reference the Manager Id when you set new values.
Note that with either method you use, you may, and probably will, need to add some additional criteria either on the criteria node, or if you choose to go with option 2, you may use a Decision Element to filter the records you update.

If you run into difficulties building the process and/or flow, or have additional questions, please ask below and if possible/relevant give some screenshots of your process/flow.

Thanks,
Parker