You need to sign in to do that
Don't have an account?

Fetch the records for the picklist value as 10.
Hi Developers ,
Can any one help me on this requirement .
i have a requirement , in an Account object i have 10000 records and picklist field with the values as 10,20,30,40 ,50.i would like to fetch the records for the picklist value as 10.how do u query on this?
Thanks In Advance
Hi,
Hitesh is right, but your trigger will update all account records, so i think you also need to check one more condition in your for loop
for(Account acc : Trigger.new) {
if(acc.PicklistField__c == '10') {
//Your logic
}
}
In that case it update records if PicklistField__c field value is 10
Thanks
Hit the Kudos button (star) and Mark as solution if it post helps you
All Answers
Hi nik,
Your SOQL query on account object is like below.
SOQL query:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/
Hi Nikkey,
You can write your query like
List<Account> accounts = [Select Id, Name, picklist field From Account Where picklist field = '10' ];
Thanks
Hit the Kudos button (star) and Mark as solution if it post helps you
Hi Subhash and Hitesh ,
thanks for ur rply .
i have written the code it got saved but whn i create a record it throws an ERROR as:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger fetchpicklistvalue caused an unexpected exception, contact your administrator: fetchpicklistvalue: execution of BeforeInsert caused by: System.SObjectException: DML statment cannot operate on trigger.new or trigger.old: Trigger.fetchpicklistvalue: line 13, column 1.
trigger fetchpicklistvalue on account(before insert,before update)
{
//if(trigger.isinsert || trigger.isupdate)
list<account> alist = new list<account>();
list<account> acc = [select id,name,PicklistField__c from account where PicklistField__c='10'];
for(account a : trigger.new)
{
a.name='xyz';
alist.add(a);
}
if(alist.size()>0 && alist.size()!=null)
{
update alist;
}
}
Request to kindly check and do the needful.
Thanks in Advance
Hi nik,
In before trigger you don't need to write DML statement in your trigger.
I have updated your code see below trigger.
Apex Trigger:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/
Hi,
Hitesh is right, but your trigger will update all account records, so i think you also need to check one more condition in your for loop
for(Account acc : Trigger.new) {
if(acc.PicklistField__c == '10') {
//Your logic
}
}
In that case it update records if PicklistField__c field value is 10
Thanks
Hit the Kudos button (star) and Mark as solution if it post helps you
hi hitesh and subhash ,
Thanks for ur rply.
i appreciate ur help.