You need to sign in to do that
Don't have an account?
Rasha
how to limit code firing for only one object record type record type
I have an Apex class that has sets a checkbox to true if certian criteria is met. Whet I need to do is to limit this change to only one record type. I'm bewbie to coding in Apex. Any suggestions on where to start from?
how does pse__Assignment__c relate to pse__Proj__c?
You need to get the pse__Proj__c.RecordType and check if that is equal to Schema.SObjectType.pse__Proj__c.getRecordTypeInfosByDeveloperName().get('AEP').getRecordTypeId()
If you dont know how to do this please show from which field does pse__Assignment__c relate to pse__Proj__c
All Answers
Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('PersonAccount').getRecordTypeId();
With that if the the record type is the one you want then you set the checkbox to true.
if this solves your issue please mark this answer as correct, it may help others
Thank you for the reply. When I add this line your provided,
Schema.SObjectType.Project.getRecordTypeInfosByDeveloperName().get('Sourcing').getRecordTypeId();
I get the below error
"Error: Compile Error: Variable does not exist: Schema.SObjectType.Project at line 206 column 9" Any idea why?
Still getting the same error
"Error: Compile Error: Variable does not exist: Schema.SObjectType.Project__c at line 206 column 9"
Id objectRecordTypeId = Schema.SObjectType.CustomObject__c.getRecordTypeInfosByName().get('CustomObject').getRecordTypeId();
Which is the Api name of the object and the developer name of the record type?
And 'AEP' is the dev name for the record type, I get the below error
Error: Compile Error: Method does not exist or incorrect signature: void getRecordTypeInfosByDeveloperName() from the type Schema.DescribeSObjectResult at line 206 column 41
Please show me an image of the record type AEP.
You can try with system.debug(Schema.SObjectType.pse__Proj__c.getRecordTypeInfosByDeveloperName().get('AEP').getRecordTypeId());
Is pse a prefix?
Yes, AEP is the record type name. And yes, pse if a prefix. the Project's object API is "pse__Proj__c"
Error: Compile Error: Method does not exist or incorrect signature: void getRecordTypeInfosByDeveloperName() from the type Schema.DescribeSObjectResult at line 206 column 41
in Setup->Apex classes->your class->Click on Edit and Change your apex class version to 43 by switching to version settings tab .
Why do we need to change the version. Can you please let me kno what impact that would have?
I have updated the version, which then I was able to use this code and save the chane successfully
"Schema.SObjectType.pse__Proj__c.getRecordTypeInfosByDeveloperName().get('AEP').getRecordTypeId();"
Even when saving the changes, the code still seems to work on all record types. I have multiple records, and the code is control a checklist field. When I try to update the checklist field on non AEP record types, the code fires off, and revert my changes.
It wont have a negative impact, if salesforce removes methods for example that may be an impact but if you compile correctly then you should be fine.
Are you using a if(pse__Proj__c.RecordType ==Schema.SObjectType.pse__Proj__c.getRecordTypeInfosByDeveloperName().get('AEP').getRecordTypeId()) then do something condition?
please show me your code.
If you are happy with your progress please like my answers or select them as correct ones.
Regards
When I add the if statement, I get this error "
Error: Compile Error: Condition expression must be of type Boolean: Id at line 207 column 91"
Here is the code:
private void excludeSmallAssignmentsFromPlanner(pse__Assignment__c a) {
Decimal threshold = PSA_General_Settings__c.getInstance().Exclude_from_Planner_Threshold__c;
if(Schema.SObjectType.pse__Proj__c.getRecordTypeInfosByDeveloperName().get('AEP').getRecordTypeId() )//Rasha
{//Rasha
if( threshold == null ) {
return;
}
Decimal numWeeks = a.pse__Start_Date__c.daysBetween( a.pse__End_Date__c ) / 7.0;
if( numWeeks < 1.0 ){
numWeeks = 1.0;
}
Decimal hoursPerWeek = a.pse__Scheduled_Hours__c / numWeeks.round(System.RoundingMode.HALF_UP);
System.debug('Assignment updated with '+numWeeks+' weeks of time and '+hoursPerWeek+' hours per week. Threshold is '+threshold+'.');
if( hoursPerWeek <= threshold ) {
a.pse__Exclude_from_Planners__c = true;
} else if (a.pse__Exclude_from_Planners__c == true) {
a.pse__Exclude_from_Planners__c = false;
}
}//Rasha
}
Thank you for your time and effore to help here even if I don't get to accomplish my goal of updating the code, I'll certainly select your answer as correct.
how does pse__Assignment__c relate to pse__Proj__c?
You need to get the pse__Proj__c.RecordType and check if that is equal to Schema.SObjectType.pse__Proj__c.getRecordTypeInfosByDeveloperName().get('AEP').getRecordTypeId()
If you dont know how to do this please show from which field does pse__Assignment__c relate to pse__Proj__c