+ Start a Discussion
B&D DeveloperB&D Developer 

I need help with Apex Code

I need to capture the Contact Address and reder it in order address field if certain picklist value is selected.
I have two Contacts Record Types. Clinician and Customer.
If user selected Clinician from the picklist value, it should capture the clinician address and render it in tyhe new order shipping address.
Likewise iwf customer is selected.

Thanks in advance

Best Answer chosen by B&D Developer
goabhigogoabhigo
Ohhh.. For populating you can use Formula field, Workflow or Apex trigger. BOTH, however, won't populate on page load. For that you need to override the edit page with VF page.
Since you also have a manual input, we can go for Workflow rules.
  • Create a workflow rule under the specific object. Evaluation Criteria would be created, and every time it’s edited
  • In the Rule Criteria, put OR( AND( NOT( ISBLANK(Ship_To__c)), ISNEW() ), ISCHANGED(Ship_To__c))
  • Create a field update and select the Address the field. In the formula (select Use a formula to set the new value), enter the below:
IF(ISPICKVAL(Ship_To__c, 'Clinic'), 
 Recipient_Clinician__r.Ship_To1__c, 
 IF(ISPICKVAL(Ship_To__c, 'Customer'),
  
Order_Contact__r.Ship_To1__c,
  null),
 null)

 I haven't tested this. Please let me know if you are getting any error. 
As I said earlier, please note that this wont auto populate. This will populate the address field on Saving.

--
Abhi

If my answer helps to solve the issue/problem/doubt, please mark it as Best Answer; so that people who are stuck in the similar issue get benefitted. 

All Answers

goabhigogoabhigo
Are you using VF page for this? You can use "rendered" attribute in field tag (<apex:inputField>).
If you are not using, then write a validation rule to make the specific address field mandatory based on picklist field.

Let me know if you need further clarity. It would be great to know what you have done to achieve this.

--
Abhi
B&D DeveloperB&D Developer
Nope,

I'm not using any VF Page
 
goabhigogoabhigo
Ok. As I mentioned above, if you are not using, then write a validation rule to make the specific address field mandatory based on picklist field.
Do you need help in writing valdiation rules? If yes, please let me know the names(API names) of the fields you are using.

--
Abhi
B&D DeveloperB&D Developer
Thanks Abhi,

It should be like this,
Once you create and  New Order for Customer there will be a picklist field for youto choose whether to ship the device to Clinic, Customer, or Custom Address,
If you selected Clinic in Ship To (Ship_To__c), it should autopopulate the address of Clinic (Recipient_Clinician__r.Ship_To1__c), If customer is selected, it shoudl populate Customer's Address (Order_Contact__r.Ship_To1__c), and if Custom, the user can enter address Manually.

Thanks for the help
 
goabhigogoabhigo
Ohhh.. For populating you can use Formula field, Workflow or Apex trigger. BOTH, however, won't populate on page load. For that you need to override the edit page with VF page.
Since you also have a manual input, we can go for Workflow rules.
  • Create a workflow rule under the specific object. Evaluation Criteria would be created, and every time it’s edited
  • In the Rule Criteria, put OR( AND( NOT( ISBLANK(Ship_To__c)), ISNEW() ), ISCHANGED(Ship_To__c))
  • Create a field update and select the Address the field. In the formula (select Use a formula to set the new value), enter the below:
IF(ISPICKVAL(Ship_To__c, 'Clinic'), 
 Recipient_Clinician__r.Ship_To1__c, 
 IF(ISPICKVAL(Ship_To__c, 'Customer'),
  
Order_Contact__r.Ship_To1__c,
  null),
 null)

 I haven't tested this. Please let me know if you are getting any error. 
As I said earlier, please note that this wont auto populate. This will populate the address field on Saving.

--
Abhi

If my answer helps to solve the issue/problem/doubt, please mark it as Best Answer; so that people who are stuck in the similar issue get benefitted. 
This was selected as the best answer
B&D DeveloperB&D Developer
The problem with the Field update is, it will only update the field after saving the changes.
What is needed is for the address to appear once picklist value is selected.

Is this possible/

Thanks Abhi
goabhigogoabhigo
Like I mentioned above, "For that you need to override the edit page with VF page.". Unfortunately, Salesforce has stopped supporting sidebar JavaScripts, so as of now only way is to override using VF page.
B&D DeveloperB&D Developer
Can you please help me with VisualForce Page?
Thanks