Thank you for taking the time to read my question, I am new to Salesforce but have experience in Java, SQL and other languages.

I am creating a Trigger on Opportunity that will create a Contract, the question I have is since my company uses Many Opportunity Page Layouts, I want the Contracts to only be created if the user is on a certain Layout.

Example: Opportunity Layouts are: Admins, HService, Maintenance Renewal,Opportunity ,SALES.

If Opportunity Layout is HService then run trigger. but I do not see a way I can do this.

Any help would be greatly appreciated, Thank you very much


This is impossible. Triggers operate on the database level and can be initiated from many different places (the page layout, api, your custom code, etc.) so there is nothing in the trigger to indicate what initiated the DML operation.

What you can do is figure out the business logic that drives which layouts appear to which users (this is based on a combination of recordtype and user profile) and put this logic into your trigger. You would access these in your trigger as follows:

for(Opportunity opp : trigger.new) Id recordtypeID = opp.recordtypeID;
ID profileID = Userinfo.getProfileId();
  • Thank you grigriforce, it seems you are correct. I will create a record type and then do a if(opp.recordType == 'HService') – jnoel10 Feb 12 '13 at 16:06
  • @jnoel10 that is definitely the approach to go with if it works for you from a business logic perspective. – Greg Grinberg Feb 12 '13 at 16:10
  • Just to add, I found the recordTypeID of the opportunity so I could do for(Opportunity opp: trigger.new){ If(Opp.recordtypeId == '01240000000UX51AAG'){ Code.... }} – jnoel10 Feb 12 '13 at 16:17
  • @jnoel10 you shouldn't hard-code the recordtypeID in there as this might be different in sandbox and production. – Greg Grinberg Feb 12 '13 at 17:29
  • Alright, I was just trying to do as little queries as possible. – jnoel10 Feb 12 '13 at 18:25

There is a round-about, and imperfect, way of handling this. Page Layouts are set by Record Type and Profile so your Trigger would need to examine those.

As grigriforce mentions, you would not be able to distinguish if the update came from the UI or some other means, but it might be enough for your situation.

  • Thanks Mike, that is the approach I am going to go with ! – jnoel10 Feb 12 '13 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.