+ Start a Discussion
David OvellaDavid Ovella 

In my standard page, Can a button be shown depending of the value of a custom field?

Hello experts

this is my standard page, and the button that I want to appear/disappear is "Crear Factura" depending of
the value of the field "Sucursal__c" which is a picklist
User-added image

If(Sucursal__c=="Maker Centro",true,false)
How can I do this in the standard page?
​any code would be really helpful
 
Best Answer chosen by David Ovella
RAM AnisettiRAM Anisetti
Hi,

follow the below steps...

step 1)
Create two recordtypes of ur object,names like DisableButton ,EnableButton

for EnableButton,assign pagelayout having "Crear Factura" button
for DisableButton,assign pagelayout which is not having "Crear Factura" button

step 2)
write a trigger like below(replace yourobject__C with ur object)
 
trigger TestCodetrigger on yourobject__C (before insert, before update) {


  RecordType rt = [select Id,name from RecordType where Name ='DisableButton' and SobjectType = 'yourobject__C'];

   for (yourobject__C ob : trigger.new)  {

      
      If(ob.Sucursal__c=="Maker Centro") { 
            
            
                // Then automatically change the Record Type to DisableButton recordtype
                
               
               ob.RecordTypeid = rt.id; 
            
       }
   }
}

 

All Answers

RAM AnisettiRAM Anisetti
Hi,

follow the below steps...

step 1)
Create two recordtypes of ur object,names like DisableButton ,EnableButton

for EnableButton,assign pagelayout having "Crear Factura" button
for DisableButton,assign pagelayout which is not having "Crear Factura" button

step 2)
write a trigger like below(replace yourobject__C with ur object)
 
trigger TestCodetrigger on yourobject__C (before insert, before update) {


  RecordType rt = [select Id,name from RecordType where Name ='DisableButton' and SobjectType = 'yourobject__C'];

   for (yourobject__C ob : trigger.new)  {

      
      If(ob.Sucursal__c=="Maker Centro") { 
            
            
                // Then automatically change the Record Type to DisableButton recordtype
                
               
               ob.RecordTypeid = rt.id; 
            
       }
   }
}

 
This was selected as the best answer
RAM AnisettiRAM Anisetti
you can also replace step 2 with workflows..