• Rafael Motta
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 1
    Replies
I am working with a service bot, I removed the pre chat because it is not consistent with the needs of the business, and all the creation of accounts, contacts and cases, I am managing them with a flow. However, when I want to send the information to the live chat transcript, the link between the case and the agent's chat does not appear. inside my stream add an update to the live chat transcript. Could someone help me to know what I have to do?

Cheers

User-added image

User-added image
Good morning Trailblazers.
I would appreciate your help to clear my mind. I would like to create a duplication rule for cases, so the only option I think i need to create a class, the problem is that I am not a developer and I want to help my team because I no longer have pending.
he criteria are as follows.
For the same Customer (Person Account)
Case Status does not equal to Resolved or Closed
Order Number = Exact match
Case Reason = Exact Match
Error Message: Duplicate Case [Case Number (link possible?)].
A case is already opened against this exact Customer, Order Number, and Case Reason.

I could crate  the select of fields but when i try to ser If sentence, i can save the field 

public class LP_CheckMarketingCustomerOnly{
    Set<Id> CasesIds = new Set<Id>();
       public static void GetAllCases() {
      // Esta Consulta funciona,  la tomare como base
         Account[] AllAccounts = [SELECT Id,(SELECT Id,Order_Number__c,Reason,Status FROM Cases) FROM Account LIMIT 3]; 
        for (Account accounts : AllAccounts) {

            //for(Case cases:accounts.Cases)
             //        System.debug('Account Id:'+accounts.Id+'   Case Id:'+cases.Id);
            //accounts.Marketing_Customer_Only__c=true;
           }
           System.debug('This is a update'+ AllAccounts);
           
           //update AllAccounts;
             //System.debug('This is a testing debug cases'+ AllAccounts);
    
       }}
 
if you can guide me i apriciate 
 
Hi everyone.

I have an request to clone attachment but i can´t solve this isue. in account i have 2 record types account and Prospect, Both are arecord types from Account.


CORRECT FLOW:
1.- IF a record with record type Prospect has the same Sap_Number(custom field) of record  with Account Recod type.
2.- Clone Attachments of Prospect Record and set in Account Record.

if i run the class Salesforce Show Me:
"Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger ActualizaAttachmente caused an unexpected exception, contact your administrator: ActualizaAttachmente: execution of AfterUpdate caused by: System.QueryException: List has more than 1 row for assignment to SObject: Class.Set_attachments.GetAccounts: line 34, column 1"


I know that i have most of 1 attachment and I try to set in For sentence to get all attachments. but salesforce Show me:
"Loop must iterate over collection: Attachment"

this is an extract of code whit the error:

   Attachment GetattAchment = New Attachment();
                   
        IF(GetattAchment!=null){
             
          GetattAchment =[SELECT id,Body,Name, Description, ParentId FROM Attachment WHERE ParentId IN (SELECT id FROM Account WHERE RecordTypeid='01236000001A0hVAAS')];
                 For (attachment att: GetattAchment){
                GetattAchment = new Attachment();
                }
         System.debug('attachment'+ GetattAchment);
                    System.debug('¿Alcanzo el parent?'+ GetattAchment.ParentId);

I show you complete apex class:

public class Set_attachments {
public static void GetAccounts(list<Account>Accountlist){
    
    //Create Variables
    
    //Name=Account Id=01236000001A0hQAAS
    //Name=Prospect RecordType:Id=01236000001A0hVAAS
    List<RecordType> GetRecord = New List<RecordType>();
    List<Account> GetAccount = New List<Account>();
    List<Account> GetProspect = New List<Account>();
    List<Attachment> GetAttachacc = New List<Attachment>();
    List<Attachment> lstattachment= new List <Attachment>();
    
    
    //QUERYS RECORDTYPES, ACCOUNTS ACCOUNT AND ACCOUNTS PROSPECT
    GetRecord =[SELECT id, Name FROM RecordType];
    GetAccount =[SELECT id, Name, ONTAP_SAP_Number__c FROM Account WHERE ONTAP_SAP_Number__c !=null AND RecordTypeid='01236000001A0hQAAS' ];
    GetProspect =[SELECT id, Name, ONTAP_SAP_Number__c FROM Account WHERE ONTAP_SAP_Number__c !=null AND RecordTypeid='01236000001A0hVAAS' ];
    
For (Account accp: GetProspect){        
    For (Account acc: GetAccount){    
    
    IF(GetAttachacc!=null){
    GetAttachacc =[SELECT id,Body,Name, Description, ParentId FROM attachment WHERE ParentId IN (SELECT id FROM Account WHERE RecordTypeid='01236000001A0hQAAS') ];
       System.debug('los attachment son : ' +GetAttachacc);
    
    //GET ACCOUNTS OF PROSPECT WITH SAP_NUMBER 
                IF(accp.ONTAP_SAP_Number__c==acc.ONTAP_SAP_Number__c ){
         
                    
        //TRY TO GET ALL ATTACHMENTS, OF PROSPECT BUT sALESFORCE DISPLAY ME 
        //************************************************************************************
        //"Error: Invalid Data. 
        //Review all error messages below to correct your data.
        //Apex trigger ActualizaAttachmente caused an unexpected exception, contact your administrator: ActualizaAttachmente: execution of AfterUpdate caused by: System.QueryException: 
        //List has more than 1 row for assignment to SObject: Class.Set_attachments.GetAccounts: line 34, column 1"
        //************************************************************************************            
          Attachment GetattAchment = New Attachment();
                   
        IF(GetattAchment!=null){
             
          GetattAchment =[SELECT id,Body,Name, Description, ParentId FROM Attachment WHERE ParentId IN (SELECT id FROM Account WHERE RecordTypeid='01236000001A0hVAAS')];
                 For (attachment att: GetattAchment){
                GetattAchment = new Attachment();
                }
         System.debug('attachment'+ GetattAchment);
                    System.debug('¿Alcanzo el parent?'+ GetattAchment.ParentId);
            
              
             /* attachment newFile = new Attachment();
                      newFile = GetattAchment.clone();
                    newFile.id= GetattAchment.id;
                    newFile.Name= GetattAchment.name;
                    newFile.Body= GetattAchment.Body;
                    newFile.ParentId=GetattAchment.ParentId;
                    lstattachment.add(newFile);
                    newFile = new Attachment();
                    }
                    if(!lstattachment.isEmpty()){
                    Insert lstattachment;
                    }*/
            
        
              
              
        
     }
}
}}
    
}}}
Hi all. I set this question but i can solve  my problem I have another Script I need to do in appex clase.

in the accounts object, I have 2 record types (Prospects and Accounts) and a field that has the same id in the 2 records Sap_number Request:

If the record with the record Type "account" has the same Sap_number that the record with the Record type "Prospectus", clone the attachments contained in the "Prospects" record and paste them into the registry Record Type "Account" I have already mentioned this question before but I still can not clone the attachments and paste them into the new record. my code is as follows:

Script to get attachments in Prospect:

//variables 
    Integer attachmentId;
    String attachmentName;
    Blob attachmentBody;
    List<attachment> attachmentsToClone;
    List<attachment> attachmentList;

    List<attachment> getAttachmentList = [SELECT Id, Body, Name, Description, lastModifiedDate, CreatedById, CreatedDate, OwnerId, CreatedBy.Name, ParentId
                      FROM Attachment WHERE ParentId IN (SELECT Id FROM Account WHERE RecordType.DeveloperName = 'Prospect') 
                      ORDER BY CreatedDate Desc];
    
    
       List<String> valueid  = new List<String>();
    For (attachment attach: getAttachmentList){
    valueid.add(attach.Id);
    }
        List<String> valuename  = new List<String>();
        For (attachment attach: getAttachmentList){
        valuename.add(attach.Name);
        }
            List<String> valuedescription  = new List<String>();
            For (attachment attach: getAttachmentList){
            valuedescription.add(attach.Description);
            }
                List<String> valueparent  = new List<String>();
                For (attachment attach: getAttachmentList){
                valueparent.add(attach.ParentId);
                }
                    List<Blob> valuebody  = new List<Blob>();
                    For (attachment attach: getAttachmentList){
                    valuebody.add(attach.Body);
                    }
                        List<String> valueownwrid  = new List<String>();
                        For (attachment attach: getAttachmentList){
                        valueownwrid.add(attach.OwnerId);
                        }

        System.debug('This is debug getattachment before to clone'+ getAttachmentList);
        System.debug('This is debug, attachmentId before to clone' + valueid);
        System.debug('This is debug, attachmentName before to clone' + valuename);
           System.debug('This is debug, attachmentBody before to clone' + valuebody); 
        System.debug('This is debug, attachmentParentId before to clone' + valueparent);
        System.debug('This is debug, attachmentOwnerId before to clone' + valueownwrid); 


This  is  my script to get Attachments in Accounts:

// obtener attachments en accounts
List<attachment> getAttachmentListacc = [SELECT Id, Body, Name, Description, lastModifiedDate, CreatedById, CreatedDate, OwnerId, CreatedBy.Name, ParentId
                      FROM Attachment WHERE ParentId IN (SELECT Id FROM Account WHERE RecordType.DeveloperName = 'Account') 
                      ORDER BY CreatedDate Desc];
    
       List<String> valueidacc  = new List<String>();
    For (attachment attach: getAttachmentListacc){
    valueid.add(attach.Id);
    }
        List<String> valuenameacc  = new List<String>();
        For (attachment attach: getAttachmentListacc){
        valuename.add(attach.Name);
        }
            List<String> valuedescriptionacc  = new List<String>();
            For (attachment attach: getAttachmentListacc){
            valuedescription.add(attach.Description);
            }
                List<String> valueparentacc  = new List<String>();
                For (attachment attach: getAttachmentListacc){
                valueparent.add(attach.ParentId);
                }
                    List<Blob> valuebodyacc  = new List<Blob>();
                    For (attachment attach: getAttachmentListacc){
                    valuebody.add(attach.Body);
                    }
                        List<String> valueownwridacc  = new List<String>();
                        For (attachment attach: getAttachmentListacc){
                        valueownwrid.add(attach.OwnerId);
                        }

        System.debug('This is debug Accounts, getattachment before to clone'+ getAttachmentListacc);
        System.debug('This is debug Accounts, attachmentId before to clone' + valueidacc);
        System.debug('This is debug Accounts, attachmentName before to clone' + valuenameacc);
           System.debug('This is debug Accounts, attachmentBody before to clone' + valuebodyacc); 
        System.debug('This is debug Accounts, attachmentParentId before to clone' + valueparentacc);
        System.debug('This is debug Accounts, attachmentOwnerId before to clone' + valueownwridacc);



This is my evaluation of Sap_number records in Boath RT:



 if(valueidacc != null && valuenameacc !=null && valuebodyacc != null){
        
        System.debug('This is debug Accounts, attachmentId If is Null' + valueidacc);
        System.debug('This is debug Accounts, attachmentName If is Null' + valuenameacc);
           System.debug('This is debug Accounts, attachmentBody If is Null' + valuebodyacc); 
        
        //obtener lista de  prospectos
    List<Account>Accountlistprospect=new List<Account>();
    
    //obtener lista de cuentas
    List<Account>Accountlistaccount=new List<Account>();
    
    //obtener Id de las cuentas 
    Set<id>AccountlistId=new Set<id>();
    
    //obtener numero de sap
    Set<String>AccountlistSapnumber=new Set<String>();
        
        // hace el recuento de cuentas 
    for(Account acc:Accountlist){
    
     //Obtener las cuentas que tienen el record type y que sap number no esta vacio
        if((acc.RecordTypeId==Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Prospect').getRecordTypeId()) && acc.ONTAP_SAP_Number__c!=null){
            Accountlistprospect.add(acc);
            AccountlistId.add(acc.id);
            AccountlistSapnumber.add(acc.ONTAP_SAP_Number__c);
            
        }
    }
    
        //obtiene las cuentas con el record type cuentas que tengan un numero sap igual al del Account
    For(Account acc:[Select id, ONTAP_SAP_Number__c from Account WHERE ONTAP_SAP_Number__c in:AccountlistSapnumber AND RecordTypeId=:Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Account').getRecordTypeId()]){
        Accountlistaccount.add(acc);
    }
        System.debug('lista de prospectos '+Accountlistprospect);
        System.debug('lista de account '+ Accountlistaccount);
    System.debug('lista de id de cuenta '+AccountlistId);
    System.debug('lista de sapnumber '+AccountlistSapnumber);



This is My insert of attacghments:

 if(Accountlistaccount!=null)
    {
   Attachment newFile = getAttachmentList.clone();
   newFile.ParentId = getAttachmentList.ParentId;
   newFile.Body = getAttachmentList.Body;
   newFile.Name = getAttachmentList.Name;
   newFile.Description = getAttachmentList.Description;
   
   insert newFile;




This is a complete Script.

public class Set_attachments {
public static void TESTMETOD(list<Account>Accountlist){
   
    //variables 
    Integer attachmentId;
    String attachmentName;
    Blob attachmentBody;
    List<attachment> attachmentsToClone;
    List<attachment> attachmentList;

    List<attachment> getAttachmentList = [SELECT Id, Body, Name, Description, lastModifiedDate, CreatedById, CreatedDate, OwnerId, CreatedBy.Name, ParentId
                      FROM Attachment WHERE ParentId IN (SELECT Id FROM Account WHERE RecordType.DeveloperName = 'Prospect') 
                      ORDER BY CreatedDate Desc];
    
    
       List<String> valueid  = new List<String>();
    For (attachment attach: getAttachmentList){
    valueid.add(attach.Id);
    }
        List<String> valuename  = new List<String>();
        For (attachment attach: getAttachmentList){
        valuename.add(attach.Name);
        }
            List<String> valuedescription  = new List<String>();
            For (attachment attach: getAttachmentList){
            valuedescription.add(attach.Description);
            }
                List<String> valueparent  = new List<String>();
                For (attachment attach: getAttachmentList){
                valueparent.add(attach.ParentId);
                }
                    List<Blob> valuebody  = new List<Blob>();
                    For (attachment attach: getAttachmentList){
                    valuebody.add(attach.Body);
                    }
                        List<String> valueownwrid  = new List<String>();
                        For (attachment attach: getAttachmentList){
                        valueownwrid.add(attach.OwnerId);
                        }

        System.debug('This is debug getattachment before to clone'+ getAttachmentList);
        System.debug('This is debug, attachmentId before to clone' + valueid);
        System.debug('This is debug, attachmentName before to clone' + valuename);
           System.debug('This is debug, attachmentBody before to clone' + valuebody); 
        System.debug('This is debug, attachmentParentId before to clone' + valueparent);
        System.debug('This is debug, attachmentOwnerId before to clone' + valueownwrid); 
    
    
    // obtener attachments en accounts
List<attachment> getAttachmentListacc = [SELECT Id, Body, Name, Description, lastModifiedDate, CreatedById, CreatedDate, OwnerId, CreatedBy.Name, ParentId
                      FROM Attachment WHERE ParentId IN (SELECT Id FROM Account WHERE RecordType.DeveloperName = 'Account') 
                      ORDER BY CreatedDate Desc];
    
       List<String> valueidacc  = new List<String>();
    For (attachment attach: getAttachmentListacc){
    valueid.add(attach.Id);
    }
        List<String> valuenameacc  = new List<String>();
        For (attachment attach: getAttachmentListacc){
        valuename.add(attach.Name);
        }
            List<String> valuedescriptionacc  = new List<String>();
            For (attachment attach: getAttachmentListacc){
            valuedescription.add(attach.Description);
            }
                List<String> valueparentacc  = new List<String>();
                For (attachment attach: getAttachmentListacc){
                valueparent.add(attach.ParentId);
                }
                    List<Blob> valuebodyacc  = new List<Blob>();
                    For (attachment attach: getAttachmentListacc){
                    valuebody.add(attach.Body);
                    }
                        List<String> valueownwridacc  = new List<String>();
                        For (attachment attach: getAttachmentListacc){
                        valueownwrid.add(attach.OwnerId);
                        }

        System.debug('This is debug Accounts, getattachment before to clone'+ getAttachmentListacc);
        System.debug('This is debug Accounts, attachmentId before to clone' + valueidacc);
        System.debug('This is debug Accounts, attachmentName before to clone' + valuenameacc);
           System.debug('This is debug Accounts, attachmentBody before to clone' + valuebodyacc); 
        System.debug('This is debug Accounts, attachmentParentId before to clone' + valueparentacc);
        System.debug('This is debug Accounts, attachmentOwnerId before to clone' + valueownwridacc); 
    
    if(valueidacc != null && valuenameacc !=null && valuebodyacc != null){
        
        System.debug('This is debug Accounts, attachmentId If is Null' + valueidacc);
        System.debug('This is debug Accounts, attachmentName If is Null' + valuenameacc);
           System.debug('This is debug Accounts, attachmentBody If is Null' + valuebodyacc); 
        
        //obtener lista de  prospectos
    List<Account>Accountlistprospect=new List<Account>();
    
    //obtener lista de cuentas
    List<Account>Accountlistaccount=new List<Account>();
    
    //obtener Id de las cuentas 
    Set<id>AccountlistId=new Set<id>();
    
    //obtener numero de sap
    Set<String>AccountlistSapnumber=new Set<String>();
        
        // hace el recuento de cuentas 
    for(Account acc:Accountlist){
    
     //Obtener las cuentas que tienen el record type y que sap number no esta vacio
        if((acc.RecordTypeId==Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Prospect').getRecordTypeId()) && acc.ONTAP_SAP_Number__c!=null){
            Accountlistprospect.add(acc);
            AccountlistId.add(acc.id);
            AccountlistSapnumber.add(acc.ONTAP_SAP_Number__c);
            
        }
    }
    
        //obtiene las cuentas con el record type cuentas que tengan un numero sap igual al del Account
    For(Account acc:[Select id, ONTAP_SAP_Number__c from Account WHERE ONTAP_SAP_Number__c in:AccountlistSapnumber AND RecordTypeId=:Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Account').getRecordTypeId()]){
        Accountlistaccount.add(acc);
    }
        System.debug('lista de prospectos '+Accountlistprospect);
        System.debug('lista de account '+ Accountlistaccount);
    System.debug('lista de id de cuenta '+AccountlistId);
    System.debug('lista de sapnumber '+AccountlistSapnumber);
        
        
    if(Accountlistaccount!=null)
    {
   Attachment newFile = getAttachmentList.clone();
   newFile.ParentId = getAttachmentList.ParentId;
   newFile.Body = getAttachmentList.Body;
   newFile.Name = getAttachmentList.Name;
   newFile.Description = getAttachmentList.Description;
   
   insert newFile;
        //System.debug(valuebody);
        //attachment ga = getAttachmentListacc;
        //Insert a IN:Attachment WHERE valueparentacc==AccountlistId;
    }
 /* 
    
    //obtener Attachments
    Map<Attachment,id> MapaaccAttachment = new Map<Attachment, id>();
    
    // hace el recuento de cuentas 
    for(Account acc:Accountlist){
        
        //Obtener las cuentas que tienen el record type y que sap number no esta vacio
        if((acc.RecordTypeId==Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Prospect').getRecordTypeId()) && acc.ONTAP_SAP_Number__c!=null){
            Accountlistprospect.add(acc);
            AccountlistId.add(acc.id);
            AccountlistSapnumber.add(acc.ONTAP_SAP_Number__c);
            
        }
    }
    
    //obtiene las cuentas con el record type cuentas que tengan un numero sap igual al del Account
    For(Account acc:[Select id, ONTAP_SAP_Number__c from Account WHERE ONTAP_SAP_Number__c in:AccountlistSapnumber AND RecordTypeId=:Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Account').getRecordTypeId()]){
        Accountlistaccount.add(acc);
    }
    
    //obtiene el attachment
    For(Attachment att:[Select id,Parentid from Attachment WHERE id in:AccountlistId]){
        MapaaccAttachment.put(att, att.ParentId);
    }
    
    System.debug(Accountlistprospect);
    System.debug(AccountlistId);
    System.debug(AccountlistSapnumber);*/
    
  
   /*If(AccountlistSapnumber==AccountlistSapnumber){
        
        System.debug(MapaaccAttachment);
        
    }*/
}:


Just I need Clone Attachments and set in the anoter RecordType Field

whats is wrong whit my screept or how i cant set those attachments in Account Record Type

Best Regards
I have 2 record types in Accounts object, I need copy since Prospect RecordType to Accounts RecordType if boath record have the same "Sap number" (Custom field) i need to copy Attachments from Prospect to Account. in my code I get ids, Developer names and list of records but  I have no Idea how I can clone the attachments from prospect and put it in account record do you have any similar code that could helps me ? or any solution to my problem.

Apex Class:

public class Set_attachments {
public static void TESTMETOD(list<Account>Accountlist){
    //obtener lista de  prospectos
    List<Account>Accountlistprospect=new List<Account>();
    //obtener lista de cuentas
    List<Account>Accountlistaccount=new List<Account>();
    //obtener Id de las cuentas 
    Set<id>AccountlistId=new Set<id>();
    //obtener numero de sap
    Set<String>AccountlistSapnumber=new Set<String>();
    //obtener Attachments
    Map<Attachment,id> MapaaccAttachment = new Map<Attachment, id>();
    // hace el recuento de cuentas 
    for(Account acc:Accountlist){
        
        //Record Type prospectos
        if((acc.RecordTypeId==Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Prospect').getRecordTypeId()) && acc.ONTAP_SAP_Number__c!=null){
            Accountlistprospect.add(acc);
            AccountlistId.add(acc.id);
            AccountlistSapnumber.add(acc.ONTAP_SAP_Number__c);
            
        }
    }
    For(Account acc:[Select id, ONTAP_SAP_Number__c from Account WHERE ONTAP_SAP_Number__c in:AccountlistSapnumber AND RecordTypeId=:Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Account').getRecordTypeId()]){
        Accountlistaccount.add(acc);
    }
    For(Attachment att:[Select id,Parentid from Attachment WHERE id in:AccountlistId]){
        MapaaccAttachment.put(att, att.ParentId);
    }
    
 
        
    }
    
}

    

        
     
I'm trying to clone attachments from a Record Type to another.
I have 2 record types (Prospects and accounts) these types of records belong to the account object. what is sought is that if a record of the record type Prospects has the same number of sap as a record with the record type accounts. Clone the attachments that are in the prospect register and paste them into the account register.  It needs to be a Apex class because I run this class sinze ();

public class Set_SapId {
public static void CloneAttachments{
    List<Accout>GetAccountId =[SELECT ONTAP__SAP_Number__c From Account WHERE RecordType.DeveloperName ='Account'];

    System.debug(GetAccountId);

    List<Accout>GetProspectId =[SELECT ONTAP__SAP_Number__c From Account WHERE RecordType.DeveloperName ='Prospect'];
    System.debug(GetProspectId);

    if(GetProspectId.ONTAP__SAP_Number__c= GetAccountId.ONTAP__SAP_Number__c){

Attachment fileAttachment = [SELECT SELECT Id,
                              Body,
                              Name,
                              Description,
                              ParentId
                              FROM Attachment
                              WHERE Id=:attachmentId] 


  Attachment newFile = fileAttachment.clone();
   // newFile.ParentId = paramParentId;
    //insert newFile;
    }
}


}

So far I have this code but I can not think of ideas to paste the cloned atachments in the account register. If someone could support me with that, I would appreciate it

 

Hi, how are you?
I'm trying to have code coverage Could you support me in determining the reason why the code is not covered?


first of all, Thanks


@isTest
public class ISSM_WSCancelarPedidos_tst {
    static testmethod void processWebService() {
        // VARIABLES
        Id RT_Emergency_id;
        Id RT_GPOrder_id;
        List<RecordType> RecordType_lst = new List<RecordType>();
RecordTypeId_id =  Schema.SObjectType.ONTAP__Order__c.getRecordTypeInfosByDeveloperName().get('Emergency').getRecordTypeId();
                Orders_lst = [SELECT Id, ONCALL__SAP_Order_Number__c, ISSM_IdEmptyBalance__c, toLabel(ONTAP__OrderStatus__c), ONCALL__Order_Created_Date_Time__c, RecordtypeId FROM ONTAP__Order__c WHERE Id =:RegistroId_id];
            
                if (Orders_lst != null  && !Orders_lst.isEmpty()) {
                    for (ONTAP__Order__c reg : Orders_lst) {
                        // Get date of datetime format
                        DateTime date_dt = reg.ONCALL__Order_Created_Date_Time__c;
                        date_dt = date.newInstance(date_dt.year(), date_dt.month(), date_dt.day());
                        
                        // Validate that the record type of the order will be "Emergency" and the status in progress
                        if ((reg.RecordtypeId == RecordTypeId_id) && (reg.ONTAP__OrderStatus__c == System.label.ISSM_OrderStatusInProgress)) {
             
                            if (date_dt == date.today()) {
                                    result_bln = ISSM_WS_CancelaPedidos_helper.UpdateStatusOrder(Orders_lst,'El pedido de emergencia fue cancelado con éxito.',System.label.ISSM_Canceled);
                                if (result_bln == true) {
                                    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, System.Label.ISSM_SuccessfulSAPOrder));
                            
                                }


The sentence that I have in the test class is as follows.

Id stExam = Schema.getGlobalDescribe().get('ONTAP__Order__c').getDescribe().getRecordTypeInfosByDeveloperName().get('Emergency').getRecordTypeId();
        RecordType_lst = [SELECT Id, Name FROM RecordType WHERE DeveloperName = 'Emergency' LIMIT 1];
        for (RecordType rt : RecordType_lst) { RT_Emergency_id = rt.Id; 
                                              ONTAP__Order__c orderEmergency = new ONTAP__Order__c();
Good day.

I would like to know if it is possible in any way, to clone the Address field (mailAddress) since in my page format I occupy it 2 times. I understand that being a standard field, it is not possible to create a custom field but I wanted to see the possibility of doing it by code.


Best regards
I have an approval process in Oportunities object, that requires to be approved by the user configured in accounts (look up field ), which would come to be the Comersial Manager. this manager may be different for each account record.

Is there some way to put that user in fine as approver.
 repeat .. I can not put an espesific user in the process builder because the manager can be variable with each account and I can not put it in a queue, because the Aproval Process has to be aprove by Comersial Mnager.


I have tried to do it by configuration but I do not see how to do it, the way I see more possible to do is with a formula that obtains that field (user) and place it in opportunities, but I do not know how to assign it as approver.

I have no idea how to do it by code so I contact you mainly to see if it is possible to do this by code.

User-added image

Best regards
Hello everyone.
I have a button on campaigns, which is responsible for activating a campaign and create a case , this is done based on some criteria (if there are members in the campaign , if the campaign is on the status: planned, once created send a message users added in the campaign etc ... ) , it works, the problem is that it takes too long to run and the user click on the button many times because the user thinks that the system does nothing and pressed several times, this which brings accordingly, duplication of cases. I would appreciate if I could help make the user as first press this button , it will lock or hide or something to prevent duplicate cases are created. I leave below the code underliner that I made. part is the code I wanted to add to the button will lock .

Beforehand thank you very much.

{!requireScript("/soap/ajax/33.0/connection.js")} 
{!requireScript("/soap/ajax/33.0/apex.js")} 

var cam= '{!Campaign.Id}'; 

if('{!Campaign.Status}' == '{!$Label.NPS_CampaignPlannedStatus}'){

   if({!Campaign.CountCampaignMembers__c} > 0)
   {
            function checkForm(form)
        {

 if(!{!Campaign.Cases_Created__c}){
     
                   var s = sforce.apex.execute("NPS_Send_CampaignEmail", "activarCampana",        {cID:'{!Campaign.Id}'}); 
           top.location.reload();
        }
        
              
        else{
            alert('{!$Label.NPS_CampaignActivateError1}');
        }
         form.myButton.disabled = true;
    return true;
  }

   }
    else{
         alert('{!$Label.NPS_CampaignActivateError2}');
    }
}
else{
   alert('{!$Label.NPS_CampaignActivateError3}');
}
I have 2 record types in Accounts object, I need copy since Prospect RecordType to Accounts RecordType if boath record have the same "Sap number" (Custom field) i need to copy Attachments from Prospect to Account. in my code I get ids, Developer names and list of records but  I have no Idea how I can clone the attachments from prospect and put it in account record do you have any similar code that could helps me ? or any solution to my problem.

Apex Class:

public class Set_attachments {
public static void TESTMETOD(list<Account>Accountlist){
    //obtener lista de  prospectos
    List<Account>Accountlistprospect=new List<Account>();
    //obtener lista de cuentas
    List<Account>Accountlistaccount=new List<Account>();
    //obtener Id de las cuentas 
    Set<id>AccountlistId=new Set<id>();
    //obtener numero de sap
    Set<String>AccountlistSapnumber=new Set<String>();
    //obtener Attachments
    Map<Attachment,id> MapaaccAttachment = new Map<Attachment, id>();
    // hace el recuento de cuentas 
    for(Account acc:Accountlist){
        
        //Record Type prospectos
        if((acc.RecordTypeId==Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Prospect').getRecordTypeId()) && acc.ONTAP_SAP_Number__c!=null){
            Accountlistprospect.add(acc);
            AccountlistId.add(acc.id);
            AccountlistSapnumber.add(acc.ONTAP_SAP_Number__c);
            
        }
    }
    For(Account acc:[Select id, ONTAP_SAP_Number__c from Account WHERE ONTAP_SAP_Number__c in:AccountlistSapnumber AND RecordTypeId=:Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Account').getRecordTypeId()]){
        Accountlistaccount.add(acc);
    }
    For(Attachment att:[Select id,Parentid from Attachment WHERE id in:AccountlistId]){
        MapaaccAttachment.put(att, att.ParentId);
    }
    
 
        
    }
    
}

    

        
     
I'm trying to clone attachments from a Record Type to another.
I have 2 record types (Prospects and accounts) these types of records belong to the account object. what is sought is that if a record of the record type Prospects has the same number of sap as a record with the record type accounts. Clone the attachments that are in the prospect register and paste them into the account register.  It needs to be a Apex class because I run this class sinze ();

public class Set_SapId {
public static void CloneAttachments{
    List<Accout>GetAccountId =[SELECT ONTAP__SAP_Number__c From Account WHERE RecordType.DeveloperName ='Account'];

    System.debug(GetAccountId);

    List<Accout>GetProspectId =[SELECT ONTAP__SAP_Number__c From Account WHERE RecordType.DeveloperName ='Prospect'];
    System.debug(GetProspectId);

    if(GetProspectId.ONTAP__SAP_Number__c= GetAccountId.ONTAP__SAP_Number__c){

Attachment fileAttachment = [SELECT SELECT Id,
                              Body,
                              Name,
                              Description,
                              ParentId
                              FROM Attachment
                              WHERE Id=:attachmentId] 


  Attachment newFile = fileAttachment.clone();
   // newFile.ParentId = paramParentId;
    //insert newFile;
    }
}


}

So far I have this code but I can not think of ideas to paste the cloned atachments in the account register. If someone could support me with that, I would appreciate it