触发更新与其关联的基于联系人的记录

时间:2014-10-13 05:47:02

标签: triggers apex

我创建了一个触发器,它将根据ETCObject记录名称更新Contact上的Resume_Souce__c字段。

触发器似乎正在工作,但由于某种原因,不会根据“名称”字段中的值更新Resume_Source__c字段。它只是用'其他'更新它。即使ETCObject名称包含' JobsDB'。

以下是代码:

trigger DerekUpdateResumeSource on AVTRRT__ETCObject__c (after insert, after update) {

    Map<Id, AVTRRT__ETCObject__c> ETCmap = new Map<Id,AVTRRT__ETCObject__c>();
    for(AVTRRT__ETCObject__c a:trigger.new)
    {
        ETCmap.put(a.AVTRRT__Candidate__c, a);
    }
    List<Contact> candidate = [Select Id, AVTRRT__Source__c from Contact WHERE ID IN:ETCmap.keyset() AND RecordtypeID = '012A0000000v0La'];
    List<Contact> ContactsToUpdate = new List<Contact>();
    for(Contact c:candidate)
    {
       If(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('jobsDB'))
       {
           c.AVTRRT__Source__c = 'JobsDB';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('Clyde Marine Recruitment')){
           c.AVTRRT__Source__c = 'Clyde Marine Recruitment';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('Corporate Event')){
           c.AVTRRT__Source__c = 'Corporate Event';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('e Financial Careers')){
           c.AVTRRT__Source__c = 'e Financial Careers';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('Head Hunt')){
           c.AVTRRT__Source__c = 'Head Hunt';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('Indeed')){
           c.AVTRRT__Source__c = 'Indeed';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('Jobstreet')){
           c.AVTRRT__Source__c = 'Jobstreet';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('Linked In')){
           c.AVTRRT__Source__c = 'Linked In';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('Linkedin Advert')){
           c.AVTRRT__Source__c = 'Linkedin Advert';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('LinkedIn Recruiter')){
           c.AVTRRT__Source__c = 'LinkedIn Recruiter';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('Oil&Gas JobSearch')){
           c.AVTRRT__Source__c = 'Oil&Gas JobSearch';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('OilCareers')){
           c.AVTRRT__Source__c = 'OilCareers';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('Reed')){
           c.AVTRRT__Source__c = 'Reed';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('Referrals')){
           c.AVTRRT__Source__c = 'Referrals';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('S1 Jobs')){
           c.AVTRRT__Source__c = 'S1 Jobs';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('Straits Times')){
           c.AVTRRT__Source__c = 'Straits Times';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('Trade Winds')){
           c.AVTRRT__Source__c = 'Trade Winds';
           ContactsToUpdate.add(c);
       } else if(c.AVTRRT__Source__c == '' && ETCmap.get(c.Id).AVTRRT__Name__c.contains('UK Job Centre')){
           c.AVTRRT__Source__c = 'UK Job Centre';
           ContactsToUpdate.add(c);
       } else {
           c.AVTRRT__Source__c = 'Other';
           ContactsToUpdate.add(c);
       }
   }
update ContactsToUpdate;
}

1 个答案:

答案 0 :(得分:0)

由于某些原因,它无法识别&#39;&#39;&#39;关于if标准。更换后,它将使其按预期工作。

否则如果(c.AVTRRT__Source__c ==&#39;&#39;

否则if(c.AVTRRT__Source__c == null