You need to sign in to do that
Don't have an account?
Silpi roy 16
Trigger for Updation
Hi All,
With thebelow code i am trying to update Billing Item Qty=0 ,Based on Document Type in Billing document in salsforce .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
trigger UpdateQty on BillingDoc__c (after insert,after update) {
Set<id> setOfParentId = new Set<Id>();
for(BillingDoc__c BD:trigger.new){
List<BillingItem__c> listBI=new List<BillingItem__c>([Select Id,BillingDocumentId__c,Quantity__c from BillingItem__c where BillingDocumentId__c in: setOfParentId]);
if ( listBI.size() > 0 )
for(BillingItem__c BI : listBI){
if(BD.DocumentTypeCode__c=='ZG2')
{
BI.Quantity__c = 0;
}
listBI.add(BI);
}
}
}
But it is not updating the Quatity=0.
please suggest me if it need some updation.
Thanks,
Silpi
With thebelow code i am trying to update Billing Item Qty=0 ,Based on Document Type in Billing document in salsforce .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
trigger UpdateQty on BillingDoc__c (after insert,after update) {
Set<id> setOfParentId = new Set<Id>();
for(BillingDoc__c BD:trigger.new){
List<BillingItem__c> listBI=new List<BillingItem__c>([Select Id,BillingDocumentId__c,Quantity__c from BillingItem__c where BillingDocumentId__c in: setOfParentId]);
if ( listBI.size() > 0 )
for(BillingItem__c BI : listBI){
if(BD.DocumentTypeCode__c=='ZG2')
{
BI.Quantity__c = 0;
}
listBI.add(BI);
}
}
}
But it is not updating the Quatity=0.
please suggest me if it need some updation.
Thanks,
Silpi
trigger UpdateQty on BillingDoc__c (after insert,after update) {
List<BillingItem__c> listBI=[Select Id,BillingDocumentId__c, BillingDocumentId__r.DocumentTypeCode__c, Quantity__c from BillingItem__c where BillingDocumentId__c in: trigger.newMap.keyset()];
List<BillingItem__c> updateList = new List<BillingItem__c>();
if ( listBI.size() > 0 ) {
for(BillingItem__c BI : listBI){
if(BI.BillingDocumentId__r.DocumentTypeCode__c=='ZG2')
{
BI.Quantity__c = 0;
updateList.add(BI);
}
}
update updateList;
}
}
All Answers
I am trying to update child object field Quatity based on parent object.
Thanks,
Silpi
Select Id,BillingDocumentId__c,Quantity__c from BillingItem__c where BillingDocumentId__c in: setOfParentId
List<BillingItem__c> listBI=[Select Id,BillingDocumentId__c, BillingDocumentId__r.DocumentTypeCode__c, Quantity__c from BillingItem__c where BillingDocumentId__c in: trigger.newMap.keyset()];
if ( listBI.size() > 0 ) {
for(BillingItem__c BI : listBI){
if(BI.BillingDocumentId__r.DocumentTypeCode__c=='ZG2')
{
BI.Quantity__c = 0;
}
}
update listBI;
}
}
trigger UpdateQty on BillingDoc__c (after insert,after update) {
List<BillingItem__c> listBI=[Select Id,BillingDocumentId__c, BillingDocumentId__r.DocumentTypeCode__c, Quantity__c from BillingItem__c where BillingDocumentId__c in: trigger.newMap.keyset()];
List<BillingItem__c> updateList = new List<BillingItem__c>();
if ( listBI.size() > 0 ) {
for(BillingItem__c BI : listBI){
if(BI.BillingDocumentId__r.DocumentTypeCode__c=='ZG2')
{
BI.Quantity__c = 0;
updateList.add(BI);
}
}
update updateList;
}
}
trigger UpdateQty on BillingDoc__c (after insert,after update) {
Set<id> setOfParentId = new Set<Id>();
List<BillingItem__c> updateList = new List<BillingItem__c>();
List<BillingItem__c> listBI=new List<BillingItem__c>([Select Id,BillingDocumentId__c,Quantity__c from BillingItem__c where BillingDocumentId__c in: setOfParentId]);
for(BillingDoc__c BD:trigger.new){
if ( listBI.size() > 0 )
for(BillingItem__c BI : listBI){
if(BD.DocumentTypeCode__c=='ZG2')
{
BI.Quantity__c = 0;
updateList.add(BI);
}
//listBI.add(BI);
}
}
update updateList;
}
In case i want to convert the trigger to a helper class,How can I write the helper class and the Trigger using the helper class.