You need to sign in to do that
Don't have an account?
Thomas Gordon 20
soql gone mad...
select id, name from account where name = :user.userrole.name
does not return anything due to an error in this query. the bind variable is used in a different query so it is valid as a value. This must be a relationship issue. Can anybody confirm or offer a fix please?
does not return anything due to an error in this query. the bind variable is used in a different query so it is valid as a value. This must be a relationship issue. Can anybody confirm or offer a fix please?
Please look into the below SOQL:
Please do let me know if it helps you.
Regards,
Mahesh
If you want to fatch any information for login user then please check below post.
UserInfo Class
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_userinfo.htm
To Learn about SOQL please check below post.
From SQL to SOQL
1) https://developer.salesforce.com/page/From_SQL_to_SOQL
A Deeper look at SOQL and Relationship Queries on Force.com
1) https://developer.salesforce.com/page/A_Deeper_look_at_SOQL_and_Relationship_Queries_on_Force.com
Some use full link for you
1) https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL.htm
I recommend you to please check below trailhead module
1) https://developer.salesforce.com/trailhead/en/apex_database/apex_database_soql
If you want to learn the Dynamic SOQL and variable binding please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm
2) http://www.sfdc99.com/2013/11/04/using-apex-variables-in-a-soql-query/
Example 1:- Salesforce knows you’re using a bind variable when you precede your Apex variable with a colon (:) –
Please let us know if this will help you
Thanks,
Amit Chaudhary
Map <String, String> Users = new Map <String, String>();
for (Contact Con : Trigger.new){
Users.put(name,User.userrole.name);
for (Account a: [select Id, name from Account where Name = :user.userrole.name]){
Users.put ('user.userrole.name', a.name);
for(User usr:[select Id, name,userrole.name from User]){
if(Usr!= null ||con.Account.Name != user.userrole.name){
update(con);
Mahesh,This is the entire trigger. ..not using Account obj as Accounts (BHinners). Whole thing is prob a train wreck. Supposed to update field on contacts from Userrole that owns the contact by mapping them...'put' lines are a mess too. ..my first trigger!..at least it has structure lol
Where are you setting values for fields on the Contacts?
Please provide the actual requirement. What exactly you are trying to achieve.
You have written the code with all SOQLs inside the for loop which is not a best practice.
Regards,
Mahesh
Please copy your full trigger which you have written by using the above Panel (< >) so that we can able to read it properly.
Also where is the mission name and what is its API Name.
Regards,
Mahesh
Im taking the mission name from the User that owns the contact. It is the user.userrole.name field. Above is a new approach using 2 Lists and Map. Still need to update the field on the Contact which is actually c.account.name