You need to sign in to do that
Don't have an account?
Irvine Delacroix
Hi Experts,
I'd like someone to help me understand how to use Map collection. I've seen some examples, articles and documentions that are too advanced and really hard to understand. Some explanations seems to hard to imagine how to use them in a Real World.
So in the scenario Above, I'd like to update a field from Contact when it's created with a value from other Related list undre Account.
I know it can be done with Maps but I don't know how to start my query or how to apply Maps.
•I'd like to know which one should be the Map
•What's going to be my first step then second then third etc.
•What are the best practices for this.
It's would be awesome if someone can comment based on Experience and not just post some artilces. Mostly, articles are confusing and don't really explain how to use things in the Real world.
P.S.
If it's possible for me to have copy of some sort of documents about Maps or Apex, I'd like to have them in my email. vinzell999@gmail.com :)
Thanks a Bunch!
Need help to understand Map collection
Hi Experts,
I'd like someone to help me understand how to use Map collection. I've seen some examples, articles and documentions that are too advanced and really hard to understand. Some explanations seems to hard to imagine how to use them in a Real World.
So in the scenario Above, I'd like to update a field from Contact when it's created with a value from other Related list undre Account.
I know it can be done with Maps but I don't know how to start my query or how to apply Maps.
•I'd like to know which one should be the Map
•What's going to be my first step then second then third etc.
•What are the best practices for this.
It's would be awesome if someone can comment based on Experience and not just post some artilces. Mostly, articles are confusing and don't really explain how to use things in the Real world.
P.S.
If it's possible for me to have copy of some sort of documents about Maps or Apex, I'd like to have them in my email. vinzell999@gmail.com :)
Thanks a Bunch!
It is all about preparing the data which is common across the object ans which can be used for mapping. For example
Now you want to put data ObjectA__c.Fieldc__c field data on Contact so to do that you can see that ou have Account common between ObjectA__c with Contact right. so you will query ObjectA__c and you will create a where Map's key value will be Accountid and value will be Field__c as shown in below code
Now you can use this AccountMap anywhere in your code and get data by passing Account id
Does it makes sense ?
Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
All Answers
Map is always a key value pair collection as described in below code, you will pass the key and you will get the value of that key.
In above example Salesforce,Apple,IBM are keys and CRM,Mobile, Hardware are values. This is basic about Map collection.
Now Lets talk about your problem.
You want to get data from Account object and put on contact object. so the use case will be that you need a Map of Contactid with corresponding Account object so Map will init like this,
You can get data from this map using
Above is the basic example of Map of Contact with single value.
so your task is to create a Map like this
Hope this will help you to understand Map
Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
This is simple one which you can handle from trigger..I haev few question for this req..
1. Is there any relationship bewteen Conatct and Other object ? if yes then it is very simple..
if not then when we create a contact that time we will check its related account and as it shows in above diagram, Account can have multiple "other Objects", so if which one we should be using for field mapping..
Account A is having --> other Object 1 , other Object 2 , other Object 3
Conatct A we are creating which is related to Account A..
So from 3 related other objects whiched one we should use for field mapping ? or you need to rollup means aggreagted sum of all related objects..
Or it is somthing like there will be only 1 other object related to account ??
Thanks,
Sandeep
However, I do have another question.
Your example seems to be pulling up value of a field from Account (Account.custom__c).
What if the value that I am getting is coming from a Related list under account and passing it to the Contact, how do I query that? and after I query it, how do I get the value to pass it to the contact field.
Thanks,
It is all about preparing the data which is common across the object ans which can be used for mapping. For example
Now you want to put data ObjectA__c.Fieldc__c field data on Contact so to do that you can see that ou have Account common between ObjectA__c with Contact right. so you will query ObjectA__c and you will create a where Map's key value will be Accountid and value will be Field__c as shown in below code
Now you can use this AccountMap anywhere in your code and get data by passing Account id
Does it makes sense ?
Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
I hope I can get more help from you in the future. You're the best!
Thanks again for sharing :)
-Irvine
Himanshu already answered a lot but it would be awesome if you can give me some more Ideas about this :)
Basically, there can be more than 1 records related to the Account. But say for example, there's a picklist field on Contact (value: 1, 2 3) and also same in Related record in Account.
the Value that I want to pass in Contact is the Record from Account Where the Picklist value is the same as the contact field.
Thanks,
-Irvine
You mean to say lets take an example
Contact 1 conatct 2 contact2 are related to Account1
Object 1 Object2 and Object 3 are also related to Account 1
if Contact 1 is having picklist value as 33 and Object 2 is also having picklist value 33 then Object 2 field we should be mapping with contact 1..
Let me know if above is the case..
Picklist are present on Conatc and Other Object ?
Sorry I didn't respond to you sooner. I'm not full time with studying apex so I can only answer when I get the chance.
Yes, if picklist value from contact 1 is 33 and Object 2 has 33 value as well, then pass the field value from Object 2 to Contac1 :)
Thanks a lot @sandeep
Please refer the below trigger code for your requirnmnet....small balnak and null check you can add in this code ..
I have added comments also how we are updating teh values
Please use this code and let me know if it works for you..I have tried in my org and it is working good....You can simply replace the objects Api names and field names and do small null check if nay field is empty or not....
Please check and letme know if you are facing any issue in this..
with above code you will be able tio achive this
If you have there OtherObject records and you are updating them then this code will find related contact record based on common account Id and picklist value and it will update the fields in contact..
please try and let me know if you have nay doubts
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Thanks,
Sandeep
Salesforce Certified Developer