• Johnie Jones
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

Hello, I try to bulkify following trigger, but without any success. Any help will be highly appreciated. Thanks!

 

 

trigger BIBU_Asset_Checks on Asset__c (before insert, before update) {

    for(Asset__c myAsset : trigger.new){

// Disables to attach to an asset a name that has been already assigned to another asset.
   
        Asset__c[] duplicateAssets = [SELECT Name FROM Asset__c WHERE Name = :myAsset.Name and Id != :myAsset.Id];
   
        if(duplicateAssets.size() > 0){
            myAsset.addError('You cannot attach to an asset a name that has been already assigned to another asset.');
        } 
    }

}

Hello, I try to bulkify following trigger, but without any success. Any help will be highly appreciated. Thanks!

 

 

trigger BIBU_Asset_Checks on Asset__c (before insert, before update) {

    for(Asset__c myAsset : trigger.new){

// Disables to attach to an asset a name that has been already assigned to another asset.
   
        Asset__c[] duplicateAssets = [SELECT Name FROM Asset__c WHERE Name = :myAsset.Name and Id != :myAsset.Id];
   
        if(duplicateAssets.size() > 0){
            myAsset.addError('You cannot attach to an asset a name that has been already assigned to another asset.');
        } 
    }

}

i Have an issue with my trigger, it is very simple one, basically it takes credit card type and expiry date from payment and put it up one level on Invoice, for reporting purposes. it works fine when a single payment is inserted however when i do bulk upload of new payments i get this error

System.LimitException: Too many DML statements: 151

 

here is my code below any help wpuld be greatly apreciated

trigger CC_Exp on Payment__c (after insert, after update) {
Set<id> objSet = new Set<id>();  

for(Payment__c objOpp:trigger.new)

{

objSet.add(objOpp.Invoice__c);

}

List<Invoice__c> myInvoice = [select Id,Status__c from Invoice__c where Id in: objSet];

for(Payment__c objOpp:Trigger.new)

{

for(Invoice__c objAcc: myInvoice)

{

if (objOpp.Payment_Method__c == 'Credit Card') {

{

objAcc.CC_Expiry_Date__c = objOpp.Expiry_Date__c;//
objAcc.Creditcard_Type__c = objOpp.Credit_card_Type__c;//
update objAcc;
}}}
}}

 

  • July 21, 2011
  • Like
  • 0