I am getting multiple request from other system, i am updating in the field Update__c with value when value is true at that time check-box is checking, suppose if i get multiple request only for 1st request the check box is checking remain all cases not
How can i change this for bulk update **quotes[0].Sys_checkchild__c =true; // How can chage for this bulk updates. it checking for only 1 record.**
trigger targerquaote on Quote_Item__c (after insert,after update) {
public boolean checkallchildrecs;
set<id>idset=new set<id>();
set<id>quoteidset=new set<id>();
for(Quote_Item__c qq:trigger.new){
idset.add(qq.id);
quoteidset.add(qq.Quote__c);
}
list<Quote_Item__c>qit1=[select id,name,Quote__c from Quote_Item__c where Quote__c IN:quoteidset];
list<Quote_Item__c>qit2=[select id,name,Quote__c from Quote_Item__c where Quote__c IN:quoteidset AND (Updated__c = 'true' OR Updated__c = 'sss')];
list<Quote_Item__c>qit3=[select id,name,Quote__c from Quote_Item__c where Quote__c IN:quoteidset AND Updated__c = 'false' ];
List<Quote__c> quotes=[select id, name,Sys_checkchild__c from Quote__c where Id IN:quoteidset];
if (quotes.size() > 0) {
integer wholerecords=qit1.size();
integer specificrecords=qit2.size();
for (Quote__c quote : quotes) {
if(wholerecords==specificrecords){
**quotes[0].Sys_checkchild__c =true; // How can chage for this bulk updates. it checking for only 1 record.**
update quotes;
}else if(qit3.size()>0){
quotes[0].Sys_checkchild__c =false;
quotes[0].Updated__c = 'false';
update quotes;
}
}
}
}
Attribution to: Sathya
Possible Suggestion/Solution #1
The code below is a version of your trigger with the special case of index 0 removed which I think is what you are asking for:
trigger targerquaote on Quote_Item__c (after insert,after update) {
set<id>quoteidset=new set<id>();
for(Quote_Item__c qq:trigger.new){
quoteidset.add(qq.Quote__c);
}
list<Quote_Item__c>qit1=[select id,name,Quote__c from Quote_Item__c where Quote__c IN:quoteidset];
list<Quote_Item__c>qit2=[select id,name,Quote__c from Quote_Item__c where Quote__c IN:quoteidset AND (Updated__c = 'true' OR Updated__c = 'sss')];
list<Quote_Item__c>qit3=[select id,name,Quote__c from Quote_Item__c where Quote__c IN:quoteidset AND Updated__c = 'false' ];
List<Quote__c> quotes=[select id, name,Sys_checkchild__c from Quote__c where Id IN:quoteidset];
if (quotes.size() > 0) {
integer wholerecords=qit1.size();
integer specificrecords=qit2.size();
for (Quote__c quote : quotes) {
if(wholerecords==specificrecords){
quote.Sys_checkchild__c = true;
}else if(qit3.size()>0){
quote.Sys_checkchild__c =false;
quote.Updated__c = 'false';
}
}
update quotes;
}
}
Note that instead of performing (time and governor limit) expensive queries to get the counts (such as wholerecords
) you could just loop over the Trigger.new collection and add up the totals like this:
trigger targerquaote on Quote_Item__c (after insert, after update) {
Set<Id> quoteidset = new Set<Id>();
Integer wholerecords = Trigger.new.size();
Integer specificrecords = 0;
Integer falserecords = 0;
for (Quote_Item__c qi : Trigger.new) {
quoteidset.add(qi.Quote__c);
if (qi.Updated__c == 'true' || qi.Updated__c == 'sss') {
specificrecords++;
}
if (qi.Updated__c == 'false') {
falserecords++;
}
}
List<Quote__c> quotes = [select Id from Quote__c where Id IN :quoteidset];
for (Quote__c quote : quotes) {
if (wholerecords == specificrecords) {
quote.Sys_checkchild__c = true;
} else if (falserecords > 0) {
quote.Sys_checkchild__c = false;
quote.Updated__c = 'false';
}
}
update quotes;
}
Attribution to: Keith C
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/34181