• mrteles
  • NEWBIE
  • 25 Points
  • Member since 2014
  • Admin and Developer Salesforce

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 9
    Replies
I need some assitance with creating a Trigger that creates a task from a lead record that has text in the Lead Web Comment Field to create a task for the Lead owner, with priority of Normal, Subject of Text "Lead Web Comment", Status of Lead Web Comment.

I have this trigger started but don't know exactly how to have all the fields populated with the above requirements.

Could someone please help?


trigger Lead_After_Insert on Lead (after insert)

{
  list<Task> lNewTasks = new list<Task>();

  for(integer i=0; i<trigger.new.size(); i++)

  {

     lNewTasks.add(MyTask = new Task(

       Subject = 'Lead Web Comment',

       WhoID = trigger.new[i].id

       *Other Task Fields Here*

     );

   }

   insert lNewTasks;

}
hi community, I'm anxious to deploy my trigger, but my code coverage is bad <75% =(

My trigger:
trigger InsertDeploymentProject on Opportunity (after insert, after update) {
	List<Projeto_Implantacao__c> pi = new List<Projeto_Implantacao__c>();
	Projeto_Implantacao__c projeto;
	Map<Id, Schema.RecordTypeInfo> rtMap = Schema.SObjectType.Opportunity.getRecordTypeInfosById();
	Set<Id> accountIds =  new Set<Id>();
	
	for(Opportunity o:Trigger.new){
		accountIds.add(o.AccountId);
	}
	Map<Id, Account> accountMap = new Map<Id, Account>([SELECT Name FROM Account WHERE Id IN :accountIds]);
	
	
	if(Trigger.isAfter) {
    if(Trigger.isUpdate) {
       for(Opportunity o: Trigger.new) {
       	for(Opportunity old: Trigger.old) {
           if(o.Id==old.id && o.IsWon  ){
           	 
             projeto = new Projeto_Implantacao__c();
             
             projeto.Name = 'Imp - '+ accountMap.get(o.AccountId).Name + ' - ' + rtMap.get(o.RecordTypeId).getName();
             projeto.Implantacao__c = o.AccountId;
             projeto.Status__c = 'Aguardando início';
             pi.add(projeto);           
           }
       	}   
       }       
    }
    if(!pi.IsEmpty())
      insert projeto;
  }
}

My test:

@isTest private class TesteInsertDeploymentProject {

    @istest static void TestDeploymentProject() {
	Account account = new Account();
	account.Name = 'Nome da conta de teste';
	account.Telefone_2__c = '(067) 3027-9600';
	account.Phone = '(067) 3027-9600';
	account.Classificacao_PAF_ECF__c = 'Sem ECF + Não PAF';
	account.CNPJ__c = '86.571.322/0001-06';
	account.Unidade_de_atendimento__c = 'Campo Grande';
	String accid = account.Id;
	
	insert account;
	
	Opportunity opp = new Opportunity();
	opp.Name = 'Opp';
	opp.AccountId = account.Id;
	opp.ForecastCategoryName = 'Funil';
	opp.CloseDate = Date.today();
	opp.StageName = 'Negocição e revisão';
	opp.Expectativas_do_cliente__c = 'Test';
	opp.Numero_de_licencas__c = 1;
	opp.Amount = 1;
	opp.Valor_Implantacao__c = 1;

	String op = opp.Id;
	
	insert opp;
	
	Projeto_Implantacao__c projeto = new Projeto_Implantacao__c();             
	System.debug(projeto.Name = 'Imp - '+ opp.AccountId + ' - ' + opp.RecordTypeId);
	System.debug(projeto.Implantacao__c = opp.AccountId);
	System.debug(projeto.Status__c = 'Waiting for start');
	insert projeto;
	
	System.debug(opp.StageName = 'Close and won');
	update opp;
	
	projeto = new Projeto_Implantacao__c();             
	System.debug(projeto.Name = 'Imp - '+ opp.AccountId + ' - ' + opp.RecordTypeId);
	System.debug(projeto.Implantacao__c = opp.AccountId);
	System.debug(projeto.Status__c = 'Waiting for start');
	insert projeto;
	
	opp.StageName = 'Close and Lost';
	update opp;
	
	projeto = new Projeto_Implantacao__c();             
	System.debug(projeto.Name = 'Imp - '+ opp.AccountId + ' - ' + opp.RecordTypeId);
	System.debug(projeto.Implantacao__c = opp.AccountId);
	System.debug(projeto.Status__c = 'Waiting for start');
	insert projeto;
	          
	projeto = new Projeto_Implantacao__c();             
	System.debug(projeto.Name = 'Imp - '+ opp.AccountId + ' - ' + opp.RecordTypeId);
	System.debug(projeto.Implantacao__c = opp.AccountId);
	System.debug(projeto.Status__c = 'Waiting for start');
	insert projeto; 
	
	
	
    }
}


I'm writing some triggers and I have difficult to deploy because I have difficult to create test class.

I saw various docs but they not helped a lot. 

Anyone help me?

Tnx.
 

I've created the following trigger and it is only updating the task before an update and not before an insert. Help me troubleshoot?

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

List<User> InsideSalesUser = [SELECT Id FROM User where UserRoleId='00E30000001rctV'];

Set<Id> InsideSalesUserId = new set<Id>();
if (InsideSalesUser != NULL){

for (User u :InsideSalesUser) {
    InsideSalesUserId.add(u.Id);
    }
}

List<Lead> LeadsWithCampaign = [SELECT Id FROM Lead where Current_Teleprospecting_Campaign__c != NULL];
Set<Id> LeadsWithCampaignId = new set<Id>();
if (LeadsWithCampaign != NULL){

for (Lead l :LeadsWithCampaign) {
    LeadsWithCampaignId.add(l.id);
    }
}

for (Task t: Trigger.new) {
    if(InsideSalesUserId.contains(t.OwnerID) && t.WhoId != NULL && LeadsWithCampaignId.contains(t.WhoId) && t.IsClosed == true && String.valueOf(t.WhoId).startsWith('00Q')&& t.Subject != NULL && String.valueOf(t.Subject).startsWith('Email'))
    
    t.IS_Response__c = true;
    }
}


hi community, I'm anxious to deploy my trigger, but my code coverage is bad <75% =(

My trigger:
trigger InsertDeploymentProject on Opportunity (after insert, after update) {
	List<Projeto_Implantacao__c> pi = new List<Projeto_Implantacao__c>();
	Projeto_Implantacao__c projeto;
	Map<Id, Schema.RecordTypeInfo> rtMap = Schema.SObjectType.Opportunity.getRecordTypeInfosById();
	Set<Id> accountIds =  new Set<Id>();
	
	for(Opportunity o:Trigger.new){
		accountIds.add(o.AccountId);
	}
	Map<Id, Account> accountMap = new Map<Id, Account>([SELECT Name FROM Account WHERE Id IN :accountIds]);
	
	
	if(Trigger.isAfter) {
    if(Trigger.isUpdate) {
       for(Opportunity o: Trigger.new) {
       	for(Opportunity old: Trigger.old) {
           if(o.Id==old.id && o.IsWon  ){
           	 
             projeto = new Projeto_Implantacao__c();
             
             projeto.Name = 'Imp - '+ accountMap.get(o.AccountId).Name + ' - ' + rtMap.get(o.RecordTypeId).getName();
             projeto.Implantacao__c = o.AccountId;
             projeto.Status__c = 'Aguardando início';
             pi.add(projeto);           
           }
       	}   
       }       
    }
    if(!pi.IsEmpty())
      insert projeto;
  }
}

My test:

@isTest private class TesteInsertDeploymentProject {

    @istest static void TestDeploymentProject() {
	Account account = new Account();
	account.Name = 'Nome da conta de teste';
	account.Telefone_2__c = '(067) 3027-9600';
	account.Phone = '(067) 3027-9600';
	account.Classificacao_PAF_ECF__c = 'Sem ECF + Não PAF';
	account.CNPJ__c = '86.571.322/0001-06';
	account.Unidade_de_atendimento__c = 'Campo Grande';
	String accid = account.Id;
	
	insert account;
	
	Opportunity opp = new Opportunity();
	opp.Name = 'Opp';
	opp.AccountId = account.Id;
	opp.ForecastCategoryName = 'Funil';
	opp.CloseDate = Date.today();
	opp.StageName = 'Negocição e revisão';
	opp.Expectativas_do_cliente__c = 'Test';
	opp.Numero_de_licencas__c = 1;
	opp.Amount = 1;
	opp.Valor_Implantacao__c = 1;

	String op = opp.Id;
	
	insert opp;
	
	Projeto_Implantacao__c projeto = new Projeto_Implantacao__c();             
	System.debug(projeto.Name = 'Imp - '+ opp.AccountId + ' - ' + opp.RecordTypeId);
	System.debug(projeto.Implantacao__c = opp.AccountId);
	System.debug(projeto.Status__c = 'Waiting for start');
	insert projeto;
	
	System.debug(opp.StageName = 'Close and won');
	update opp;
	
	projeto = new Projeto_Implantacao__c();             
	System.debug(projeto.Name = 'Imp - '+ opp.AccountId + ' - ' + opp.RecordTypeId);
	System.debug(projeto.Implantacao__c = opp.AccountId);
	System.debug(projeto.Status__c = 'Waiting for start');
	insert projeto;
	
	opp.StageName = 'Close and Lost';
	update opp;
	
	projeto = new Projeto_Implantacao__c();             
	System.debug(projeto.Name = 'Imp - '+ opp.AccountId + ' - ' + opp.RecordTypeId);
	System.debug(projeto.Implantacao__c = opp.AccountId);
	System.debug(projeto.Status__c = 'Waiting for start');
	insert projeto;
	          
	projeto = new Projeto_Implantacao__c();             
	System.debug(projeto.Name = 'Imp - '+ opp.AccountId + ' - ' + opp.RecordTypeId);
	System.debug(projeto.Implantacao__c = opp.AccountId);
	System.debug(projeto.Status__c = 'Waiting for start');
	insert projeto; 
	
	
	
    }
}


I'm writing some triggers and I have difficult to deploy because I have difficult to create test class.

I saw various docs but they not helped a lot. 

Anyone help me?

Tnx.
 

I need some assitance with creating a Trigger that creates a task from a lead record that has text in the Lead Web Comment Field to create a task for the Lead owner, with priority of Normal, Subject of Text "Lead Web Comment", Status of Lead Web Comment.

I have this trigger started but don't know exactly how to have all the fields populated with the above requirements.

Could someone please help?


trigger Lead_After_Insert on Lead (after insert)

{
  list<Task> lNewTasks = new list<Task>();

  for(integer i=0; i<trigger.new.size(); i++)

  {

     lNewTasks.add(MyTask = new Task(

       Subject = 'Lead Web Comment',

       WhoID = trigger.new[i].id

       *Other Task Fields Here*

     );

   }

   insert lNewTasks;

}