You need to sign in to do that
Don't have an account?
Trigger to relate entries on two custom objects on bulk upload
I've been trying to puzzle out this problem with various roundabout methods for some time on Professional Edition, but we just upgraded to Enterprise and it seems like apex triggers would be the most effective way to implement this. I wonder if anyone could provide any advice or guidance, as I'm pretty new to apex.
We're trying to use Salesforce to store and organize some payroll info that is provided to us in the form of Excel spreadsheets. They are basically lists of sales which include the name and ID of the rep who made the sale. We need to upload these on a weekly basis and then be able to view the sales made by each rep.
So basically we have two custom objects, "Sales" and "Reps". We upload a list of sales (in .csv format) into the Sales object each week. We want to make it so that every time a Sale entry gets created it is assigned to the Rep who made that sale (Sales has a master-detail relationship with Reps). Each sale lists the Name and ID# of the rep who made it, but not the Salesforce ID of the corresponding Rep entry. So it seems we need the apex trigger to match each Sale to the correct Rep by comparing the Name and/or ID fields in both objects.
Does this sound plausible and make sense? Could anyone provide any insight on how I might get started? Any help would be greatly appreciated.
P.S. We also need to assign "points" to each Rep based on the status of each sale that gets added...but I suppose that will come after. I've been told this might be accomplished with workflow rules, but obviously we first need to find a way of associating each Sale with the correct Rep
Yes this is possible through triggers. But before working with triggers, i would like to suggest one more alternative. If you have a list of Rep ID's and the Salesforce ID's of these reps in an excel sheet, you could easily do a vlookup to get the Salesforce ID of the Rep in a new column in your Sale csv file. This way there is no need for a trigger.
Ok now the trigger based solution.
1. Create a trigger on the Deal to dynamically lookup the the Salesforce ID of the rep.
I have not compiled and checked, so there may be a few syntax errors. Let us know if you get any errors.
You cannot write new triggers on your production instance, so test it first on a sandbox and then migrate it later
Hope this helps.
Regards,
Satish Kumar
Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.
All Answers
Yes this is possible through triggers. But before working with triggers, i would like to suggest one more alternative. If you have a list of Rep ID's and the Salesforce ID's of these reps in an excel sheet, you could easily do a vlookup to get the Salesforce ID of the Rep in a new column in your Sale csv file. This way there is no need for a trigger.
Ok now the trigger based solution.
1. Create a trigger on the Deal to dynamically lookup the the Salesforce ID of the rep.
I have not compiled and checked, so there may be a few syntax errors. Let us know if you get any errors.
You cannot write new triggers on your production instance, so test it first on a sandbox and then migrate it later
Hope this helps.
Regards,
Satish Kumar
Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.
Wow! I never noticed the email that there was a reply. I'm amazed and delighted to get such a thorough and detailed response. I really appreciate it and apologize for not replying to thank you earlier.
I'm trying out your trigger...but I am getting a little error. My Rep IDs are in fact strings, not integers, so I did change both instances of "Set<Integer>" to "Set<String>". The only other change I made was to change "deal" to "sale" to match my Sales object.
The error I'm getting is: "Error: Compile Error: Invalid bind expression type of SET<String> for column of type String at line 22 column 81"
I'm not quite sure what's causing that. I'll copy my slightly modfied code below.
Thanks so much again for your help. I can't tell you how much I appreciate it. I'll make sure to keep an eye out for a reply now that I know there's someone as helpful as you on these forums.
Regards,
Satish Kumar
Pardon me...line 22 is:
Thanks again for your help!
Still around? Any guidance on this error? I really appreciate the help you've given so far and am very grateful.
I did get this resolved...in case anyone in future finds this useful I figured I'd post here that the solution to the error was to remove the parenthesis around ":repIDs" on the line:
Also, I learned after the fact that the free Dataloader.io app on the appexchange can do this Salesforce ID lookup right out of the box...so when using that there's no need for a trigger or a vlookup or any of that annoying stuff I've spent time messing around with.
Thanks
Satish Kumar