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
EnozzirEnozzir 

How to use dot notation to reference the record type?

So heres a small portion of my code

 if(newOpp.Go_Live_Date__c != oldOpp.Install_Date__c && newOpp.Go_Live_Date__c != null)
                    newOpp.Install_Date__c = newpp.Go_Live_Date__c;

Now i wanted to add another && to the if statement, but i want to i want it to .... if the opp in question is a record type sales..ie equal to..

how would i go about that?
a1andersa1anders
Use the following org-agnostic pattern to get the Id of the record type:
 
// Replace 'B2B Opportunity' with the name of your opportunity record type

Id opptyId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('B2B Opportunity').getRecordTypeId();

// Whatever your code does...

// Reference the opptyId variable with your sObject

if(newOpp.Go_Live_Date__c != oldOpp.Install_Date__c && 
   newOpp.Go_Live_Date__c != null && 
   newOpp.RecordTypeId == opptyId)
{
   newOpp.Install_Date__c = newpp.Go_Live_Date__c;
}
Best practice: If you are new to Salesforce, make sure that what you are coding cannot be build with the Validation, Workflow, Process Builder, Flows, or any other declarative tool. Clicks not code if possible.