+ Start a Discussion
MalakondaiahMalakondaiah 

Is it possible to implement the custom button instead of apex trigger?

Hi All,

I have list of records(Age and cost), these list of records inserted into custom settings, in this scenario i have written before insert,before update trigger then i mapped the custom settings values into account object field values.

Working fine. But we need a custom button for this functionality.

How to achieve this, could you please guide me.

Thanks,
Malakondaiah

 
Amit Chaudhary 8Amit Chaudhary 8
YEs you can create Button for same, Can you please post your Trigger code.
MalakondaiahMalakondaiah
Hi Amit,

Below is my trigger...
  
  trigger CostAccount on Account (Before Insert, Before Update) 

    {  
        // Custom Settings
        List<customsetting__c> settings1 = customsetting__c.getall().Values();
        List<customsetting2__c> settings2 = customsetting2__c.getall().Values();
        List<customsetting3__c> settings3 = customsetting3__c.getall().Values();
       List<customsetting4__c> settings4 = customsetting4__c.getall().Values();
        
for(Account acc : Trigger.new)
        {
    
                    for(customsetting__c setting : settings1 ){
                             
                           
                            if(acc.picklist1__c =='2.500 €' && setting.Name==acc.Age__c){  
                                             
                              Decimal cost  = setting.price__c;
                              acc.field1__c = cost; 
                              }
                            
                              if(acc.picklist2__c  =='2.500 €' && setting.Name==acc.Age2__c){
                              Decimal cost1  = setting.price__c;
                              acc.field2__c=cost1;                         
                             }                       
                    }
                           
                
                    for(customsetting2__c setting50 : settings2 ){
                
                        if(acc.picklist1__c=='5.000 €' && setting50.Name==acc.Age__c){   
                                            
                              Decimal cost  = setting50.price__c;
                              acc.field1__c = cost; 
                              }
                               
                              if(acc.picklist2__c  =='5.000 €' && setting50.Name==acc.Age2__c){
                              Decimal cost1  = setting50.price__c;
                              acc.field2__c=cost1;                        
                        }
                    }            
                  
                    for(customsetting3__c setting70 : settings3 ){
                
                         if(acc.picklist1__c=='7.500 €' && setting70.Name==acc.Age__c){  
                                              
                              Decimal cost  = setting70.cost__c;
                              acc.field1__c = cost; 
                              }
                              if (acc.picklist2__c =='7.500 €' && setting70.Name==acc.Age2__c){
                              Decimal cost1  = setting70.price__c;
                              acc.field2__c=cost1;  
                                                     
                             }                       
                        }
                                  
                
                    for(customsetting4__c setting10 : settings3 ){
                
                        if(acc.picklist1__c=='10.000 €' && setting10.Name==acc.Age__c){                       
                              Decimal cost  = setting10.price__c;
                              acc.field1__c = cost;  
                              }
                               if(acc.picklist2__c =='10.000 €' && setting10.Name==acc.Age2__c){
                              Decimal cost1  = setting10.price__c;
                              acc.field2__c=cost1;                         
                        }
                    }            
                                 
        }
        
    }