You need to sign in to do that
Don't have an account?
harish reddy 50
updating checkboxs on case object based on account multipicklist values
my scenario: i have multipicklist field multivaue__c (first,second,third,fourth,fifth) on account when ever i select some values in picklist field then corresponding checkbox field on case with same names first__c,second__c...,should be checked,As account and case have lookup relation i have written trigger on case
problem:how should i check each multi picklist value in if condition
Here is my code:
trigger boxTrigger on case (before insert) {
LIST<id> ids = new LIST<id>();
LIST<case> cse=new lIST<case>();
for(case cse1:trigger.new)
{
ids.add(cse1.accountid);
}
List<account> acc = [select multivalue__c,(select id,first__c,second__c,third__c,fourth__c,fifth__c from cases)from account where id in:ids];
for(account acc1:acc)
{
for( case cse1:acc1.cases)
{
if(acc1.multivalue__c.contains('first'))
{
cse1.first__c= true;
}
cse.add(cse1);
}
}
update cse;
}
problem:how should i check each multi picklist value in if condition
Here is my code:
trigger boxTrigger on case (before insert) {
LIST<id> ids = new LIST<id>();
LIST<case> cse=new lIST<case>();
for(case cse1:trigger.new)
{
ids.add(cse1.accountid);
}
List<account> acc = [select multivalue__c,(select id,first__c,second__c,third__c,fourth__c,fifth__c from cases)from account where id in:ids];
for(account acc1:acc)
{
for( case cse1:acc1.cases)
{
if(acc1.multivalue__c.contains('first'))
{
cse1.first__c= true;
}
cse.add(cse1);
}
}
update cse;
}
Try the below one:
trigger UpdateChildbasedonParent1 on case (before insert)
{
set<id> AccIds=new set<id>();
for(case con:trigger.new)
{
AccIds.add(con.AccountId);
}
map<Id,Account> RelatedAccounts = new map<Id,Account>([SELECT Id, Name,multivalue__c FROM Account WHERE Id IN :AccIds]);
for(case con:trigger.new)
{
Account Related=RelatedAccounts.get(con.AccountId);
If(con.first__c==false && Related.multivalue__c.contains('first'))
con.first__c=true;
}
}
Let me know if it works or not!!!
If it works mark this as a best answer!!!
Thanks,
Raj
Try the below which is modified from your code Its works to me:
trigger boxTrigger on case (before insert) {
LIST<id> ids = new LIST<id>();
LIST<case> cse=new lIST<case>();
for(case cse1:trigger.new)
{
ids.add(cse1.accountid);
}
account acc = [select Id,multivalue__c from account where id in:ids];
for( case cse1:trigger.new)
{
if(acc.multivalue__c.contains('first'))
{
cse1.first__c= true;
}
}
}
Can you please Let me know if it works or not and also If you face any problems!!!
If it works don't forget to mark this as a best answer!!!
Thanks,
Raj
Thanks,
Raj