在 Application__c 上触发 App_Trigger(插入后、删除后、取消删除后、更新后){ Set canId = new Set(); 设置 jobId = new Set();
if(Trigger.isInsert || Trigger.isUndelete || Trigger.isUpdate){
for(Application__c app : Trigger.new){
if(app.Candidate_Master__c != null){
canId.add(app.Candidate_Master__c);
}
if(app.Job_Position_Master__c != null){
jobId.add(app.Job_Position_Master__c);
}
}
}
if(Trigger.isDelete || Trigger.isUpdate){
for(Application__c app : Trigger.old){
if(app.Candidate_Master__c != null){
canId.add(app.Candidate_Master__c);
}
if(app.Job_Position_Master__c != null){
jobId.add(app.Job_Position_Master__c);
}
}
}
//Here we have to apply many to many relationship between candidate and job position
//so here we have to apply two look up relationships
// one is between Application and Candidate
// and second is between Application and job position
// and theni have to store job name related to particular application in the description field .
// and then store the job description in job summary
List<Job_Positions__c> jobList = [Select Id,Name,Job_Description__c,(Select id from Applications__r) from Job_Positions__c where Id = : jobId];
for(Job_Positions__c job : jobList){
// job.Job_Description__c = job.Applications__r.name+'-'+job.Name;
List<Candidate__c> canList = [Select Id,Name,No_of_application__c,(Select id from Applications__r) from Candidate__c where Id = : canId];
for(Candidate__c can : canList){
can.No_of_application__c = can.Applications__r.size();
}
}
if(canList != null){
update canList;
}
}
我的要求是在两个父对象(即 Candidate 和 Job Position )之间建立多对多关系。我有一个名为 Application 的联结对象,其中我有两个主视图字段,例如 Candidate_Master 和 Job_Position_Master 。我的要求是我想通过职位对象的 job_name 和 Job_Description 字段更新候选人对象上的职位摘要字段。所以我如何在这些对象之间建立多对多关系