Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have my Case object linked to the Contact object with a lookup field (Contact__c). What is the best way to modify the value of a field in a Contact record from the Case record, when there's a contact selected?

For example, I have a Case with the Contact__c lookup populated. I want to modify the value of a picklist in the Contact, from the Case.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

If you are looking to do this from the a Case page layout, unfortunately I don't believe this will be possible. A page layout uses a StandardController which doesn't have any functionality innately built into it to save any object but the main object of the controller.

Programmatically this is very simple. You just need to update each object separately, but that won't help you for a page layout.

share|improve this answer
    
That's what I thought. I've been doing this for a while, and I was asking myself if there was a workaround that I'm not aware of instead of adding a new VisualForce page (or with a Trigger/workflow). –  jpmonette Feb 27 '13 at 21:36

Your question is a bit confusing. DO you want something to happen when user selects contact in the lookup? (what if he selects one, then another one, then maybe selects 1st one again?)... I think some problematic scenarios sit in this area so maybe think again what you want to achieve... And if that's really it - Visualforce Case creation page (don't expect it to work when Case comes from outside like Web-to-Case, Email-to-Case, customer portal...)

If it has to happen on Case save... I don't think you can make cross-object workflows between Case and Contact and besides picklist updates in workflows are annoying (select previous/next value on picklist... wow, awesome, thx SF).

Trigger I'm afraid? Or some Javascript'y hack in the sidebar... or batch job that periodically checks new / changed Cases... Trigger sounds most accurate for this task.

P.S. It's not exactly "Parent" ;) If you'd have a master-detail relation between the two you could cheat by either making it a rollup summary or make a workflow on Contact "count of cases changed -> do something". Alas standard object can't be a "detail".

EDIT: Or maybe you're on the Case viewing page? Then you're one click away from editing the contact (hover over the link, balloon pops up, [edit])... If you really really need to do it from detail page - embed a VF page in the layout:

<apex:page standardController="Case" extension="myclass">

and in the Controller extension query for contact etc.

share|improve this answer
1  
From the sound of his question, he wants to modify a field of the Contact on a Case page layout. Before we even worry about saving the Contact, how would we even get that field on the page for the user to edit if we that field isn't on the Case? –  Jesse Altman Feb 27 '13 at 21:30
1  
yep, you can't traverse relationships before you save, formulas are null etc... And "what happens if I select him 2 times" pops up. A variation on classic "viewing of data shouldn't have side effects like changing it", whether it's <apex:page action="{!doEvilStuff}>, component with allowDML=true or simply difference between GET and POST requests... –  eyescream Feb 27 '13 at 21:34
    
Jesse is right. I also thought that it wasn't possible without coding a little bit, just wanted to make sure that there was no easy way built from scratch to do this :) –  jpmonette Feb 27 '13 at 21:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.