You need to sign in to do that
Don't have an account?
NevDev
Validation Rule To Only Show Certain Contact Values In A Contact Lookup Field.
Hi Guys,
I have two lookup fields on the Cases object. One field is a lookup field to Contacts and the other is a lookup field to Policy_c which is a child object of Contacts.
What I want to do is once a user types a Policy No. in the Policy_No_c Lookup field and click on the search icon next to the Contacts lookup field, I only want Contacts who have the Policy No as a related list item in the Contact record to appear.
How can I achieve this?
I have two lookup fields on the Cases object. One field is a lookup field to Contacts and the other is a lookup field to Policy_c which is a child object of Contacts.
What I want to do is once a user types a Policy No. in the Policy_No_c Lookup field and click on the search icon next to the Contacts lookup field, I only want Contacts who have the Policy No as a related list item in the Contact record to appear.
How can I achieve this?
Reference
https://help.salesforce.com/apex/HTViewHelpDoc?id=fields_lookup_filters_dependent_lookups.htm&language=en
https://help.salesforce.com/apex/HTViewHelpDoc?id=fields_lookup_filters_examples.htm&language=en_US
Can this solution work if I am referencing a related list item and not a field on the Contact record. So a Contact could have 4 related Policies in a related list item, some of which could be joint policies. If I type the policy number into the Policy_c lookup field in Cases can I filter the Contact Lookup field to only show the Contacts that have that policy number as a related list item in their Contact records?
What i can suggest is to create a field on contact, that has all the related policies value in it, appended as a string (can be done using a basic trigger/ process builder).
Refer this custom field while setting up the dependent lookup.
See the attached link for your reference.
http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/
Using the Process Builder I'm not seeing how this is possible. What criteria should I use?
Refer the link below for step by step process :
http://focusonforce.com/process-automation/focus-on-automation-visual-workflow-loops/
Can you help me with the trigger that I need to autopopulate the field in the Contact record with the related Policy No's?
Thank you for this. I am receiving the below error message. The custom field API is Policy_c and the Custom Object API is Policies__c
Error: Compile Error: No such column 'Policy_No_c' on entity 'Policies__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 9 column 32
I keep getting an invalid SObject type name error when I use the code that you provided. I have changed the Custom object name to Policy_Information_c which is the object that relates to the Contact object. The custom field that I created to capture the Policy numbers is Policy_No_c.
Not sure where I'm going wrong.
Just your latest code in here, then I can have a look
Set<Id> contactIdSet = new Set<Id>();
for(Policy__c thisRecord : trigger.new){
if(thisRecord.Policy_No_c != null && thisRecord.ContactId != null){
contactIdSet.add(thisRecord.ContactId);
}
}
Map<String, String> contactPolicyNoMap = new Map<String, String>();
for(Policy__c thisRecord : [SELECT Policy_No_c, ContactId FROM Policy__c WHERE Id IN: contactIdSet]){
if(contactPolicyNoMap.containsKey(thisRecord.ContactId)){
String policyString = contactPolicyNoMap.get(thisRecord.ContactId);
contactPolicyNoMap.put(thisRecord.ContactId, policyString + thisRecord.Policy_No_c);
}else{
contactPolicyNoMap.put(thisRecord.ContactId, thisRecord.Policy_No_c);
}
}
List<Contact> updateContactList = new List<Contact>();
for(String thisKey : contactPolicyNoMap.keySet()){
Contact newContact = new Contact();
newContact.Id = thisKey
newContact.Policy_No_c = contactPolicyNoMap.get(thisKey);
updateContactList.add(newContact);
}
if(!newContact.isEmpty()){
update updateContactList;
}
}
I'm still getting the same error message.
It's back to this error message again
Error: Compile Error: No such column 'ContactId' on entity 'Policy_Information__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 9 column 44
This is a bit confusing as I am coping and pasting the actual API name directly into the code so it should definitely be correct.
Error: Compile Error: Field is not writeable: Contact.Name at line 21 column 9
Trigger PolicyTrigger on Policy_Information__c (after insert, after update) {
Set<Id> Policy_Holder__cSet = new Set<Id>();
for(Policy_Information__c thisRecord : trigger.new){
if(thisRecord.Name != null && thisRecord.Policy_Holder__c != null){
Policy_Holder__cSet.add(thisRecord.Policy_Holder__c);
}
}
Map<String, String> contactPolicyNoMap = new Map<String, String>();
for(Policy_Information__c thisRecord : [SELECT Name, Policy_Holder__c FROM Policy_Information__c WHERE Id IN: Policy_Holder__cSet]){
if(contactPolicyNoMap.containsKey(thisRecord.Policy_Holder__c)){
String policyString = contactPolicyNoMap.get(thisRecord.Policy_Holder__c);
contactPolicyNoMap.put(thisRecord.Policy_Holder__c, policyString + thisRecord.Name);
}else{
contactPolicyNoMap.put(thisRecord.Policy_Holder__c, thisRecord.Name);
}
}
List<Contact> updateContactList = new List<Contact>();
for(String thisKey : contactPolicyNoMap.keySet()){
Contact newContact = new Contact();
newContact.Id = thisKey;
newContact.Name = contactPolicyNoMap.get(thisKey);
updateContactList.add(newContact);
}
if(!newContact.isEmpty()){
update updateContactList;
}
}
What I asked you was to create a new Text field, and save the appended value on that.
Replace newContact.Name with newContact.<customField>
Error: Compile Error: Variable does not exist: newContact at line 24 column 10
This will populate the custom text field with all of the Related Policy Numbers right?
Something like : newContact.policy_lookup_key__c
API Custom Object = Policy_Information__c
API Custom Object Name Field = Policy Number (I can't find the actual API name of this field, It is the Name field renamed to Policy Number).
Do mark this answer aas best answer if it helped you.
Can anyone please get involved here and help me resolve this? The suggestions above have worked up to a certain point but it still remains unresolved. Here is what I am trying to do and what I have done:
Created a Custom object called Policy_Information_c which has a Master Detail Relationship with Contacts
Created a Custom field in Cases object which looks up Policy_Information_c
A Policy_Information_c can be related to multiple Contacts
In the Cases object the Contact Lookup field is filtered to only show Contacts related to the Policy No. So the Policy no. is typed in first.
Looks like a simple requirement but I'm struggling Badly to find a solution, and I have been working on this simple requirement now for a couple of days.