• Apex Estrategia
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies

Im Trying to create a case in one of my account if my field antecipado__c = AR.

 

And I Want to Avoid duplicate. So I Tried this:

 

trigger CriarCaseAccount_AR on Account (after update) {
    
List<Case> cases = [SELECT Id, motivo__c FROM Case WHERE motivo__c = :'Formandos AR'];
    if(cases.size() < 1)
        
    List<Account> act = [SELECT Id, antecipado__c, lab__c FROM Account WHERE antecipado__c = :'AR'];
    
    for (Account acc: Trigger.new) {
        Account oldAccount = Trigger.oldMap.get(acc.ID);
        if (acc.Antecipado__c != oldAccount.Antecipado__c || acc.Lab__c != oldAccount.Lab__c){
            if (acc.lab__c <> null && acc.Antecipado__c == 'AR') {                
                    
        Case c = new Case
              (AccountID = acc.id,
               Func_abertura_chamado__c = 'ALAN FERNANDES',
               RecordTypeID = '012U000000011yC',
               Motivo__c = 'Formandos AR',
               Prazo_para_resolucao__c = Date.today(),
               Description = 'Montagens',
               Subject = 'CP7',
               Priority = 'Médio',
               Origin = 'Interna',
               Status = 'Novo',
               Ownerid = '005U0000001KraS');
      cases.add(c);
                }
        }
    }
insert cases;
}

 Tks!!!

Hi there,

 

I'm brand new in Apex and I never used any program to create triggers or class like Eclipse or others.

What I did it’s just create the trigger or class in my Sandbox using developer console and send to my production.

 

Doing this I never learned how to delete an trigger or class in my production and this is becoming too appears some problems to me.

 

Is there an easy way to delete triggers or class from my production that are messing me up?

 

Thanks !

Hi,

 

I created this trigger:

 

trigger CriarTarefa_Produtos_Cobranca on Task (after update) {

    List<Task> taskProd = new List<Task>();
    for (Task tt : Trigger.new)
    if (tt.subject == 'Cobrança - Problemas com produtos' && tt.status == 'Concluído' || tt.subject == 'Cobrança - Pergunta não solucionada' && tt.status == 'Concluído'){
                taskProd.add (new Task(
                         Subject = 'Cobrança - Questão solucionada?',
                         Status = 'Nenhum',
                         WhatID = tt.WhatID,
                         Description = tt.description,
                    	 OwnerId = '005U0000001KrXY',
                         ActivityDate = Date.today()));
 }

    for (Task tt : Trigger.new)
    if (tt.subject == 'Cobrança - Questão solucionada?' && tt.Quest_o_solucionada__c == 'SIM' && tt.status == 'Concluído'){
                taskProd.add (new Task(
                         Subject = 'Cobrança - Feche o chamado e notifique o formando',
                         Status = 'Nenhum',
                         WhatID = tt.WhatID,
                         Description = tt.description,
                    	 OwnerId = '005U0000001KrXY',
                         ActivityDate = Date.today()));
 }
    for (Task tt : Trigger.new)
    if (tt.subject == 'Cobrança - Questão solucionada?' && tt.Quest_o_solucionada__c == 'NÃO' && tt.status == 'Concluído'){
                taskProd.add (new Task(
                         Subject = 'Cobrança - Pergunta não solucionada',
                         Status = 'Nenhum',
                         WhatID = tt.WhatID,
                         Description = tt.description,
                    	 OwnerId = '005U0000000FrCz',
                         ActivityDate = Date.today()));
 }
                insert taskProd;
            }

 And my test class:

 

@IsTest(SeeAllData=true)
public class CriarTarefa_Pendencia_Duomind_test{
static testmethod void MyUnitTest(){
    
 
     User u = [select id from User where LastName='Marketing'];
      
     Case c = new Case (recordtypeid='012U000000011yC');
    
     Task tsk  = new Task(Status='Não iniciado', Priority='Normal', subject='- Iniciador do Fluxo -');
     insert tsk;
 
    tsk.Status = 'Concluído';
    update tsk;
}
}

 

My code coverage is in 74%.

What I'm missing here?

 

Any help?

 

Thanks !

Hi !

 

I create a trigger to close my case when I close one specific task.

 

trigger FechaTask_FechaCase on Task (after update) {

Task[] cse = Trigger.new;

    Set<ID> cseIds = new Set<ID>();
    for (Task t:cse)
      if (t.status == 'Completed' && t.subject == 'Baixar PP')
      cseIds.add(t.whatid);

      for (Case c : [select id, motivo__c, status from case where id in :cseIds for update])
      if (c.motivo__c == 'Solicitação de Pagamento'){
        c.status = 'Closed';
        update c;
      }
    }

 

And I got an error:

 

  • Corpo: Validation Error: Value is required
  • FechaTask_FechaCase: System.LimitException: Too many SOQL queries: 101

 

I don't know why this error appears just when I try to close the case.

If I update a regular field my trigger works.

Hi,

 

I created this trigger:

 

trigger CriarTarefa_Produtos_Cobranca on Task (after update) {

    List<Task> taskProd = new List<Task>();
    for (Task tt : Trigger.new)
    if (tt.subject == 'Cobrança - Problemas com produtos' && tt.status == 'Concluído' || tt.subject == 'Cobrança - Pergunta não solucionada' && tt.status == 'Concluído'){
                taskProd.add (new Task(
                         Subject = 'Cobrança - Questão solucionada?',
                         Status = 'Nenhum',
                         WhatID = tt.WhatID,
                         Description = tt.description,
                    	 OwnerId = '005U0000001KrXY',
                         ActivityDate = Date.today()));
 }

    for (Task tt : Trigger.new)
    if (tt.subject == 'Cobrança - Questão solucionada?' && tt.Quest_o_solucionada__c == 'SIM' && tt.status == 'Concluído'){
                taskProd.add (new Task(
                         Subject = 'Cobrança - Feche o chamado e notifique o formando',
                         Status = 'Nenhum',
                         WhatID = tt.WhatID,
                         Description = tt.description,
                    	 OwnerId = '005U0000001KrXY',
                         ActivityDate = Date.today()));
 }
    for (Task tt : Trigger.new)
    if (tt.subject == 'Cobrança - Questão solucionada?' && tt.Quest_o_solucionada__c == 'NÃO' && tt.status == 'Concluído'){
                taskProd.add (new Task(
                         Subject = 'Cobrança - Pergunta não solucionada',
                         Status = 'Nenhum',
                         WhatID = tt.WhatID,
                         Description = tt.description,
                    	 OwnerId = '005U0000000FrCz',
                         ActivityDate = Date.today()));
 }
                insert taskProd;
            }

 And my test class:

 

@IsTest(SeeAllData=true)
public class CriarTarefa_Pendencia_Duomind_test{
static testmethod void MyUnitTest(){
    
 
     User u = [select id from User where LastName='Marketing'];
      
     Case c = new Case (recordtypeid='012U000000011yC');
    
     Task tsk  = new Task(Status='Não iniciado', Priority='Normal', subject='- Iniciador do Fluxo -');
     insert tsk;
 
    tsk.Status = 'Concluído';
    update tsk;
}
}

 

My code coverage is in 74%.

What I'm missing here?

 

Any help?

 

Thanks !

Hi !

 

I create a trigger to close my case when I close one specific task.

 

trigger FechaTask_FechaCase on Task (after update) {

Task[] cse = Trigger.new;

    Set<ID> cseIds = new Set<ID>();
    for (Task t:cse)
      if (t.status == 'Completed' && t.subject == 'Baixar PP')
      cseIds.add(t.whatid);

      for (Case c : [select id, motivo__c, status from case where id in :cseIds for update])
      if (c.motivo__c == 'Solicitação de Pagamento'){
        c.status = 'Closed';
        update c;
      }
    }

 

And I got an error:

 

  • Corpo: Validation Error: Value is required
  • FechaTask_FechaCase: System.LimitException: Too many SOQL queries: 101

 

I don't know why this error appears just when I try to close the case.

If I update a regular field my trigger works.