• jonpilarski1.3914448382645588E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 11
    Replies
Hello.
Our org wants to implement state and country picklists. After I run the org scan I am presented with a report citing several reference points to said state and country. However, most of these references are on classes/reports that are managed and I do not have access to. Has anyone else implemented picklists? Do I just ignore these managed reports/classes/triggers?

Thanks in advance

Jon
Hi All,

I have added several new custom fields and validations to one of our existing custom objects. Now it is time to deploy to production. In my change set can I simply deploy the object or do I need to create change set comprised of every change (field and validations added). And, if I do just deploy the object is production data preserved?

Thanks as always,,
Jon
Hi Everyone

I have a simple before update trigger below. I am trying to catch any error and log to a custom table. The below will cause Duplicate error in UI but nothing is inserted into custome object USD_Error_Log__c.. Its like trigger does not fall into either DMLException or Exception catch blocks. Any and all help is appreciated.

Thanks

Jon

trigger USD_Contact on Contact(before update){

Set<USD_Error_Log__c> student = new Set<USD_Error_Log__c>(); 

for (Contact c: Trigger.new) {
    // delete [select id from USD_Error_Log__c];    
    
try{
  
     c.TargetX_SRMb__BannerID__c = '008372883';   // this will cause Duplicate value on record error      
     
} catch (DMLException e) {

  string error = e.getMessage();
  student.add(new USD_Error_Log__c(Banner_ID__c = c.TargetX_SRMb__BannerID__c,Error_Message__c = error ));
  
  if(!student.isEmpty()){   
   List<USD_Error_Log__c> toInsert = new List<USD_Error_Log__c>();
   try{
      toInsert.addAll(student);
      insert toInsert;     
   }catch(Exception se){
   }                             
  } 

} catch(Exception e) {
    
  string error = e.getMessage();
  student.add(new USD_Error_Log__c(Banner_ID__c = c.TargetX_SRMb__BannerID__c,Error_Message__c = error ));
  
  if(!student.isEmpty()){   
   List<USD_Error_Log__c> toInsert = new List<USD_Error_Log__c>();
   try{
      toInsert.addAll(student);
      insert toInsert;     
   }catch(Exception se){
   }                             
  } 
  
    
}

}//end loop



}
Hello. I have 3 custom objects, WorkRequest, Project and ProjectRequirements. ProjectRequirements is child to Project and Project can be associated to a WorkRequest. In single query I can query data easily as such:

 requirementList = [SELECT  id, 
                            ResourceAssigned__c,
                            Project__r.Work_Request__r.Work_Request_Status__c, 
                            Status__c ,  
                            Project__r.Name, 
                            Project__r.Project_Status__c, 
                            Project__r.Work_Request__r.Name,
                            Project__r.Work_Request__r.Short_Description__c,  
                            Project__r.Work_Request__r.Problem_Description__c,
                            Comments__c,
                            Name,
                            AddRequirementDetails__c
                      FROM USD_ProjectRequirements__c
                     WHERE Project__r.Work_Request__r.Name  != null
                       AND (ResourceAssigned__c IN :idList];    

However, what I also want to do is query in single query WorkRequests assigned to a rresource which have not been related to a Project. Anywat to do this in APEX?  Basically, the equivalent of SQL UNION operator.

Thanks in advance,

Jon
Hi!
I would like to create a Master-Detail relationship on two custom objects. The Master object is already a Detail object to another unrelated object. Is this possible? When I attempt I do not see the the desired Master object name in Related To dropdown list. I do not see ANY objects in this list that are not already defined as a detail object in master-detal relationship.

Thanks

Jon
Hi

On my commandButton action I call custom controller method. I have all code in method commented (except return statement). And still get Formula Expression is required on the action attributes error whe I submit. See alot of post on this but none helping..

Here is VF page
<apex:page controller="pickListScholarshipController" >


 <apex:form >
    <apex:pageBlock title="Schoalrship Application Assignment " id="out">
        <apex:pageBlockButtons >
            <apex:commandButton value="Assign Readers" action="{!insertScoringRecords}" rerender="out" status="actStatusId"/>
             <apex:commandButton value="Email Readers" action="{!submit}" rerender="out" status="actStatusId"/>
            <apex:actionStatus id="actStatusId">
                <apex:facet name="start">
                    <img src="/img/loading.gif" />
                </apex:facet>
            </apex:actionStatus>
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="Select Scholarship then Save button" collapsible="false">
            <apex:selectList value="{!selectedScholarship}" multiselect="false" size="1">
           <apex:selectOption itemValue="{!selectedScholarship}" itemLabel="{!selectedScholarship}"  />
                <apex:selectOption itemValue="Alumni Endowed Scholarship" itemLabel="Alumni Endowed Scholarship"/>
                <apex:selectOption itemValue="Danny Burkett Memorial Scholarship" itemLabel="Danny Burkett Memorial Scholarship"/>
                <apex:selectOption itemValue="Kyle O'Connell Memorial Scholarship" itemLabel="Kyle O'Connell Memorial Scholarship"/>
                <apex:selectOption itemValue="Senior Class Legacy Scholarship" itemLabel="Senior Class Legacy Scholarship"/>
                <apex:selectOption itemValue="Kyle O'Connell Memorial Scholarship" itemLabel="Kyle O'Connell Memorial Scholarship"/>
                <apex:selectOption itemValue="Terry Whitcomb Scholarship" itemLabel="Terry Whitcomb Scholarship"/>
                <apex:selectOption itemValue="Beckman Program Application" itemLabel="Beckman Program Application"/>
                <apex:selectOption itemValue="SURE Scholarship" itemLabel="SURE Scholarship"/>
                <apex:selectOption itemValue="PURE Scholarship" itemLabel="PURE Scholarship"/>   
            </apex:selectList>
             
            <apex:outputText value="{!selectedScholarship}" label="You have selected:"/>
        </apex:pageBlockSection>
         
      
    </apex:pageblock>
  </apex:form>
  
  
</apex:page>

And controller:

public class pickListScholarshipController {

 public String selectedScholarship;


    public pickListScholarshipController (){
    }
 
    public PageReference save(){
        return null;
    }
   
   
    public PageReference submit() {
              
        return null;
    }
    
 
 
   public String getSelectedScholarship() {
        return selectedScholarship;
    }

    public void setSelectedScholarship(String s) {
        selectedScholarship = s;
    }
    
        
   
   
   public String insertScoringRecords() {
   
/*
   
   USD_Scholarship_Scoring__c[] scoringRecs;
   USD_Roles__c[] readers;

   
   
   Date today = Date.today();
   Integer year = today.year();
   String yearToQuery = year+'-'+year+1;
   
   Integer len, i;
   ID contact;

   
   List<USD_Scholarship_Scoring__c> scholarshipExists = new List<USD_Scholarship_Scoring__c>([SELECT ID, SUID__c FROM USD_Scholarship_Scoring__c ]);
   Set<Id> setIds = new Set<Id>();
   
   for (USD_Scholarship_Scoring__c obj:scholarshipExists){
      setIds.add(obj.SUID__c);   
   }
   
   List<USD_Scholarship__c> scholarshipList = new List<USD_Scholarship__c>();
   
   scholarshipList = ([SELECT ID 
                         FROM USD_Scholarship__c 
                         WHERE Submit_Term_Year__c = :yearToQuery 
                           AND name = :selectedScholarship
                           AND SUID__c  NOT IN :setIds] );

   readers= ([SELECT ID, Contact__c 
                FROM USD_Roles__c 
               WHERE Scholarship_Name__c = :selectedScholarship 
                 AND Start_Date__c <= TODAY 
                 AND End_Date__c > TODAY] );
                 
   len = readers.size();                                    
                           
   for(USD_Scholarship__c s : scholarshipList) {
   
      if(i>len){
         i=0;
      }
      // assign application to next 3 readers 
      
      if ( len>0 ) {
    //  scoringRecs = new USD_Scholarship_Scoring__c[]{new USD_Scholarship_Scoring__c(Reader_Contact__c=readers[i++].Contact__c, ScholarshipSUID__c=s.ID),
                                    //                 new USD_Scholarship_Scoring__c(Reader_Contact__c=readers[i++].Contact__c, ScholarshipSUID__c=s.ID),
                                    //                 new USD_Scholarship_Scoring__c(Reader_Contact__c=readers[i++].Contact__c, ScholarshipSUID__c=s.ID) };
      }  
     
   }
   
    if ( len>0 ) {
    //  insert scoringRecs;
    }


*/ 
   return 'success';
   }
   
   
}

Thanks for everyone's help,

Jon
 
Hi. 

I have a custom object TargetX_SRMb__Application__c which has a master-detail relation to Contact. Contact, of course, has lookup relation to Account. In a trigger on TargetX_SRMb__Application__c I need to get Name from Account. I though I could traverse up using dot notation but always returns null. For example I tried:

 for(TargetX_SRMb__Application__c a :  trigger.new) {
  System.debug('aaccountID:'+a.TargetX_SRMb__Contact__r.Account); 
  System.debug('aaccountID:'+a.TargetX_SRMb__Contact__r.AccountId); 
  System.debug('aaccountID:'+a.TargetX_SRMb__Contact__r.Account.Id); 
}
All return null. Any and all help appreciated.

Jon

 
Hi.

I have a custom object (TargetX_SRMb__Application__c) It has a relationship to Contact defined in WSDL by:

  <complexType name="TargetX_SRMb__Application__c">
                <complexContent>
                    <extension base="ens:sObject">

...
                       <element name="TargetX_SRMb__Contact__c" nillable="true" minOccurs="0" type="tns:ID"/>
                        <element name="TargetX_SRMb__Contact__r" nillable="true" minOccurs="0" type="ens:Contact"/>

However, when I run SOQL test as:

 Contact contact = [SELECT  c.Id, c.lastName, (Select CreatedDate  FROM TargetX_SRMb__Contact__r) FROM Contact c]

I get error:

Error: Compile Error: Didn't understand relationship 'TargetX_SRMb__Contact__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name

I also tries adding a "s" as follows: Same error.

 Contact contact = [SELECT  c.Id, c.lastName, (Select CreatedDate  FROM TargetX_SRMb__Contacts__r) FROM Contact c]

 Is this not the correct syntax to query child records from a custom object?

Thanks in advance,

Jon
Hi !

I have a simple test method which creates an Account and a Contact. A trigger on Contact which sets a field based on the Account's BillingState. Problem is when the trigger fires the Billing state evelautes to null. I cannot understand as to why. Here is test method setting these up.

test method:

static testMethod void validate() {
     
        Test.startTest();
         
        account[] accounts = new account[]{
        new account(name='highschool',BillingState='CA',BillingPostalCode='92100') };
 
        insert accounts;

        contact[] contacts = new contact[] {
        new contact(LastName='Sand10',TargetX_SRMb__Student_Type__c='New Freshman',accountId=accounts[0].id)};
 
        insert contacts;
        Test.stopTest();

        List<contact> con = [select id, LastName, FirstName,TargetX_SRMb__Student_Type__c,TargetX_SRMb__College__c,account.BillingState, account.billingPostalCode,Territory_Assignments__c from Contact];
         
        for(Contact e: con) {
    
        System.debug('Last name.......... '+e.lastname+'  State '+e.account.BillingState);   // this actually DOES return BillingState
}

In trigger logic:

...
if(String.isNotBlank(c.TargetX_SRMb__Student_Type__c) ){ 
     system.debug('lastname in trigger: '+c.lastname+' state is '+c.account.billingState);    // this shows null for BillingState
        //look at territory state
        if(String.isNotBlank(c.Account.BillingState)){
              system.debug('not blank');                                    // never get here
.....    
Thanks,
Jon
Hi !

I have a simple test method which creates an Account and a Contact. A trigger on Contact which sets a field based on the Account's BillingState. Problem is when the trigger fires the Billing state evelautes to null. I cannot understand as to why. Here is test method setting these up. When I query contact object in test method I can see the BillingState, however.

test method:

static testMethod void validate() {
    
        Test.startTest();
        
        account[] accounts = new account[]{
        new account(name='highschool',BillingState='CA',BillingPostalCode='92100') };

        insert accounts;

        contact[] contacts = new contact[] {
        new contact(LastName='Sand10',TargetX_SRMb__Student_Type__c='New Freshman',accountId=accounts[0].id)};

        insert contacts;
        Test.stopTest();

        List<contact> con = [select id, LastName, FirstName,TargetX_SRMb__Student_Type__c,TargetX_SRMb__College__c,account.BillingState, account.billingPostalCode,Territory_Assignments__c from Contact];
        
        for(Contact e: con) {
   
        System.debug('Last name.......... '+e.lastname+'  State '+e.account.BillingState);   // this actually DOES return BillingState
}

In Contact trigger logic:

...
if(String.isNotBlank(c.TargetX_SRMb__Student_Type__c) ){
     system.debug('lastname in trigger: '+c.lastname+' state is '+c.account.billingState);    // this shows null for BillingState
        //look at territory state
        if(String.isNotBlank(c.Account.BillingState)){
              system.debug('not blank');                                    // never get here
.....   
Thanks,
Jon
Hi,

I have executes test class successfully in sandbox several times. After I do code coverage shows 95%. When I attempt to deploy to production I get error:

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

I see many threads on this and have tried many things...At first I put all logic in class and merely called class from trigger. Now I moved all logic into trigger. Still test fine in sandbox but not in production.
Here is trigger and test class.

Thanks,

Jon

@isTest
private class USDTestClass {
       static testMethod void validate() {

   
  
        contact[] contacts = new contact[] {
        new contact(LastName='Sand1',FirstName='Debbie'),
        new contact(LastName='Sand2',FirstName='Carla'),
        new contact(LastName='Sand3',FirstName='Bob'),
        new contact(LastName='Sand4',FirstName='Jon'),
        new contact(LastName='Sand5',FirstName='Bill')
        };
      
        insert contacts;


    USD_Eform__c[] eforms = new USD_Eform__c[] {
        new USD_Eform__c(Contact__c=contacts[0].id,Eform_Type__c='Freshman Questionnaire',name='no name'),
        new USD_Eform__c(Contact__c=contacts[1].id,Eform_Type__c='Freshman Questionnaire',Majr_area_of_interest1__c='xxxEngineering', Majr_area_of_interest2__c='Soccer',Pre_Professional_prog__c='Pre-Med', name='one'),
        new USD_Eform__c(Contact__c=contacts[2].id,Eform_Type__c='Freshman Questionnaire',Majr_area_of_interest1__c='Junk Science',Majr_area_of_interest2__c='abcEngineering',Pre_Professional_prog__c='Pre-Dental', name='two'),
        new USD_Eform__c(Contact__c=contacts[3].id,Eform_Type__c='Freshman Questionnaire',Majr_area_of_interest1__c='Junk Science',Majr_area_of_interest2__c='fff jjjj',Pre_Professional_prog__c='Pre-Health',name='three'),
        new USD_Eform__c(Contact__c=contacts[4].id,Eform_Type__c='Freshman Questionnaire',Majr_area_of_interest1__c='abc Engineering Mechanical',Majr_area_of_interest2__c='aaa Engineering',Pre_Professional_prog__c='Pre-Health', name='four honor')
        };
      
        insert  eforms;
      
         
       List<USD_Eform__c> eFormList = [select id, Eform_Type__c, name,  Majr_area_of_interest1__c, Majr_area_of_interest2__c, Pre_Professional_prog__c,  Assignee__c
                                       from USD_Eform__c];
         

      for(USD_Eform__c e: eFormList) {
    
      if(e.name == 'one'){
         System.assertEquals('Rick Olson', e.Assignee__c);
      }
      if(e.name == 'two'){
         System.assertEquals('Rick Olson', e.Assignee__c);
      }
      if(e.name == 'three'){
         System.assertEquals('Casandra Gomez', e.Assignee__c);
      }
      if(e.name == 'four'){
         System.assertEquals('Jim Gump', e.Assignee__c);
      }        
        
      System.debug('Final>>'+e.Assignee__c);  
      }

      
 


//      System.assertEquals(90, b.Price__c);
    }
}

trigger USD_Eform_BI on USD_Eform__c (before insert) {


// USD_Eform__c[] eform = Trigger.new;


   for (USD_Eform__c e: Trigger.new) {
     //USD_Eform_BI.setAssignee(eform);
   
     Integer honorsResult = 0, areaOfInterestResult1 = 0, areaOfInterestResult2= 0,preHealthResult= 0 ;
     string nameValue ,areaOfInterst1Value,areaOfInterst2Value,preHealthValue ;

if(e.Eform_Type__c.equals('Freshman Questionnaire')) {

   nameValue = e.name.toUpperCase();
   
   try{
      areaOfInterst1Value = e.Majr_area_of_interest1__c.toUpperCase();
   }catch(NullPointerException ne){
 
   }

   try{
      areaOfInterst2Value = e.Majr_area_of_interest2__c.toUpperCase();
   }catch(NullPointerException ne){

   }
   try{
      preHealthValue = e.Pre_Professional_prog__c.toUpperCase();
   }catch(NullPointerException ne){

   }
 
   try{
      honorsResult = nameValue.indexOf('HONOR',0);
   }catch(NullPointerException ne){
      honorsResult = -1;
  }

   try{
      areaOfInterestResult1 = areaOfInterst1Value.indexOf('ENGINEERING');

   }catch(NullPointerException ne){
      areaOfInterestResult1  = -1;
   }
 
   try{
      areaOfInterestResult2 = areaOfInterst2Value.indexOf('ENGINEERING');

   }catch(NullPointerException ne){
      areaOfInterestResult2  = -1;
   }

   try{
      preHealthResult = preHealthValue.indexOf('PRE-HEALTH',0);  
   }catch(NullPointerException ne){
      preHealthResult  = -1;
   }

   if(honorsResult>=0) {
      //Honors
      e.Assignee__c = 'Jim Gump';    
   }else
    if(areaOfInterestResult1 >=0 || areaOfInterestResult2 >=0) {
      //Engineering
      e.Assignee__c = 'Rick Olson';   
   }else
    if(preHealthResult >=0) {
     //Pre-Health
      e.Assignee__c = 'Casandra Gomez';  
   }else {
      e.Assignee__c = null;
   }
 
 
   honorsResult = -1;
   areaOfInterestResult1 = -1;
   areaOfInterestResult2 = -1;
   preHealthResult = -1;

  }


   }   

 
}
Hi,

I am trying to debug an Apex trigger in my sandbox. I have serveral System.debug statements which I see fime using Developer Console but I need to see them in debug log as I am running an integration API. I have modified the debug log filters (see below) but never see the debug.

Here I have changed filter on APEX_CODE to FInest and Debug but no System.debug statements are presented.


14.0 APEX_CODE,FINEST
12:33:57.054 (54988000)|ENTERING_MANAGED_PKG|TargetX_SRMb
12:33:57.055 (55190000)|HEAP_ALLOCATE|[71]|Bytes:3
12:33:57.055 (55220000)|HEAP_ALLOCATE|[76]|Bytes:152
12:33:57.055 (55241000)|HEAP_ALLOCATE|[272]|Bytes:408
12:33:57.055 (55266000)|HEAP_ALLOCATE|[285]|Bytes:408
12:33:57.055 (55290000)|HEAP_ALLOCATE|[379]|Bytes:48
12:33:57.055 (55332000)|HEAP_ALLOCATE|[131]|Bytes:6
12:33:57.055 (55406000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
12:33:57.055 (55418000)|VARIABLE_SCOPE_BEGIN|[1]|this|TargetX_SRMb.setFeeWaiverInfo|true|false
12:33:57.055 (55462000)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x3497f74
12:33:57.055 (55685000)|HEAP_ALLOCATE|[50]|Bytes:5
12:33:57.055 (55714000)|HEAP_ALLOCATE|[56]|Bytes:5
12:33:57.055 (55725000)|HEAP_ALLOCATE|[63]|Bytes:7
12:33:57.059 (59123000)|CODE_UNIT_STARTED|[EXTERNAL]|01qf00000000DRe|studentStage on Application trigger event BeforeUpdate for [a00f0000004fGKb, a00f00000051SDX]
12:33:57.059 (59141000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
12:33:57.059 (59147000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
12:33:57.059 (59179000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:37
12:33:57.059 (59190000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
12:33:57.059 (59200000)|VARIABLE_SCOPE_BEGIN|[1]|this|studentStage|true|false
12:33:57.059 (59219000)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x628e4d06
12:33:57.059 (59233000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
12:33:57.059 (59241000)|VARIABLE_SCOPE_BEGIN|[1]|this|studentStage|true|false
12:33:57.059 (59252000)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x628e4d06
12:33:57.059 (59259000)|STATEMENT_EXECUTE|[1]
12:33:57.059 (59269000)|STATEMENT_EXECUTE|[4]
12:33:57.059 (59302000)|CODE_UNIT_FINISHED|studentStage on Application trigger event BeforeUpdate for [a00f0000004fGKb, a00f00000051SDX]
12:33:57.098 (98416000)|ENTERING_MANAGED_PKG|TargetX_SRMb
12:33:57.098 (98490000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
12:33:57.098 (98502000)|VARIABLE_SCOPE_BEGIN|[1]|this|TargetX_SRMb.EnrollmentDepositTrigger|true|false
12:33:57.098 (98545000)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x4f071cdc
12:33:57.101 (101745000)|ENTERING_MANAGED_PKG|TargetX_SRMb
12:33:57.101 (101808000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
12:33:57.101 (101818000)|VARIABLE_SCOPE_BEGIN|[1]|this|TargetX_SRMb.ApplicationInsertTrigger|true|false


14.0 APEX_CODE,DEBUG
12:35:30.068 (68106000)|ENTERING_MANAGED_PKG|TargetX_SRMb
12:35:30.070 (70783000)|CODE_UNIT_STARTED|[EXTERNAL]|01qf00000000DRe|studentStage on Application trigger event BeforeUpdate for [a00f0000004fGKb, a00f00000051SDX]
12:35:30.070 (70883000)|CODE_UNIT_FINISHED|studentStage on Application trigger event BeforeUpdate for [a00f0000004fGKb, a00f00000051SDX]
12:35:30.094 (94490000)|ENTERING_MANAGED_PKG|TargetX_SRMb
12:35:30.097 (97310000)|ENTERING_MANAGED_PKG|TargetX_SRMb

Thanks

Jon
Hello. Very new to APEX so be kind :)

I have a rather simple trigger which evaluates Applications (children of Contact) Depending on some specific logic I want to update the Contact. I will have multuple Applciations for the same Contact so I put them in a Set. The last one added should be the only one persisted as I am adding to a Set. However, I get System.ListException when here:

List<Contact> toUpdate = new List<Contact>();
        toUpdate.addAll(student);              // add SET to LIST
     
        update toUpdate;                          //this operation throws: System.ListException: Duplicate id in list

Here is whole trigger.

Thanks,
Jon

trigger studentStage on TargetX_SRMb__Application__c (before insert, before update) {

Set<Contact> student = new Set<Contact>();

for (TargetX_SRMb__Application__c app : trigger.new) {

  if ( app.TargetX_SRMb__Level__c != null && app.TargetX_SRMb__Level__c.equals('Undergraduate')){
     try{
   
      if (      String.IsBlank(app.TargetX_SRMb__Application_Decision__c) ||
                app.TargetX_SRMb__Application_Decision__c.length() == 0 ||
                app.TargetX_SRMb__Application_Decision__c.equals('Cancelled Implied') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Waitlist') ||              
                app.TargetX_SRMb__Application_Decision__c.equals('Cancelled before offer') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Denied') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Conditional status') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Accepted to ELA program') ) {
                         
         student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Applicant' ));
  
      }else if (app.TargetX_SRMb__Application_Decision__c.equals('Accepted') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Cancelled after order') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Deferral') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Accepted to EOP program') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Waitlist admit'))  {
         student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Admitted' ));
    
      }else if (app.TargetX_SRMb__Application_Decision__c.equals('Confirmed') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Confirmed 2') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Cancelled after confirmed'))  {
         student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Confirmed' )); 
           
      }else if (app.TargetX_SRMb__Contact__r.TargetX_SRMb__Anticipated_Start_Term__c == null) {
    
   
      }
    
      }catch(NullpointerException ne){
         student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Applicant' ));
       //   studentList.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Applicant' ));
      }catch(ListException le) {
      }
   

    }else if (app.TargetX_SRMb__Level__c.equals('Graduate') || app.TargetX_SRMb__Level__c.equals('Doctoral') ){

System.debug('student is graduate' + app.TargetX_SRMb__Level__c+ ' '+ app.TargetX_SRMb__Application_Decision__c);


 
     try{
   

   
       if (     String.IsBlank(app.TargetX_SRMb__Application_Decision__c) ||
                app.TargetX_SRMb__Application_Decision__c.length() == 0 ||
                app.TargetX_SRMb__Application_Decision__c.equals('Cancelled Implied') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Denied') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Conditional status') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Accepted ELA program')
                 ) {


System.debug('adding to list '+app.TargetX_SRMb__Application_Decision__c);
   
         student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Applicant' )); 

      }else if (app.TargetX_SRMb__Application_Decision__c.equals('Accepted') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Cancelled after offer') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Conditional status') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Deferral') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Accepted EOP offer') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Waitlist admit') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Accepted EOP program')  )  {
         student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Admitted' ));
      
        System.debug('adding to list '+app.TargetX_SRMb__Application_Decision__c);
     }else if (app.TargetX_SRMb__Application_Decision__c.equals('Confirmed') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Confirmed 2') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Cancelled after confirmed'))  {
         student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Confirmed' ));
  
      }else if (app.TargetX_SRMb__Contact__r.TargetX_SRMb__Anticipated_Start_Term__c == null){
      //   student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Inquiry' ));
      }  
   
 
   
     }catch(NullpointerException ne){
        student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Applicant' ));

     }catch(ListException le) {
     
     }
  
   
     }


    
    }// end for loop
  

    if(!student.isEmpty()){
  
    try{

    
        List<Contact> toUpdate = new List<Contact>();
        toUpdate.addAll(student);              // add set to list
          System.debug('update contacts');
        update toUpdate;                          //this operation throws: System.ListException: Duplicate id in list
          System.debug('after update');

    }catch(ListException le) {
      System.debug('error : '+le);
    }
    }




}
Hi.

I have a custom object (TargetX_SRMb__Application__c) It has a relationship to Contact defined in WSDL by:

  <complexType name="TargetX_SRMb__Application__c">
                <complexContent>
                    <extension base="ens:sObject">

...
                       <element name="TargetX_SRMb__Contact__c" nillable="true" minOccurs="0" type="tns:ID"/>
                        <element name="TargetX_SRMb__Contact__r" nillable="true" minOccurs="0" type="ens:Contact"/>

However, when I run SOQL test as:

 Contact contact = [SELECT  c.Id, c.lastName, (Select CreatedDate  FROM TargetX_SRMb__Contact__r) FROM Contact c]

I get error:

Error: Compile Error: Didn't understand relationship 'TargetX_SRMb__Contact__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name

I also tries adding a "s" as follows: Same error.

 Contact contact = [SELECT  c.Id, c.lastName, (Select CreatedDate  FROM TargetX_SRMb__Contacts__r) FROM Contact c]

 Is this not the correct syntax to query child records from a custom object?

Thanks in advance,

Jon
Hello. I have 3 custom objects, WorkRequest, Project and ProjectRequirements. ProjectRequirements is child to Project and Project can be associated to a WorkRequest. In single query I can query data easily as such:

 requirementList = [SELECT  id, 
                            ResourceAssigned__c,
                            Project__r.Work_Request__r.Work_Request_Status__c, 
                            Status__c ,  
                            Project__r.Name, 
                            Project__r.Project_Status__c, 
                            Project__r.Work_Request__r.Name,
                            Project__r.Work_Request__r.Short_Description__c,  
                            Project__r.Work_Request__r.Problem_Description__c,
                            Comments__c,
                            Name,
                            AddRequirementDetails__c
                      FROM USD_ProjectRequirements__c
                     WHERE Project__r.Work_Request__r.Name  != null
                       AND (ResourceAssigned__c IN :idList];    

However, what I also want to do is query in single query WorkRequests assigned to a rresource which have not been related to a Project. Anywat to do this in APEX?  Basically, the equivalent of SQL UNION operator.

Thanks in advance,

Jon
Hi!
I would like to create a Master-Detail relationship on two custom objects. The Master object is already a Detail object to another unrelated object. Is this possible? When I attempt I do not see the the desired Master object name in Related To dropdown list. I do not see ANY objects in this list that are not already defined as a detail object in master-detal relationship.

Thanks

Jon
Hi.

I have a custom object (TargetX_SRMb__Application__c) It has a relationship to Contact defined in WSDL by:

  <complexType name="TargetX_SRMb__Application__c">
                <complexContent>
                    <extension base="ens:sObject">

...
                       <element name="TargetX_SRMb__Contact__c" nillable="true" minOccurs="0" type="tns:ID"/>
                        <element name="TargetX_SRMb__Contact__r" nillable="true" minOccurs="0" type="ens:Contact"/>

However, when I run SOQL test as:

 Contact contact = [SELECT  c.Id, c.lastName, (Select CreatedDate  FROM TargetX_SRMb__Contact__r) FROM Contact c]

I get error:

Error: Compile Error: Didn't understand relationship 'TargetX_SRMb__Contact__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name

I also tries adding a "s" as follows: Same error.

 Contact contact = [SELECT  c.Id, c.lastName, (Select CreatedDate  FROM TargetX_SRMb__Contacts__r) FROM Contact c]

 Is this not the correct syntax to query child records from a custom object?

Thanks in advance,

Jon
Hi !

I have a simple test method which creates an Account and a Contact. A trigger on Contact which sets a field based on the Account's BillingState. Problem is when the trigger fires the Billing state evelautes to null. I cannot understand as to why. Here is test method setting these up.

test method:

static testMethod void validate() {
     
        Test.startTest();
         
        account[] accounts = new account[]{
        new account(name='highschool',BillingState='CA',BillingPostalCode='92100') };
 
        insert accounts;

        contact[] contacts = new contact[] {
        new contact(LastName='Sand10',TargetX_SRMb__Student_Type__c='New Freshman',accountId=accounts[0].id)};
 
        insert contacts;
        Test.stopTest();

        List<contact> con = [select id, LastName, FirstName,TargetX_SRMb__Student_Type__c,TargetX_SRMb__College__c,account.BillingState, account.billingPostalCode,Territory_Assignments__c from Contact];
         
        for(Contact e: con) {
    
        System.debug('Last name.......... '+e.lastname+'  State '+e.account.BillingState);   // this actually DOES return BillingState
}

In trigger logic:

...
if(String.isNotBlank(c.TargetX_SRMb__Student_Type__c) ){ 
     system.debug('lastname in trigger: '+c.lastname+' state is '+c.account.billingState);    // this shows null for BillingState
        //look at territory state
        if(String.isNotBlank(c.Account.BillingState)){
              system.debug('not blank');                                    // never get here
.....    
Thanks,
Jon
Hi,

I have executes test class successfully in sandbox several times. After I do code coverage shows 95%. When I attempt to deploy to production I get error:

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

I see many threads on this and have tried many things...At first I put all logic in class and merely called class from trigger. Now I moved all logic into trigger. Still test fine in sandbox but not in production.
Here is trigger and test class.

Thanks,

Jon

@isTest
private class USDTestClass {
       static testMethod void validate() {

   
  
        contact[] contacts = new contact[] {
        new contact(LastName='Sand1',FirstName='Debbie'),
        new contact(LastName='Sand2',FirstName='Carla'),
        new contact(LastName='Sand3',FirstName='Bob'),
        new contact(LastName='Sand4',FirstName='Jon'),
        new contact(LastName='Sand5',FirstName='Bill')
        };
      
        insert contacts;


    USD_Eform__c[] eforms = new USD_Eform__c[] {
        new USD_Eform__c(Contact__c=contacts[0].id,Eform_Type__c='Freshman Questionnaire',name='no name'),
        new USD_Eform__c(Contact__c=contacts[1].id,Eform_Type__c='Freshman Questionnaire',Majr_area_of_interest1__c='xxxEngineering', Majr_area_of_interest2__c='Soccer',Pre_Professional_prog__c='Pre-Med', name='one'),
        new USD_Eform__c(Contact__c=contacts[2].id,Eform_Type__c='Freshman Questionnaire',Majr_area_of_interest1__c='Junk Science',Majr_area_of_interest2__c='abcEngineering',Pre_Professional_prog__c='Pre-Dental', name='two'),
        new USD_Eform__c(Contact__c=contacts[3].id,Eform_Type__c='Freshman Questionnaire',Majr_area_of_interest1__c='Junk Science',Majr_area_of_interest2__c='fff jjjj',Pre_Professional_prog__c='Pre-Health',name='three'),
        new USD_Eform__c(Contact__c=contacts[4].id,Eform_Type__c='Freshman Questionnaire',Majr_area_of_interest1__c='abc Engineering Mechanical',Majr_area_of_interest2__c='aaa Engineering',Pre_Professional_prog__c='Pre-Health', name='four honor')
        };
      
        insert  eforms;
      
         
       List<USD_Eform__c> eFormList = [select id, Eform_Type__c, name,  Majr_area_of_interest1__c, Majr_area_of_interest2__c, Pre_Professional_prog__c,  Assignee__c
                                       from USD_Eform__c];
         

      for(USD_Eform__c e: eFormList) {
    
      if(e.name == 'one'){
         System.assertEquals('Rick Olson', e.Assignee__c);
      }
      if(e.name == 'two'){
         System.assertEquals('Rick Olson', e.Assignee__c);
      }
      if(e.name == 'three'){
         System.assertEquals('Casandra Gomez', e.Assignee__c);
      }
      if(e.name == 'four'){
         System.assertEquals('Jim Gump', e.Assignee__c);
      }        
        
      System.debug('Final>>'+e.Assignee__c);  
      }

      
 


//      System.assertEquals(90, b.Price__c);
    }
}

trigger USD_Eform_BI on USD_Eform__c (before insert) {


// USD_Eform__c[] eform = Trigger.new;


   for (USD_Eform__c e: Trigger.new) {
     //USD_Eform_BI.setAssignee(eform);
   
     Integer honorsResult = 0, areaOfInterestResult1 = 0, areaOfInterestResult2= 0,preHealthResult= 0 ;
     string nameValue ,areaOfInterst1Value,areaOfInterst2Value,preHealthValue ;

if(e.Eform_Type__c.equals('Freshman Questionnaire')) {

   nameValue = e.name.toUpperCase();
   
   try{
      areaOfInterst1Value = e.Majr_area_of_interest1__c.toUpperCase();
   }catch(NullPointerException ne){
 
   }

   try{
      areaOfInterst2Value = e.Majr_area_of_interest2__c.toUpperCase();
   }catch(NullPointerException ne){

   }
   try{
      preHealthValue = e.Pre_Professional_prog__c.toUpperCase();
   }catch(NullPointerException ne){

   }
 
   try{
      honorsResult = nameValue.indexOf('HONOR',0);
   }catch(NullPointerException ne){
      honorsResult = -1;
  }

   try{
      areaOfInterestResult1 = areaOfInterst1Value.indexOf('ENGINEERING');

   }catch(NullPointerException ne){
      areaOfInterestResult1  = -1;
   }
 
   try{
      areaOfInterestResult2 = areaOfInterst2Value.indexOf('ENGINEERING');

   }catch(NullPointerException ne){
      areaOfInterestResult2  = -1;
   }

   try{
      preHealthResult = preHealthValue.indexOf('PRE-HEALTH',0);  
   }catch(NullPointerException ne){
      preHealthResult  = -1;
   }

   if(honorsResult>=0) {
      //Honors
      e.Assignee__c = 'Jim Gump';    
   }else
    if(areaOfInterestResult1 >=0 || areaOfInterestResult2 >=0) {
      //Engineering
      e.Assignee__c = 'Rick Olson';   
   }else
    if(preHealthResult >=0) {
     //Pre-Health
      e.Assignee__c = 'Casandra Gomez';  
   }else {
      e.Assignee__c = null;
   }
 
 
   honorsResult = -1;
   areaOfInterestResult1 = -1;
   areaOfInterestResult2 = -1;
   preHealthResult = -1;

  }


   }   

 
}
Hello. Very new to APEX so be kind :)

I have a rather simple trigger which evaluates Applications (children of Contact) Depending on some specific logic I want to update the Contact. I will have multuple Applciations for the same Contact so I put them in a Set. The last one added should be the only one persisted as I am adding to a Set. However, I get System.ListException when here:

List<Contact> toUpdate = new List<Contact>();
        toUpdate.addAll(student);              // add SET to LIST
     
        update toUpdate;                          //this operation throws: System.ListException: Duplicate id in list

Here is whole trigger.

Thanks,
Jon

trigger studentStage on TargetX_SRMb__Application__c (before insert, before update) {

Set<Contact> student = new Set<Contact>();

for (TargetX_SRMb__Application__c app : trigger.new) {

  if ( app.TargetX_SRMb__Level__c != null && app.TargetX_SRMb__Level__c.equals('Undergraduate')){
     try{
   
      if (      String.IsBlank(app.TargetX_SRMb__Application_Decision__c) ||
                app.TargetX_SRMb__Application_Decision__c.length() == 0 ||
                app.TargetX_SRMb__Application_Decision__c.equals('Cancelled Implied') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Waitlist') ||              
                app.TargetX_SRMb__Application_Decision__c.equals('Cancelled before offer') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Denied') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Conditional status') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Accepted to ELA program') ) {
                         
         student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Applicant' ));
  
      }else if (app.TargetX_SRMb__Application_Decision__c.equals('Accepted') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Cancelled after order') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Deferral') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Accepted to EOP program') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Waitlist admit'))  {
         student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Admitted' ));
    
      }else if (app.TargetX_SRMb__Application_Decision__c.equals('Confirmed') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Confirmed 2') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Cancelled after confirmed'))  {
         student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Confirmed' )); 
           
      }else if (app.TargetX_SRMb__Contact__r.TargetX_SRMb__Anticipated_Start_Term__c == null) {
    
   
      }
    
      }catch(NullpointerException ne){
         student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Applicant' ));
       //   studentList.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Applicant' ));
      }catch(ListException le) {
      }
   

    }else if (app.TargetX_SRMb__Level__c.equals('Graduate') || app.TargetX_SRMb__Level__c.equals('Doctoral') ){

System.debug('student is graduate' + app.TargetX_SRMb__Level__c+ ' '+ app.TargetX_SRMb__Application_Decision__c);


 
     try{
   

   
       if (     String.IsBlank(app.TargetX_SRMb__Application_Decision__c) ||
                app.TargetX_SRMb__Application_Decision__c.length() == 0 ||
                app.TargetX_SRMb__Application_Decision__c.equals('Cancelled Implied') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Denied') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Conditional status') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Accepted ELA program')
                 ) {


System.debug('adding to list '+app.TargetX_SRMb__Application_Decision__c);
   
         student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Applicant' )); 

      }else if (app.TargetX_SRMb__Application_Decision__c.equals('Accepted') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Cancelled after offer') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Conditional status') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Deferral') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Accepted EOP offer') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Waitlist admit') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Accepted EOP program')  )  {
         student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Admitted' ));
      
        System.debug('adding to list '+app.TargetX_SRMb__Application_Decision__c);
     }else if (app.TargetX_SRMb__Application_Decision__c.equals('Confirmed') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Confirmed 2') ||
                app.TargetX_SRMb__Application_Decision__c.equals('Cancelled after confirmed'))  {
         student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Confirmed' ));
  
      }else if (app.TargetX_SRMb__Contact__r.TargetX_SRMb__Anticipated_Start_Term__c == null){
      //   student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Inquiry' ));
      }  
   
 
   
     }catch(NullpointerException ne){
        student.add(new Contact(Id = app.TargetX_SRMb__Contact__c, TargetX_SRMb__Status__c = 'Applicant' ));

     }catch(ListException le) {
     
     }
  
   
     }


    
    }// end for loop
  

    if(!student.isEmpty()){
  
    try{

    
        List<Contact> toUpdate = new List<Contact>();
        toUpdate.addAll(student);              // add set to list
          System.debug('update contacts');
        update toUpdate;                          //this operation throws: System.ListException: Duplicate id in list
          System.debug('after update');

    }catch(ListException le) {
      System.debug('error : '+le);
    }
    }




}