The first thing you should look at here is bulkifying your trigger so that it doesn't need to perform a SOQL call for each Job__c in Trigger.new. See Best Practice: Bulkify Your Code
Part of this will be minimising the number of SOQL calls you make to get the Question Set Id for each job.
I'm assuming that you want to lookup a Question_Set__c by
Name based on the Record Type of the Job__c
record?
One thing that might make this much easier is to add the Job RecordTypeId as field on the Question_Set__c. Then you wouldn't need to do the lookup via the Question Set Name. Below I've assumed that such a field exists as JobRecordTypeId__c
. If you don't want to go down that path you will need to add a mapping step to translate between the Job Record Type and the Question Set Name.
Example bulkified trigger:
trigger UpdateQuestionSet on Job__c (before insert, before update) {
Set<Id> jobRecordTypeIds = new Set<Id>();
for (Job__c job: Trigger.new) {
jobRecordTypeIds.add(job.RecordTypeId);
}
if(jobRecordTypeIds.size() > 0) {
Question_Set__c[] applicationQuestions =
[SELECT Id, JobRecordTypeId__c FROM Question_Set__c
WHERE JobRecordTypeId__c in :jobRecordTypeIds];
// Build up a map here to easily go from the job Record Type to the Question Set Id
Map<Id, Id> mapFromRecordTypeIdToQuestionSetId = new Map<Id, Id>();
for (Question_Set__c questionSet : applicationQuestions) {
mapFromRecordTypeIdToQuestionSetId.put(questionSet.JobRecordTypeId__c, questionSet.Id);
}
for (Job__c job: Trigger.new) {
// TODO: Should check that the map actually contains the Job Id key first.
Id questionSetId = mapFromRecordTypeIdToQuestionSetId.get(job.Id);
job.Question_Set__c = questionSetId;
}
}
}