• Sam Ingra
  • NEWBIE
  • 60 Points
  • Member since 2022

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

Hi,
i inserted this condition inside my apex code : 

if(con.DataDocumentoDiVendita__c > soglia.startDate__c && con.DataDocumentoDiVendita__c < soglia.endDate__c  && con.NuovoAziendaleUsato__c.equals('NUOVO')){
                
                con.SogliaSconto__c = soglia.SogliaSconto__c;
                
            }

However, I would like to add the exception if endDate__c should be null.

at this time if endDate__c is null would it go into error? 

Hi, I should develop a batch apex for account merge. 
the merge will be performed if :
1 ) the email will be the same.
2) the phone number will be the same
3) the first name + last name + date of birth will be equal.

this is my written code , but i think it is not the best solution:
 
global class BatchMergeAccount implements Database.Batchable<sobject> {
    
    global  Database.QueryLocator start(Database.BatchableContext ctx) {
        List<String> lastModify = New List<String>{'Bruno Simone','Automated Process','Admin Atlantic'};
           String type = 'Customer';
        List<String> listCampus = new List<String>{'Milano Fashion And Design', 'Milano Fashion', 'Milano Design', 'London', 'Paris', 'Miami', 'Dubai','Firenze'};
        
       String query = 'SELECT Id, FirstName, LastName, PersonEmail, Phone, PersonBirthdate FROM Account WHERE LastModifiedBy IN : lastModify and matricola__pc = null And Is_Duplicate__pc = true And Type=type And Campus__c In :ListCampus';
            
            return Database.getQueryLocator(query);
        
    }
    
    global void execute(Database.BatchableContext BC, List<Account> scope){
        List<Account> accountDuplicateforMerge = new List<Account>();
        Map<String , Account> masterAccountMap = new Map<String , Account>();
        system.debug('scope' +scope);
        
        for(Account ac : scope){
            if(String.isNotBlank(ac.PersonEmail) && !masterAccountMap.containsKey(ac.PersonEmail)){
                  masterAccountMap.put(ac.PersonEmail, ac);
            }else if(String.isBlank(ac.PersonEmail) && String.isNotBlank(ac.Phone) && !masterAccountMap.containsKey(ac.Phone)){
                masterAccountMap.put(ac.Phone, ac);
            }else If(String.isBlank(ac.PersonEmail) && String.isBlank(ac.Phone) && !masterAccountMap.containsKey(ac.FirstName + ac.LastName + ac.PersonBirthdate)){
               masterAccountMap.put(ac.FirstName+ac.LastName+ac.PersonBirthdate, ac);
            }else {
                accountDuplicateforMerge.add(ac);
            }
            
             
        }
        system.debug('masterAccountMap'+masterAccountMap);
        system.debug('accountDuplicateforMerge'+accountDuplicateforMerge);
        for(Account accc : masterAccountMap.values()){
            Account master = accc;
        for (Account a :accountDuplicateforMerge){
            if(String.isNotBlank(accc.Sinapto_ID__pc) && String.isNotBlank(a.Sinapto_ID__pc) && accountDuplicateforMerge.size()>=1){
                
                Database.merge(master, accountDuplicateforMerge);
                
            }
                
                
            
                }
        }

        
        
        
    }
    global void finish(Database.BatchableContext BC) {
        
        
        
    }

}

Thanks for any help.
 
Problems with queries within the for loop
hi, i'm new to salesforce. I'm having problems with queries within my for loop. exceeding the query limit.

My code in the batch:
 
for (Object raw : raws) {
            Map<Object, Object> rawMap = (Map<Object, Object>) raw;

            Object telaio = rawMap.get(columns.get(COLUMN_TELAIO));
            Object targa = rawMap.get(columns.get(COLUMN_TARGA));
            Id campaignId = (Id) rawMap.get(columns.get(COLUMN_CAMPAIGN_ID));
            System.debug(campaignId);


            //telaii.add(String.valueOf(telaio));


            if (telaio != null) {
                ContactIds = [SELECT Utilizzatore__c FROM Contratto__c WHERE Telaio__c = :String.valueOf(telaio)];
            } else {
                ContactIds = [SELECT Utilizzatore__c FROM Contratto__c WHERE Targa__c = :String.valueOf(targa)];
            }

            System.debug(ContactIds);

            for (Contratto__c c : ContactIds) {


                matchingCampaignMembers = [
                        SELECT Id, Status
                        FROM CampaignMember
                        WHERE ContactId = :c.Utilizzatore__c AND CampaignId = :campaignId
                ];
                System.debug('My Match List ' + matchingCampaignMembers);
                if (!matchingCampaignMembers.isEmpty()) {

                    for (CampaignMember mb : matchingCampaignMembers) {

                        mb.Status = 'To send';

                        CampaignMemberUpdates.add(mb);
                    }
                    System.debug(CampaignMemberUpdates);

                    for (SObject oh : CampaignMemberUpdates) {

                        recordsToUpdate.put(String.valueOf(oh.Id), oh);


                    }
                    System.debug(recordsToUpdate);
                }

                Map<Object, Object> rawMapClone = rawMap.clone();
                System.debug(rawMapClone);
                if (c.Utilizzatore__c != null) {
                    rawMapClone.put(COLUMN_CONTACT_ID, c.Utilizzatore__c);
                }
                rawMapClone.put(COLUMN_CAMPAIGN_ID, campaignId);
                rawMapClone.put(COLUMN_STATUS, 'To send');
                rawMapClone.remove(COLUMN_TARGA);
                rawMapClone.remove(COLUMN_TELAIO);
                rawsCampaignMember.add(rawMapClone);
                System.debug(rawsCampaignMember);
            }
        }

Hi, i' m trying to populate a <String, Sobject> map but when I try to take only the last record
My code :
 
private void matchCampaigns(Map<Integer, SObject> records, Map<String, SObject> recordsToUpdate){
        
        List<CampaignMember> matchingCampaignMembers = new List<CampaignMember>();
        List<CampaignMember> matchMember = new List<CampaignMember>();
        Set<Id> contactIds = new Set<Id>();
        Set<Id> campaignIds = new Set<Id>();
        
         List<Sobject> recordsToGet = records.values();
                        system.debug(recordsToGet);
                        for(Sobject obj : recordsToGet){
                            
                            Id IdContact = (Id)obj.get('ContactId');
                            Id IdCampaign = (Id)obj.get('CampaignId');
                            
                            contactIds.add(IdContact);
                            campaignIds.add(IdCampaign);
                            
                                                                           
                        }
        system.debug(contactIds);
                            system.debug(campaignIds);
                        
                        matchingCampaignMembers = [Select id,Status 
                 from CampaignMember 
                 where ContactId IN : contactIds and CampaignId IN : campaignIds];
        system.debug('My Match List ' +matchingCampaignMembers);
        
        for(Sobject oh : matchingCampaignMembers ){
            
             recordsToUpdate.put('Id', oh);
            
            
        }
        system.debug('recordsToUpdate ' +recordsToUpdate);
                        
        
    }

as you see from the debug there are not the three records found and inserted in the "matchingCampaignMembers" list. 
what is going wrong?
I would like all the records found to be there.

Debug
Hi, 

I'm trying to check if a campaign member has already been entered in a campaign in case affemative update the status otherwise enter the member.

This is my code, but currently it doesn't work very well:
 
List<CampaignMember> controlAlreadyInserted = [Select id,Status from CampaignMember where ContactId=:c.Id and CampaignId =:camp.Id];
        system.debug(controlAlreadyInserted);
        if(controlAlreadyInserted.size()<=0){
            
            CampaignMember cm= New CampaignMember(CampaignId=camp.Id,ContactId=c.Id,Status='To send');
        memberList.add(cm);
                 system.debug(memberList);
        
        insert memberList;
        }else{
            controlAlreadyInserted.Status='Sent';
            update controlAlreadyInserted;
        }

I would like to know if I am doing something wrong or if there is another, more efficient way. Thank for any help.
 

Hi,

I'm experiencing a problem with platform events, in this case platform events are not generated for a specific user. 

While for other users with the same profile the platform events are generated. 
I have already checked the permission set and everything is ok. maybe I'm forgetting to check something else?

ps: the user has a "system administrator" profile.

Thanks for any help

Hi, I have a classic email template I am using html. I would like to know if it would be possible to add a line of ("***") to the end of this field :  Comments history: {!Quote.CommentStorage__c}   (the field is a long area text).   Example output:  
comment number 1  
 *** 
comment number 2 
  ***

  I don't know if it was possible to implement this directly in my classic email template, Or something should be done at field level.  Thanks

 thanks for any help
 

Hi, I need to create a batch that automates the creation of Cases from a Campaign by taking only the members related to a campaign that are in 'To send' status.
(this batch should run after pressing a button in a campaign object )

Each campaign can have related different members. 

 

my draft code : 

global class CreateRicontatto implements Database.Batchable<sObject> {
    
    
    global Database.QueryLocator start (Database.BatchableContext BC){
        
        String id = '7010J000001HCkjQAG';
        String query = 'SELECT Campaign.Id, Status, Campaign.Type__c, Campaign.Subject__c, Name, Campaign.Data_Chiamata__c, Campaign.Description FROM CampaignMember WHERE Campaign.Id :=id';
         
        return Database.getQueryLocator(query);
            
    }
    global void execute(Database.BatchableContext BC, List<CampaignMember> scope){
        List<Case> ricontatto = new List<Case>();
        
        For(CampaignMember c : scope){
            
            if(c.Status == 'Invito'){
                
                Case casi = new Case();
                casi.RecordTypeId = '0120Y000000FbCuQAK';
                casi.Campaign__c = c.Campaign.Id;
                casi.Type = c.Campaign.Type__c;
                casi.Description = c.Campaign.Description;
                casi.Subject = c.Campaign.Subject__c;
                casi.DataChiamata__c = c.Campaign.Data_Chiamata__c;
                ricontatto.add(casi);
            }
            
        }
        If(ricontatto.size()>0)
            insert ricontatto;
          
    }
global void finish (Database.BatchableContext BC){
}

thank you for any help.

 

 I'm trying to create two apex methods: one that returns me the list of duplicates, the second that removes the duplicates.

Input for first method [A,B,B,C,A,D];
Output : [A,B];

Input second method [A,B,B,C,A,D]
output: [C,D];

Thanks for any kind of help.

I am new to apex salesforce programming.
I would like to create a trigger for changing the available quantity (AvaibleQuantity) in the custom product2 object, when the field (Stage) of the related proposal is changed.

The proposal object is related with configuration in one to one relationship, while the configuration_line is an auxiliary object because there is a relationship between configuration and product many to many.

Any help would be appreciated, thanks.

User-added image

Hi,
i inserted this condition inside my apex code : 

if(con.DataDocumentoDiVendita__c > soglia.startDate__c && con.DataDocumentoDiVendita__c < soglia.endDate__c  && con.NuovoAziendaleUsato__c.equals('NUOVO')){
                
                con.SogliaSconto__c = soglia.SogliaSconto__c;
                
            }

However, I would like to add the exception if endDate__c should be null.

at this time if endDate__c is null would it go into error? 

Hi, I should develop a batch apex for account merge. 
the merge will be performed if :
1 ) the email will be the same.
2) the phone number will be the same
3) the first name + last name + date of birth will be equal.

this is my written code , but i think it is not the best solution:
 
global class BatchMergeAccount implements Database.Batchable<sobject> {
    
    global  Database.QueryLocator start(Database.BatchableContext ctx) {
        List<String> lastModify = New List<String>{'Bruno Simone','Automated Process','Admin Atlantic'};
           String type = 'Customer';
        List<String> listCampus = new List<String>{'Milano Fashion And Design', 'Milano Fashion', 'Milano Design', 'London', 'Paris', 'Miami', 'Dubai','Firenze'};
        
       String query = 'SELECT Id, FirstName, LastName, PersonEmail, Phone, PersonBirthdate FROM Account WHERE LastModifiedBy IN : lastModify and matricola__pc = null And Is_Duplicate__pc = true And Type=type And Campus__c In :ListCampus';
            
            return Database.getQueryLocator(query);
        
    }
    
    global void execute(Database.BatchableContext BC, List<Account> scope){
        List<Account> accountDuplicateforMerge = new List<Account>();
        Map<String , Account> masterAccountMap = new Map<String , Account>();
        system.debug('scope' +scope);
        
        for(Account ac : scope){
            if(String.isNotBlank(ac.PersonEmail) && !masterAccountMap.containsKey(ac.PersonEmail)){
                  masterAccountMap.put(ac.PersonEmail, ac);
            }else if(String.isBlank(ac.PersonEmail) && String.isNotBlank(ac.Phone) && !masterAccountMap.containsKey(ac.Phone)){
                masterAccountMap.put(ac.Phone, ac);
            }else If(String.isBlank(ac.PersonEmail) && String.isBlank(ac.Phone) && !masterAccountMap.containsKey(ac.FirstName + ac.LastName + ac.PersonBirthdate)){
               masterAccountMap.put(ac.FirstName+ac.LastName+ac.PersonBirthdate, ac);
            }else {
                accountDuplicateforMerge.add(ac);
            }
            
             
        }
        system.debug('masterAccountMap'+masterAccountMap);
        system.debug('accountDuplicateforMerge'+accountDuplicateforMerge);
        for(Account accc : masterAccountMap.values()){
            Account master = accc;
        for (Account a :accountDuplicateforMerge){
            if(String.isNotBlank(accc.Sinapto_ID__pc) && String.isNotBlank(a.Sinapto_ID__pc) && accountDuplicateforMerge.size()>=1){
                
                Database.merge(master, accountDuplicateforMerge);
                
            }
                
                
            
                }
        }

        
        
        
    }
    global void finish(Database.BatchableContext BC) {
        
        
        
    }

}

Thanks for any help.
 
Hi, 

I'm trying to check if a campaign member has already been entered in a campaign in case affemative update the status otherwise enter the member.

This is my code, but currently it doesn't work very well:
 
List<CampaignMember> controlAlreadyInserted = [Select id,Status from CampaignMember where ContactId=:c.Id and CampaignId =:camp.Id];
        system.debug(controlAlreadyInserted);
        if(controlAlreadyInserted.size()<=0){
            
            CampaignMember cm= New CampaignMember(CampaignId=camp.Id,ContactId=c.Id,Status='To send');
        memberList.add(cm);
                 system.debug(memberList);
        
        insert memberList;
        }else{
            controlAlreadyInserted.Status='Sent';
            update controlAlreadyInserted;
        }

I would like to know if I am doing something wrong or if there is another, more efficient way. Thank for any help.
 
Hi, I have a classic email template I am using html. I would like to know if it would be possible to add a line of ("***") to the end of this field :  Comments history: {!Quote.CommentStorage__c}   (the field is a long area text).   Example output:  
comment number 1  
 *** 
comment number 2 
  ***

  I don't know if it was possible to implement this directly in my classic email template, Or something should be done at field level.  Thanks

 thanks for any help