function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Forrest Muldune 36Forrest Muldune 36 

opportunity record type

I have created the trigger below


trigger Opportunity_CS_Default_Stage on Opportunity (before insert) {
      for(Opportunity opp: trigger.new){
           opp.stagename = 'Identification';
     }
}


How can I update this trigger so that it will only updated the stagename = 'Identification' , and when the Opportunity Record type name = Concept_Team     only ?
sfdcMonkey.comsfdcMonkey.com
Hi Forrest, use below trigger :
 
trigger Opportunity_CS_Default_Stage on Opportunity (before insert) {
      for(Opportunity opp: trigger.new){
	  Id recIdConceptTeam = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Concept_Team').getRecordTypeId();
	   system.debug(recIdConceptTeam);
	    if(recIdConceptTeam == opp.recordTypeId){
		  opp.stagename = 'Identification';
		}  
     }
}
Note : Id recIdConceptTeam = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Concept_Team').getRecordTypeId();
in above statement use developer name of record type here( bold text above) :

if it helps you, closed your query with choosing best answer so it make proper solution for others in future
Thanks
Forrest Muldune 36Forrest Muldune 36
Piyushi,

I appreciate your trigger, however when I created a new opportunity using the Concept_Team record type, the value "Identification"  did not populate in the stagename field. I know the Sobject Type is  Opportunity as well. 

do you know what could be the issue?
Forrest Muldune 36Forrest Muldune 36
I checked the picklist and "Identification" is available in the Stagename field for Concept_Team record type in opportunity
Forrest Muldune 36Forrest Muldune 36
below is what I checked

Trigger is active


The Record Type developer name is actually Concept_Systems , I updated this part of the code    get('Concept_Systems')    but it still did not work.

in the Concept System sales process, Identification value is located in the "Available Values" View. I moved it to the "Selected Values" view and it still did not work.

I have permission to this record type

View code below after I updated the record type name. 


trigger Opportunity_CS_Default_Stage on Opportunity (before insert) {
      for(Opportunity opp: trigger.new){
      Id recIdConceptSystems = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Concept_Systems').getRecordTypeId();
       system.debug(recIdConceptSystems);
        if(recIdConceptSystems == opp.recordTypeId){
          opp.stagename = 'Identification';
        }  
     }
}


Do you know what could be the issue?
HARSHIL U PARIKHHARSHIL U PARIKH
If you have any other triggers running on an Opportunity or surrounded objects then deactivate them for now and check your original trigger..
Forrest Muldune 36Forrest Muldune 36
I turned off all the Opportunity triggers and still the same. 

After selecting the "new" button on an Opportunity where Concept_System is the record type, the Identification value is not displayed in the opportunity stage before I save it. 
HARSHIL U PARIKHHARSHIL U PARIKH
Wait.. Are you trying to auto populate stage name as "Identification" before you save the record for a specific record type? If yes, then you do not need a trigger but rather a configuration of record type specific picklist.

Go to the record type and see the values of picklist and make "Identification" as default.

The purpose of trigger is not to auto populate values before SAVE. URL hacking would do that.
Forrest Muldune 36Forrest Muldune 36
Harshil,

I appreciate your feedback. the Field I am trying to set the default value is on the Opportunity Stage. This field is not located on the Record Type but It is located in the standard field and I was unable to set a default value there. 

I found this website on Ideas https://success.salesforce.com/ideaView?id=08730000000BrKdAAK and I read the comment below

"Workaround doesn't work for Opportunity Stage since it is a required field, why is it so hard to make a new Opportunity default to a stage that it almost always starts in?"

will URL hacking solve this issue? if yes, could you send me some helpful URL hacking solution?