You need to sign in to do that
Don't have an account?
Help Troubleshooting a Trigger for Lead Assignment
Hello!
I have some code listed below that I was hoping someone would be able to help me troubleshoot. The code is supposed to assign the owner of a Lead based on what Account Team of the User. So when the lead is created, if select "Storefront" for Lead_Direction__c picklist, then it should assign to the Account Team Member on the Account labeled as 'Storefront Associate'. If the I select Big Deal in the picklist, then it should assign to the Account Team Member for the associated Account labeled as the 'Big Deal Associate'. It works when I select Storefront in the Lead Direction and assigned the appropriate rep, but it doesn't assign correctly to the Big Deal Rep.
trigger OpportunityTrigger on Lead (before insert){ List<String> accountIds = new List<String>(); List<AccountTeamMember> parentAccounts = new List<AccountTeamMember>(); for(Lead lead : Trigger.new){ accountIds.add(lead.Account__c); } parentAccounts = [Select AccountId, UserId, TeamMemberRole from AccountTeamMember where AccountId in :accountIds]; Map<String,AccountTeamMember> accountMap = new Map<String,AccountTeamMember>(); for(AccountTeamMember a : parentAccounts){ accountMap.put(a.AccountId,a); } for(Lead lead : Trigger.new){ AccountTeamMember parentAccount = accountMap.get(lead.Account__c); String memberRole = accountMap.get(lead.Account__c).TeamMemberRole; if((parentAccount != null)&&(memberRole == 'Storefront Associate')&&(lead.Lead_Direction__c == 'Storefront')){ lead.OwnerId = parentAccount.UserId; } else if((parentAccount != null)&&(memberRole == 'Big Deal Associate')&&(lead.Lead_Direction__c == 'Big Deal')){ lead.OwnerId = parentAccount.UserId; } else{ lead.OwnerId = lead.OwnerId; } } }
Can you take debug log for below code.
All Answers
Check the picklist value "Big Deal Associate" on picklist field is exactly matches with the string you have given in your apex class. Make sure there is no leading or trailing spaces for picklist value.
I just double checked and it's not an issue with leading spaces for both the Lead Direction picklist or the TeamMemberRole string. They match exactly.
Can you modify your bottom for loop in your trigger like below and try again
if it return leadqwnerid then ur code is correct just check spelling or space while matching .....
No luck, it's still not assigning me as the Owner instead of the Big Deal Associate Account Team Member.
place debug statements in for loop in your code to capture account team member and lead direction values for inserting lead.
I went ahead and tried adding some debug statements in to my code, but when I go to execute this in the system log to look at the value in debug statements, I am getting this weird error.
Can you post your debug log.
That's the thingIt's not even letting me execute it, it's giving me that error when I am trying to execute it anonymously in the developer console to get the debug log.
Do not excevute anonymously in the developer console.
First turn on debug logs for you, then go and try to insert one lead then see the debug log for your lead insert.
You can turn on debug logs like this
setup --------> adminstrative setup------------>Monitoring------------->debuglogs
then click "New" button on moniterd users section and enter your name to add you as monitered user.
After adding you as moniterd user, then you insert one lead from ui then navigate back to debuglogs ,here you can see your debug log for your process in debug logs section.
Ther you can download or view your debug log for your process.
Gotcha! So when I submit it as a Storefront, I am seeing that it showing the Storefront values in the debug log but when I submit it as a Big Deal in the Lead Direction, it's not even printing out Big Deal in the debug log:
This is the debug log for when I selected Storefront:
I just ran it again...it's weird that it's marking that it's a Storefront Associate instead of a Big Deal Associate...
Now its Clear. Can you query account team member records for that account. like below. I think there are more than 1 acoount team records for that account.
SELECT TeamMemberRole,id, accountId FROM AccountTeamMember where accountID ='0013000000pPKtlAAG'
Yes, that's correct, there's more than one Account Team Member for each Account. there should be a Big Deal Associate and a Storefront Associate for each Account.
I switched my code to this:
It's still not working, here's the debug log.
TRy the below code . I hope code will work this time
Still no luck. :(
After seeing your debug lo, i understand that The if loop inside for loop did not exceute. (If you see the debug log it is upto 28 line after 28 line the loop ends. Put debug statement at line 24(above for loop) to get the map values.
System.debug('*****************MAp Values*********'+acctToAccTeanMemsMap.values());
Here's the debug log:
What is the datatype of Account__c on lead?. LookUp or text
Can you take debug log for below code.
Account__c is a lookup. And I just created a lead and it worked! :) Here's the debug log just in case you'd like to look. Thank you so much for your help on this, I appreciate it!
https://twilightteens.com/whatsapp-status-in-english/ (https://twilightteens.com/whatsapp-status-in-english/" target="_blank)
https://twilightteens.com/rose-status-for-whatsapp/ (https://twilightteens.com/whatsapp-status-in-english/" target="_blank)
https://twilightteens.com/rain-whatsapp-status/ (https://twilightteens.com/whatsapp-status-in-english/" target="_blank)
https://twilightteens.com/whatsapp-marathi-status-in-one-line/ (https://twilightteens.com/whatsapp-marathi-status-in-one-line/" target="_blank)
https://twilightteens.com/best-attitude-status/ (https://twilightteens.com/best-attitude-status/" target="_blank)
https://twilightteens.com/romantic-status/ (https://twilightteens.com/best-attitude-status/" target="_blank)
https://twilightteens.com/cool-status-in-hindi/ (https://twilightteens.com/best-attitude-status/" target="_blank)
https://twilightteens.com/cool-status-for-boys/ (https://twilightteens.com/cool-status-for-boys/" target="_blank)
https://twilightteens.com/cool-status-in-english/ (https://twilightteens.com/cool-status-in-english/" target="_blank)
https://twilightteens.com/cool-attitude-status/ (https://twilightteens.com/cool-attitude-status/" target="_blank)
https://twilightteens.com/cool-status/ (https://twilightteens.com/cool-status/" target="_blank)
https://twilightteens.com/life-status-in-english/ (https://twilightteens.com/life-status-in-english/" target="_blank)
https://twilightteens.com/attitude-status-in-english/ (https://twilightteens.com/attitude-status-in-english/" target="_blank)
https://twilightteens.com/attitude-status-in-hindi/ (https://twilightteens.com/attitude-status-in-hindi/" target="_blank)
https://twilightteens.com/motivational-status-in-marathi/ (https://twilightteens.com/motivational-status-in-marathi/" target="_blank)
https://twilightteens.com/whatsapp-status-in-marathi/ (https://twilightteens.com/whatsapp-status-in-marathi/" target="_blank)
https://twilightteens.com/motivational-status-in-hindi/ (https://twilightteens.com/motivational-status-in-hindi/" target="_blank)
https://twilightteens.com/marathi-love-status/ (https://twilightteens.com/marathi-love-status/" target="_blank)
https://twilightteens.com/love-status-in-hindi/ (https://twilightteens.com/love-status-in-hindi/" target="_blank)
https://twilightteens.com/whatsapp-status-in-hindi/ (https://twilightteens.com/whatsapp-status-in-hindi/" target="_blank)
https://twilightteens.com/how-to-hide-online-status-on-whatsapp/ (https://twilightteens.com/how-to-hide-online-status-on-whatsapp/" target="_blank)
https://twilightteens.com/best-motivational-status/ (https://twilightteens.com/best-motivational-status/" target="_blank)
https://twilightteens.com/best-whatsapp-status/ (https://twilightteens.com/best-whatsapp-status/" target="_blank)
https://twilightteens.com/love-status/ (https://twilightteens.com/love-status/" target="_blank)
https://twilightteens.com/life-status/ (https://twilightteens.com/life-status/" target="_blank)
https://twilightteens.com/attitude-status/ (https://twilightteens.com/attitude-status/" target="_blank)
https://twilightteens.com/motivational-status/ (https://twilightteens.com/motivational-status/" target="_blank)
https://twilightteens.com/whatsapp-status-quotes/ (https://twilightteens.com/whatsapp-status-quotes/" target="_blank)
https://twilightteens.com/whatsapp-status-images/ (https://twilightteens.com/whatsapp-status-images/" target="_blank)
https://twilightteens.com/whatsapp-status/ (https://twilightteens.com/whatsapp-status/" target="_blank)
https://goodmorningquotes.live/good-morning-inspirational-quotes-in-english/ (https://goodmorningquotes.live/good-morning-inspirational-quotes-in-english/" target="_blank)
https://goodmorningquotes.live/good-morning-monday-quotes/ (https://goodmorningquotes.live/good-morning-monday-quotes/" target="_blank)
https://goodmorningquotes.live/good-morning-positive-quotes/ (https://goodmorningquotes.live/good-morning-positive-quotes/" target="_blank)
https://goodmorningquotes.live/good-morning-quotes-for-bf/ (https://goodmorningquotes.live/good-morning-quotes-for-bf/" target="_blank)
https://goodmorningquotes.live/good-morning-quotes-for-gf/ (https://goodmorningquotes.live/good-morning-quotes-for-gf/" target="_blank)
https://goodmorningquotes.live/romantic-good-morning-quotes/ (https://goodmorningquotes.live/romantic-good-morning-quotes/" target="_blank)
https://goodmorningquotes.live/good-morning-quotes-for-him/ (https://goodmorningquotes.live/good-morning-quotes-for-him/" target="_blank)
https://goodmorningquotes.live/good-morning-quotes-for-her/ (https://goodmorningquotes.live/good-morning-quotes-for-her/" target="_blank)
https://goodmorningquotes.live/good-morning-quotes-for-love/ (https://goodmorningquotes.live/good-morning-quotes-for-love/" target="_blank)
https://goodmorningquotes.live/good-morning-love/ (https://goodmorningquotes.live/good-morning-love/" target="_blank)
https://goodmorningquotes.live/good-morning-sunday-quotes/ (https://goodmorningquotes.live/good-morning-sunday-quotes/" target="_blank)
https://goodmorningquotes.live/good-morning-images-with-quotes-for-whatsapp/ (https://goodmorningquotes.live/good-morning-images-with-quotes-for-whatsapp/" target="_blank)
https://goodmorningquotes.live/meaningful-good-morning-quotes/ (https://goodmorningquotes.live/meaningful-good-morning-quotes/" target="_blank)
https://morningquotes.online/sweet-girls-quotes/ (https://morningquotes.online/sweet-girls-quotes/" target="_blank)
https://morningquotes.online/quotes-about-thursdays/ (https://morningquotes.online/quotes-about-thursdays/" target="_blank)
https://morningquotes.online/quotes-about-sunday/ (https://morningquotes.online/quotes-about-sunday/" target="_blank)
https://morningquotes.online/morning-funny-quotes/ (https://morningquotes.online/morning-funny-quotes/" target="_blank)
https://morningquotes.online/good-morning-jokes/ (https://morningquotes.online/good-morning-jokes/" target="_blank)
https://morningquotes.online/funny-engaged-quotes/ (https://morningquotes.online/funny-engaged-quotes/" target="_blank)
https://morningquotes.online/cute-girl-quotes/ (https://morningquotes.online/cute-girl-quotes/" target="_blank)
https://morningquotes.online/touchy-love-quotes/ (https://morningquotes.online/touchy-love-quotes/" target="_blank)
https://morningquotes.online/quotes-for-ex-boyfriends/ (https://morningquotes.online/quotes-for-ex-boyfriends/" target="_blank)
https://morningquotes.online/quote-about-missing-someone-you-love/ (https://morningquotes.online/quote-about-missing-someone-you-love/" target="_blank)
https://morningquotes.online/good-morning-quote-for-him/ (https://morningquotes.online/good-morning-quote-for-him/" target="_blank)
https://morningquotes.online/thursday-motivational-quotes/ (https://morningquotes.online/thursday-motivational-quotes/" target="_blank)
https://morningquotes.online/sunday-motivational-quotes/ (https://morningquotes.online/sunday-motivational-quotes/" target="_blank)
https://morningquotes.online/quotes-on-sacrificing/ (https://morningquotes.online/quotes-on-sacrificing/" target="_blank)
https://morningquotes.online/morning-workout-quote/ (https://morningquotes.online/morning-workout-quote/" target="_blank)
https://morningquotes.online/fit-girl-quotes/ (https://morningquotes.online/fit-girl-quotes/" target="_blank)
https://morningquotes.online/sad-and-depressing-quotes/ (https://morningquotes.online/sad-and-depressing-quotes/" target="_blank)
https://morningquotes.online/hurting-quotes-for-him/ (https://morningquotes.online/hurting-quotes-for-him/" target="_blank)
https://morningquotes.online/hurting-quotes-for-her/ (https://morningquotes.online/hurting-quotes-for-her/" target="_blank)
https://morningquotes.online/cheer-up-quotes-for-friends/ (https://morningquotes.online/cheer-up-quotes-for-friends/" target="_blank)