• Edward East
  • NEWBIE
  • 40 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 5
    Replies
Hi there, currently struggling with this slight problem:

I have created a custom object called "List", with a child custom object nested within that called "Person Accounts" (the name field is set to be an auto number on that one). Other than the master-detail relationship it has to "List" it also has a master detail relationship to Accounts (with a filter to limit it to person accounts only), enabling me to add person accounts to specific lists.
I now want to create a custom button that should sit on the account view that enables me o bulk add several people to a list of my choosing. Is that possible? 
I am trying to write a trigger that will automatically mark a task called 'Lead - Intro' as complete when the Lead Status changes from Open to Contacted. I tried cobbling it together from various similiar things I've found on the forum, but there are big chunks missing and I've sort of hit a brick wall. This is how far I've come so far:

trigger updateTaskStatus on Lead (after update) {
 
try{   
        for(Lead myLead: Trigger.new){
            
            if((myLead.isconverted==false) && (myLead.Status == 'Contacted')) {
            
        List<Task> taskstatus = new List<Task>();
        
             for (Task t: taskstatus){
  if (t.Subject == 'Lead - Intro') && (t.Status == 'Open') {
    t.Status = 'Completed';
  }
            
                Update taskstatus;                             
                }
Hi all, 

I'm trying to create a trigger that will automatically change an opportunity stage once a certain task is completeted. The code is here:

trigger changeOpportunityStage on Task (before insert, after update) {

    Set<Id> oppIds = new Set<Id>();  
    for(Task t:trigger.new){
        String wId = t.WhatId;
              if(wId!=null && wId.startsWith('006') && t.Status == 'Completed' && t.Subject.Contains('Account - Initial Report')){
                oppIds.add(t.WhatId);
  }
    }//for 
   List<Opportunity> opps = [select Id, StageName from opportunity where id in: oppIds AND ( RecordType.name = 'Influencer' or RecordType.name = 'Creative')];    
        for(Opportunity opp : opps){
          if(opp.StageName == 'Closed Won')
          opp.StageName = 'Report Sent';
}
    try{
        update opps;
    }catch(DMLException e){
        system.debug('Opportunities were not all properly updated.  Error: '+e);
    }   
}//trigger

It works perfectly in sandbox and I've been trying to deploy it to production. However, my apex text class has been flagging up this error and I don't know how to resolve this issue:

testChangeOpportunityStage.testChangeOpportunityStatusTrigger(), Details: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Name ID: id value of incorrect type: 00624000008UJnkAAG: [WhoId] Class.testChangeOpportunityStage.testChangeOpportunityStatusTrigger: line 14, column 1

Here is my test class:

@isTest
private class testChangeOpportunityStage {
    static testMethod void testChangeOpportunityStatusTrigger(){
      String desiredNewOpportunityStage='Report Sent';
      
      Account a = new Account(Name ='testing acc');
insert a;
        
        Opportunity opp= new Opportunity (Name='triggertest', Account = a, AccountId=a.Id, CloseDate = System.today(), StageName='Closed Won');
        insert opp;
        Task t=new Task (whoId=opp.Id, subject='Account - Initial Report', Status='Completed');

        Test.StartTest();
            insert t;
        Test.StopTest();
        
        Opportunity opp2=[Select Id, StageName FROM Opportunity WHERE Id=:opp.Id];
        system.assertEquals(desiredNewOpportunityStage,opp2.StageName);
    }
}

Thanks a lot!

 
Hi all,

I am trying to implement a tasks apex trigger that would automatically change a Lead's status from open to contacted when an Email has been sent out.
I have used the below code with success in the past, but since then we have created three unique record types, one of which has different Statuses and should never be afftected by this trigger. How do I specify that this trigger should only fire for the remaining two record types?

trigger changeLeadStatus on Task (before insert, before update) {

    /*String desiredNewLeadStatus = 'Contacted';
    String task_subject_check = 'Email: Would you like to do more Brand Endorsements?';
    List<Id> leadIds=new List<Id>();
    
    for(Task t:trigger.new){
        if(t.Status=='Completed'){
            if(t.whoId!=NULL){//check if the task is associated with a lead
                if(t.Subject.contains(task_subject_check)){
                leadIds.add(t.whoId);}
            }//if 2
        }//if 1
    }//for
    List<Lead> leadsToUpdate=[SELECT Id, Status FROM Lead WHERE Id IN :leadIds AND IsConverted=FALSE];
    For (Lead l:leadsToUpdate){
        l.Status=desiredNewLeadStatus;
    }//for
    
    try{
        update leadsToUpdate;
    }catch(DMLException e){
        system.debug('Leads were not all properly updated.  Error: '+e);
    }*/
}//trigger
I have just created a formassembly form which we sent to potential clients. Those potential clients are Leads and a lot of their information is in the database already. Once they have completed the form and returned it to us the Lead status automatically changes from "Identified" to "Signed". At that point I ould like to set up a trigger that immediately converts those leads into a Person - Account. Anyone knows how I can achieve this?
Hi there, currently struggling with this slight problem:

I have created a custom object called "List", with a child custom object nested within that called "Person Accounts" (the name field is set to be an auto number on that one). Other than the master-detail relationship it has to "List" it also has a master detail relationship to Accounts (with a filter to limit it to person accounts only), enabling me to add person accounts to specific lists.
I now want to create a custom button that should sit on the account view that enables me o bulk add several people to a list of my choosing. Is that possible? 
Hi all, 

I'm trying to create a trigger that will automatically change an opportunity stage once a certain task is completeted. The code is here:

trigger changeOpportunityStage on Task (before insert, after update) {

    Set<Id> oppIds = new Set<Id>();  
    for(Task t:trigger.new){
        String wId = t.WhatId;
              if(wId!=null && wId.startsWith('006') && t.Status == 'Completed' && t.Subject.Contains('Account - Initial Report')){
                oppIds.add(t.WhatId);
  }
    }//for 
   List<Opportunity> opps = [select Id, StageName from opportunity where id in: oppIds AND ( RecordType.name = 'Influencer' or RecordType.name = 'Creative')];    
        for(Opportunity opp : opps){
          if(opp.StageName == 'Closed Won')
          opp.StageName = 'Report Sent';
}
    try{
        update opps;
    }catch(DMLException e){
        system.debug('Opportunities were not all properly updated.  Error: '+e);
    }   
}//trigger

It works perfectly in sandbox and I've been trying to deploy it to production. However, my apex text class has been flagging up this error and I don't know how to resolve this issue:

testChangeOpportunityStage.testChangeOpportunityStatusTrigger(), Details: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Name ID: id value of incorrect type: 00624000008UJnkAAG: [WhoId] Class.testChangeOpportunityStage.testChangeOpportunityStatusTrigger: line 14, column 1

Here is my test class:

@isTest
private class testChangeOpportunityStage {
    static testMethod void testChangeOpportunityStatusTrigger(){
      String desiredNewOpportunityStage='Report Sent';
      
      Account a = new Account(Name ='testing acc');
insert a;
        
        Opportunity opp= new Opportunity (Name='triggertest', Account = a, AccountId=a.Id, CloseDate = System.today(), StageName='Closed Won');
        insert opp;
        Task t=new Task (whoId=opp.Id, subject='Account - Initial Report', Status='Completed');

        Test.StartTest();
            insert t;
        Test.StopTest();
        
        Opportunity opp2=[Select Id, StageName FROM Opportunity WHERE Id=:opp.Id];
        system.assertEquals(desiredNewOpportunityStage,opp2.StageName);
    }
}

Thanks a lot!

 
Hi all,

I am trying to implement a tasks apex trigger that would automatically change a Lead's status from open to contacted when an Email has been sent out.
I have used the below code with success in the past, but since then we have created three unique record types, one of which has different Statuses and should never be afftected by this trigger. How do I specify that this trigger should only fire for the remaining two record types?

trigger changeLeadStatus on Task (before insert, before update) {

    /*String desiredNewLeadStatus = 'Contacted';
    String task_subject_check = 'Email: Would you like to do more Brand Endorsements?';
    List<Id> leadIds=new List<Id>();
    
    for(Task t:trigger.new){
        if(t.Status=='Completed'){
            if(t.whoId!=NULL){//check if the task is associated with a lead
                if(t.Subject.contains(task_subject_check)){
                leadIds.add(t.whoId);}
            }//if 2
        }//if 1
    }//for
    List<Lead> leadsToUpdate=[SELECT Id, Status FROM Lead WHERE Id IN :leadIds AND IsConverted=FALSE];
    For (Lead l:leadsToUpdate){
        l.Status=desiredNewLeadStatus;
    }//for
    
    try{
        update leadsToUpdate;
    }catch(DMLException e){
        system.debug('Leads were not all properly updated.  Error: '+e);
    }*/
}//trigger
I have just created a formassembly form which we sent to potential clients. Those potential clients are Leads and a lot of their information is in the database already. Once they have completed the form and returned it to us the Lead status automatically changes from "Identified" to "Signed". At that point I ould like to set up a trigger that immediately converts those leads into a Person - Account. Anyone knows how I can achieve this?