• Mohan_Shanmugam
  • NEWBIE
  • 159 Points
  • Member since 2011
  • Salesforce Developer
  • TECOM Group

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 14
    Replies
Hi ,

Can some one help me to write a trigger to prevent delete of all Account records and its supporting test class.
Doesn't matter who the user is (Sys Admin/Custom Profile/Read Only...etc), the user should not be able to delete the account record.
There cannot be any exception.

Any help is appreciate.
Thanks!
A
Hi everyone,

I have a requirement that needs me to link a user id field on a custom object to another user id field on the opportunity object. When the id field is updated from either object, I want the corresponding field on the other object to update with the same user. The custom and opportunity objects are connected to each other by two lookup relationship fields. (Implementation__c on the Opportunity and Opportunity__c on the custom object)  These are the two triggers I wrote:

1 trigger UpdateESS on Opportunity (after insert, after update) {
2
3      List<ID> ImpIds = New List<ID>();
4
5       for(Opportunity o : Trigger.new){
6       if(o.Assigned_trainer__c != null && o.Implementation__r.Education_Support_Specialist__c  == null){
7           ImpIds.add(o.Implementation__c); 
8       } 
9   }
10     
11   
12  List<Implementation__c> ImpList = [SELECT id, Education_Support_Specialist__c, opportunity__c FROM Implementation__C WHERE id in :ImpIds];
13   
14   Map<id,Opportunity> mImptoOpp = New Map<id,Opportunity>();
15       for(Opportunity k : trigger.new){
16           if(k.Assigned_Trainer__c != null && k.Implementation__r.Education_Support_Specialist__c == null){ 
17               mImptoOpp.put(k.implementation__c, k);              
18           }
19       }    
20  for(integer i = 0 ; i < ImpList.size(); i++){ 
21    ImpList[i].Education_Support_Specialist__c = mImptoOpp.get(ImpList[i].id).Assigned_Trainer__c;
22    }        
23 Update ImpList;
24 }

1 trigger UpdateAssignedTrainer on Implementation__c (after insert, after update) {
2
3   List<ID> OppIds = New List<ID>();
4
5   for(Implementation__c o : Trigger.new){
6       if(o.Education_Support_Specialist__c != null && o.Opportunity__r.Assigned_Trainer__c == null){
7           OppIds.add(o.Opportunity__c);  
8       } 
9   }  
10   
11   List<Opportunity> OppList = [SELECT id, Assigned_Trainer__c, implementation__c FROM Opportunity WHERE id in :OppIds];
12   
13   Map<id,Implementation__c> mImptoOpp = New Map<id,Implementation__c>();
14       for(Implementation__c k : trigger.new){
15           if(k.Education_Support_Specialist__c != null && k.Opportunity__r.Assigned_Trainer__c  == null){ 
16               mImptoOpp.put(k.Opportunity__c, k);
17           }
18       } 
19   
20 for(integer i = 0 ; i < OppList.size(); i++){ 
21    OppList[i].Assigned_Trainer__c = mImptoOpp.get(OppList[i].id).Education_Support_Specialist__c; 
22    } 
23 Update OppList;  
24 }

The two triggers are essentially identical, except they are initiated by and update the opposite object. The issue I'm having (at least I think this is what's happening) is that the DML statement that saves the changes to the database actually causes the other trigger to fire, creating the infinite loop.  I tried adding conditions to the trigger that would prevent the loop, but I think the trigger executes before the new data value can be comitted to the database. Is it possible to stop the DML statement from firing the second trigger? Could combining these triggers resolve the issue? Any advice would be much appreciated.

Here's the actual error in case I am misunderstanding what is happening:

Error:Apex trigger UpdateESS caused an unexpected exception, contact your administrator: UpdateESS: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0BW000000JNK7aMAH; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateAssignedTrainer: maximum trigger depth exceeded Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a] Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a] Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a] Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a] Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a] Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a] Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a] Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a]: []: Trigger.UpdateESS: line 23, column 1

Hi there,

I'm hoping someone might be able to help me!

I want to create a custom formula field, which brings back a specific result based on what's been selected from a custom picklist that I've created. Below are picklist values against the results that I need returning.

CPM = 1,000
CPC = 1
CPL = 1
CPA = 1

The custom field that I've created is called Pricing_Metric__c

Any help/guidence would be awesome. I've tried CASE, IF... and the only result I seem to be achieving is a loss of hair, which I'm gradually pulling out!

Thanks,

Paul
Here is my code.
trigger TLIYear1Rollup on Template_Line_item__c (after insert, after update) {

    Map<ID, Apttus_Proposal__Proposal__c> parentProposal = new Map<ID, Apttus_Proposal__Proposal__c>();
    List<Id> listIds = new List<Id>();
    List<Id> LineItems = new List<Id>();

    for (Template_Line_item__c childObj : Trigger.new) {
        listIds.add(childObj.Quote_Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,TLI_Net_Price_Rollup__c ,(Select id, Net_Price__c, Year_2_Price_Form__c, Year_3_Price_Form__C, Year_4_Price_Form__c, Year_5_Price_Form__C from Template_Line_Items__r where net_price__c > 0) FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Template_Line_item__c TemplateLineItem: Trigger.new){
         Apttus_Proposal__Proposal__c myParentProposal = parentProposal.get(TemplateLineItem.Quote_Proposal__c);
        if(parentProposal.containsKey(TemplateLineItem.Quote_Proposal__c) && parentProposal.get(TemplateLineItem.Quote_Proposal__c).Template_Line_Items__r.size() > 0)
        {
            myParentProposal.TLI_Net_Price_Rollup__c = SUM(ParentProposal.Net_Price__C);
        }
        else
        {
            myParentProposal.TLI_Net_Price_Rollup__c = 0 ;
        }
    }
    update parentProposal.values();
 }

 
Hi Experts,

I have requirement that is If text is entered in field NCT04b Material and Plant Storage(NCT04b_Material_and_Plant_Storage__c), on selecting Save button,  check box field NCT04 Material & Plant Storage((NCT04_Material_Plant_Storage__c)  should be true,
If text is removed/deleted from field the NCT04b Material and Plant Storage(NCT04b_Material_and_Plant_Storage__c), corresponding  chek box field is unchecked =(false). like this there are 11 text fields and 11 checkbox fields are there. Could you anyone help me please
Hi ,

Can some one help me to write a trigger to prevent delete of all Account records and its supporting test class.
Doesn't matter who the user is (Sys Admin/Custom Profile/Read Only...etc), the user should not be able to delete the account record.
There cannot be any exception.

Any help is appreciate.
Thanks!
A
Hi everyone,

I have a requirement that needs me to link a user id field on a custom object to another user id field on the opportunity object. When the id field is updated from either object, I want the corresponding field on the other object to update with the same user. The custom and opportunity objects are connected to each other by two lookup relationship fields. (Implementation__c on the Opportunity and Opportunity__c on the custom object)  These are the two triggers I wrote:

1 trigger UpdateESS on Opportunity (after insert, after update) {
2
3      List<ID> ImpIds = New List<ID>();
4
5       for(Opportunity o : Trigger.new){
6       if(o.Assigned_trainer__c != null && o.Implementation__r.Education_Support_Specialist__c  == null){
7           ImpIds.add(o.Implementation__c); 
8       } 
9   }
10     
11   
12  List<Implementation__c> ImpList = [SELECT id, Education_Support_Specialist__c, opportunity__c FROM Implementation__C WHERE id in :ImpIds];
13   
14   Map<id,Opportunity> mImptoOpp = New Map<id,Opportunity>();
15       for(Opportunity k : trigger.new){
16           if(k.Assigned_Trainer__c != null && k.Implementation__r.Education_Support_Specialist__c == null){ 
17               mImptoOpp.put(k.implementation__c, k);              
18           }
19       }    
20  for(integer i = 0 ; i < ImpList.size(); i++){ 
21    ImpList[i].Education_Support_Specialist__c = mImptoOpp.get(ImpList[i].id).Assigned_Trainer__c;
22    }        
23 Update ImpList;
24 }

1 trigger UpdateAssignedTrainer on Implementation__c (after insert, after update) {
2
3   List<ID> OppIds = New List<ID>();
4
5   for(Implementation__c o : Trigger.new){
6       if(o.Education_Support_Specialist__c != null && o.Opportunity__r.Assigned_Trainer__c == null){
7           OppIds.add(o.Opportunity__c);  
8       } 
9   }  
10   
11   List<Opportunity> OppList = [SELECT id, Assigned_Trainer__c, implementation__c FROM Opportunity WHERE id in :OppIds];
12   
13   Map<id,Implementation__c> mImptoOpp = New Map<id,Implementation__c>();
14       for(Implementation__c k : trigger.new){
15           if(k.Education_Support_Specialist__c != null && k.Opportunity__r.Assigned_Trainer__c  == null){ 
16               mImptoOpp.put(k.Opportunity__c, k);
17           }
18       } 
19   
20 for(integer i = 0 ; i < OppList.size(); i++){ 
21    OppList[i].Assigned_Trainer__c = mImptoOpp.get(OppList[i].id).Education_Support_Specialist__c; 
22    } 
23 Update OppList;  
24 }

The two triggers are essentially identical, except they are initiated by and update the opposite object. The issue I'm having (at least I think this is what's happening) is that the DML statement that saves the changes to the database actually causes the other trigger to fire, creating the infinite loop.  I tried adding conditions to the trigger that would prevent the loop, but I think the trigger executes before the new data value can be comitted to the database. Is it possible to stop the DML statement from firing the second trigger? Could combining these triggers resolve the issue? Any advice would be much appreciated.

Here's the actual error in case I am misunderstanding what is happening:

Error:Apex trigger UpdateESS caused an unexpected exception, contact your administrator: UpdateESS: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0BW000000JNK7aMAH; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateAssignedTrainer: maximum trigger depth exceeded Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a] Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a] Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a] Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a] Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a] Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a] Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a] Opportunity trigger event AfterUpdate for [006W000000605S1] Implementation trigger event AfterUpdate for [a0BW000000JNK7a]: []: Trigger.UpdateESS: line 23, column 1

Hi there,

I'm hoping someone might be able to help me!

I want to create a custom formula field, which brings back a specific result based on what's been selected from a custom picklist that I've created. Below are picklist values against the results that I need returning.

CPM = 1,000
CPC = 1
CPL = 1
CPA = 1

The custom field that I've created is called Pricing_Metric__c

Any help/guidence would be awesome. I've tried CASE, IF... and the only result I seem to be achieving is a loss of hair, which I'm gradually pulling out!

Thanks,

Paul
Here is my code.
trigger TLIYear1Rollup on Template_Line_item__c (after insert, after update) {

    Map<ID, Apttus_Proposal__Proposal__c> parentProposal = new Map<ID, Apttus_Proposal__Proposal__c>();
    List<Id> listIds = new List<Id>();
    List<Id> LineItems = new List<Id>();

    for (Template_Line_item__c childObj : Trigger.new) {
        listIds.add(childObj.Quote_Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,TLI_Net_Price_Rollup__c ,(Select id, Net_Price__c, Year_2_Price_Form__c, Year_3_Price_Form__C, Year_4_Price_Form__c, Year_5_Price_Form__C from Template_Line_Items__r where net_price__c > 0) FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Template_Line_item__c TemplateLineItem: Trigger.new){
         Apttus_Proposal__Proposal__c myParentProposal = parentProposal.get(TemplateLineItem.Quote_Proposal__c);
        if(parentProposal.containsKey(TemplateLineItem.Quote_Proposal__c) && parentProposal.get(TemplateLineItem.Quote_Proposal__c).Template_Line_Items__r.size() > 0)
        {
            myParentProposal.TLI_Net_Price_Rollup__c = SUM(ParentProposal.Net_Price__C);
        }
        else
        {
            myParentProposal.TLI_Net_Price_Rollup__c = 0 ;
        }
    }
    update parentProposal.values();
 }

 
Looking for Salesforce Job having 3 years of experience in salesforce  with certifications (Salesforce Certified Platform Developer I,Salesforce Certified Platform Developer II(first Level),Salesforce Certified Administrator,Salesforce Certified Service Cloud Consultant,Salesforce Certified Force.com Developer)(Immediately Available). 

Thanks & Regard,

(+971 - 554315139)