• Trif Cristian 7
  • NEWBIE
  • 79 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 24
    Questions
  • 30
    Replies

Hello, I'm trying to convert my trigger to a batch class. Can anyone help me with this one, I would much appreciate:

 

trigger SetTitleToAttachment on Attachment (before insert) { 
//store the id of the WO related to the attachment
 List<String> woIDs= new List<String>();
    for (Attachment  orderRec : Trigger.new) {
        woIDs.add(orderRec.ParentID);
    }
System.Debug('>>>>'+woIDs);

//store the work order(s) where the ID in woIDs
Map<String, SVMXC__Service_Order__c > woByIds= new Map<String, SVMXC__Service_Order__c >([
        SELECT Id, Name, SVMX_PS_Ship_To_Name__c, SVMXC__Order_Type__c, SerialNumberIP__c
        FROM SVMXC__Service_Order__c 
        WHERE Id =: woIDs
    ]);
  
//change the name of the attachment
 System.debug('woByIds'+ woByIds);
        for(Attachment a: Trigger.new){
           SVMXC__Service_Order__c workorder = woByIds.get(a.ParentId);
            System.debug('workorder '+ workorder );
                if(workorder != null){
                    if(a.Name.startsWith('SIG_Work_Order_Service__Reports')){
                        a.Name =  'SR'+ '_'+  date.today().format()+ '_'+workorder.SVMX_PS_Ship_To_Name__c+ '_' + workorder.Name+ '_'+ workorder.SVMXC__Order_Type__c+'_'+ workorder.SerialNumberIP__c +'.pdf';
                    }
                    else if (a.Name.startsWith('SIG_HandoverCheckList_Customer_To_SIG_Report')){
                        a.Name = 'Handover Customer To SIG' +'.pdf';
                    } 
                    else if (a.Name.startsWith('SIG_HandoverCheckList_SIG_To_Customer')){ 
                        a.Name = 'Handover SIG_To_Customer'+'.pdf';
                    }
                    else if (a.Name.startsWith('SIG_Work_Order_Service')){ 
                        a.Name = 'SR'+ '_'+  date.today().format()+ '_'+workorder.SVMX_PS_Ship_To_Name__c+ '_' + workorder.Name+ '_'+ workorder.SVMXC__Order_Type__c+'_'+ workorder.SerialNumberIP__c+'.pdf' ;
                    }
                }
             
         } 

}

i want to set my field isActive to true:

User-added image
but if i try to debug this, i get two records:

 

User-added image

 

Hi all,

i'm trying to figure it out what I'm doing wrong here, when I'm looking for my Debog Logs I see this error:

User-added imageUser-added imageand my part of code where is the error.

Can anyone help me with this error?

Hi all,

I'm trying to create a validation rule via trigger when two multiselect picklist values are the same then the validation to fire.

trigger differentValues on User (before insert) {

    for(User u : Trigger.New) {
        if(u.Restrict_access_by_Country__c =='DE' && u.TestMultiSelectCountry__c== 'DE' ) {
        u.addError('Values cannot be the same');
    }
    }
}

This trigger it's not firing.. I'm confused why not?

Hi,

I have a multiselect picklist on my User Record called CountryAccess. User can select multiple countries in this field like: TH, BR. I also have another custom field called Country on my Account object which is a picklist field with all the countries. 

Now what I want is to create another formula field to check if the values from the Country contain the value from the CountryAccessand if yes, return TRUE otherwise FALSE.

Let's say for example a user X has 2 values TH and BR on CountryAccess field.  Now if I go to an account and the country is either TH or BR than display TRUE otherwise false.

 

Any ideas please? I manage to create a formula field but based on a picklist, with one value not multiselect...

Hi, I wrote a batch class to send email notification to users from Queue. 
This is my class:

 

global class sendEmailBatchClass implements Database.Batchable < sobject > {
   
    global Database.QueryLocator start(Database.BatchableContext bc) {
        Date dt = date.today().addDays(1);
        System.debug('scope ' + dt);
        return Database.getquerylocator([SELECT Id,OwnerId,Name,Owner.Email,
        (Select Id,OwnerId,Name,Owner.Email from SVMXC__Work_Orders__r where SIG_Due_Date__c =:dt and SVMXC__Order_Status__c NOT IN ('Closed','Completed')),
        (Select Id,OwnerId,Name,Owner.Email from Administrative_Tasks__r where SIG_Due_Date__c =:dt and SIG_Status__c Not IN ('Closed','Completed')) 
        From SVMXC__Service_Request__c  WHERE SVMXC__Status__c = 'Open' and SVMX_SIG_Due_Date__c  =: dt]);
    }
    
    global void execute(Database.BatchableContext bc, List <SVMXC__Service_Request__c> scope) {
       System.debug('scope ' + scope); 
        String userStringVal = '005';
        List<SVMXC__Service_Order__c> emailUsers = new List<SVMXC__Service_Order__c>();
        Map<Id,set<SVMXC__Service_Request__c>> srMap = new Map<Id, set<SVMXC__Service_Request__c>>();
        System.debug('#####srMap ' + srMap);
        Map<Id, Set<SVMXC__Service_Order__c>> woMap = new Map<Id, Set<SVMXC__Service_order__c>>();
        System.debug('#####woMap ' + woMap);
        Map<Id, Set<SIG_Administrative_Task__c>> atMap = new Map<Id, Set<SIG_Administrative_Task__c>>();
        System.debug('#####atMap ' + atMap);
        Map<String, set<SVMXC__Service_Request__c>> userSRMap = new Map< String, set<SVMXC__Service_Request__c>>();
        System.debug('#####userSRMap ' + userSRMap);
        Map<String, set<SVMXC__Service_Order__c>> userWoMap = new Map< String, set<SVMXC__Service_Order__c>>();
        System.debug('#####userWoMap ' + userWoMap);
        Map<String, set<SIG_Administrative_Task__c>> userATMap = new Map< String, set<SIG_Administrative_Task__c>>();
        System.debug('#####userATMap ' + userATMap);
        OrgWideEmailAddress[] owea = [select Id,DisplayName,Address from OrgWideEmailAddress where DisplayName = 'SIG OrgWideAddress'];

        For(SVMXC__Service_Request__c srVal:scope){
            If(string.valueOf(srVal.OwnerId).startsWith(userStringVal)){
                if(!userSRMap.containsKey(srVal.Owner.Email)){
                userSRMap.put(srVal.Owner.Email,new set<SVMXC__Service_Request__c>{srVal} );
                }else
                {
                   userSRMap.get(srVal.Owner.Email).add(srVal);
                   system.debug('**userSRMap'+userSRMap);
                }                   system.debug('**userSRMap'+userSRMap);

            }
            else{
                if(!srMap.containsKey(srVal.OwnerId)){
                    srMap.put(srVal.OwnerId,new set<SVMXC__Service_Request__c>{srVal} );
                }else
                {
                   srMap.get(srVal.OwnerId).add(srVal);
                   system.debug('***srMap'+srMap);
                }                   system.debug('**userSRMap'+userSRMap);

            }
            
            For(SVMXC__Service_Order__c woVal :srVal.SVMXC__Work_Orders__r){
                If(string.valueOf(srVal.OwnerId).startsWith(userStringVal)){
                if(!userWoMap.containsKey(woVal.Owner.Email)){
                userWoMap.put(woVal.Owner.Email,new set<SVMXC__Service_Order__c>{woVal} );
                }else
                {
                   userWoMap.get(woVal.Owner.Email).add(woVal);
                }
            }
            else{
                if(!woMap.containsKey(woVal.OwnerId)){
                    woMap.put(woVal.OwnerId,new set<SVMXC__Service_Order__c>{woVal} );
                }else
                {
                   woMap.get(woVal.OwnerId).add(woVal);
                }
            }
            }
            
            For(SIG_Administrative_Task__c atVal :srVal.Administrative_Tasks__r){
                If(string.valueOf(atVal.OwnerId).startsWith(userStringVal)){
                if(!userATMap.containsKey(atVal.Owner.Email)){
                userATMap.put(atVal.Owner.Email,new set<SIG_Administrative_Task__c>{atVal} );
                }else
                {
                   userATMap.get(atVal.Owner.Email).add(atVal);
                }
            }
            else{
                if(!atMap.containsKey(atVal.OwnerId)){
                    atMap.put(atVal.OwnerId,new set<SIG_Administrative_Task__c>{atVal} );
                }else
                {
                   atMap.get(atVal.OwnerId).add(atVal);
                }
            }
            }
         }
         /***  Group Member Extracting ***/
         
         Set<Id> groupIds = new Set<Id>();
         groupIds.addAll(srMap.keyset());
         groupIds.addAll(woMap.keyset());
         groupIds.addAll(atMap.keyset());
         Map<Id,Set<user>> GpMap = new Map<Id,Set<User>>();
         
         Map<Id,User> userVal = new Map<Id,User>([SELECT User.Id, User.Email FROM User WHERE Id IN 
                                                (SELECT UserOrGroupId FROM GroupMember WHERE GroupId in : groupIds)]);
         
         
         For(GroupMember gm :[Select groupId, UserOrGroupId From GroupMember where groupId IN : groupIds]){
             if(GpMap.containsKey(gm.groupId)){
                 GpMap.get(gm.groupId).add(userVal.get(gm.UserOrGroupId));
             }else{
                 GpMap.put(gm.groupId,new set<User>{userVal.get(gm.UserOrGroupId)});
             }
         }
         // Extracting group member from Service Request
         
         If(!GpMap.isEmpty() && !srMap.isEmpty()){
         For(Id gVal : GpMap.keyset()){
              For(User usVal : GpMap.get(gVal)){
                if(!userSRMap.containsKey(usVal.Email)){
                userSRMap.put(usVal.Email,new set<SVMXC__Service_Request__c>(srMap.get(gVal)));
                }
                else
                {
                   userSRMap.get(usVal.Email).addAll(srMap.get(gVal));
                }
              }
         }
         }
        
         
          // Extracting group member from Work Order
          
         If(!GpMap.isEmpty() && !woMap.isEmpty()){
         For(Id gVal : GpMap.keyset()){
              For(User usVal : GpMap.get(gVal)){
                 if(!userWoMap.containsKey(usVal.Email)){
                 userWoMap.put(usVal.Email,new set<SVMXC__Service_Order__c>(woMap.get(gVal)));
                }
                else
                {
                   userWoMap.get(usVal.Email).addAll(woMap.get(gVal));
                }
              }
         }
         }
          // Extracting group member from Service Request
          
          If(!GpMap.isEmpty() && !atMap.isEmpty()){
         For(Id gVal : GpMap.keyset()){
              For(User usVal : GpMap.get(gVal)){
                  
                if(!userSRMap.containsKey(usVal.Email)){
                userATMap.put(usVal.Email,new set<SIG_Administrative_Task__c>(atMap.get(gVal)));
                }
                else
                {
                   userATMap.get(usVal.Email).addAll(atMap.get(gVal));
                }
              }
         }
         }
         
         // Sending Email for Service Request
          For(String userval1: userSRMap.keyset()){
           For(SVMXC__Service_Request__c srlistval: userSRMap.get(userval1)){
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

                Id templateId =  [select id, name from EmailTemplate where developername = 'SIG_Service_Request_Escalation_Email'].id;
                // Create Contact
                    Contact con;
                    con = new Contact();
                    con.FirstName = 'Test';
                    con.LastName = 'Contact';
                    con.Email = 'no-reply@organization.com';
                    insert con;
                    email.setTargetObjectId(con.Id);
               // email.setTargetObjectId(srlistval.ownerId);
               String[] toAddresses ;
                    
              // I have hardcoded my Id for testing , please update the logic to add the respective email addresses.
                toAddresses   = new String[] {'vivek.agrawal@servicemax.com'};
                
                email.setOrgWideEmailAddressId(owea[0].Id);
                email.setCcAddresses(toAddresses);

                email.setWhatId(srlistval.Id);
                email.setTemplateId(templateId);
                email.setSaveAsActivity(false);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
                                   system.debug('***email Message'+email);

            }
          }
          
          // Sending Email For Work Order
    
          For(String userval1: userWoMap.keyset()){
           For(SVMXC__Service_Order__c woListVal: userWoMap.get(userval1)){
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                Id templateId =  [select id, name from EmailTemplate where developername = 'SIG_Work_Order_Escalation_Email'].id;
                //email.setTargetObjectId(woListVal.ownerId);
                // Create Contact
                    Contact con;
                    con = new Contact();
                    con.FirstName = 'Test';
                    con.LastName = 'Contact';
                    con.Email = 'no-reply@organization.com';
                    insert con;
                    email.setTargetObjectId(con.Id);
                String[] toAddresses ;
  
              // I have hardcoded my Id for testing , please update the logic to add the respective email addresses.
              //  toAddresses   = new String[] {'vivek.agrawal@servicemax.com'};
                 toAddresses = new String [] {};
                for (String emaill : emailUsers.SIG_Queue_Members_Email_Address__c.split(',')) {
                                    String trimmed = email.trim();
                                    if (trimmed.length() > 0) {
                                     
                                     toAddresses.add(trimmed);
                                    }
                                  
                             }
                       
                             
                email.setOrgWideEmailAddressId(owea[0].Id);
                email.setCcAddresses(toAddresses);

                email.setWhatId(woListVal.Id);
                email.setTemplateId(templateId);
                email.setSaveAsActivity(false);
               Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
            }
          }
          
          // Sending Email For Admin  Task
           For(String userval1: userATMap.keyset()){
           For(SIG_Administrative_Task__c adListVal: userATMap.get(userval1)){
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                Id templateId =  [select id, name from EmailTemplate where developername = 'SIG_Service_Request_Escalation_Email'].id;
                // Create Contact
                    Contact con;
                    con = new Contact();
                    con.FirstName = 'Test';
                    con.LastName = 'Contact';
                    con.Email = 'no-reply@organization.com';
                    insert con;
                    email.setTargetObjectId(con.Id);
               // email.setTargetObjectId(adListVal.ownerId);
               
               String[] toAddresses ;

              // I have hardcoded my Id for testing , please update the logic to add the respective email addresses.
                toAddresses   = new String[] {'vivek.agrawal@servicemax.com'};
                
                email.setOrgWideEmailAddressId(owea[0].Id);
                email.setCcAddresses(toAddresses);

                email.setWhatId(adListVal.Id);
                email.setTemplateId(templateId);
                email.setSaveAsActivity(false);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
            }
          }
          
          
          
    }
    
    global void finish(database.BatchableContext bc) {
        
    }
}


I'm trying to loop through each user from the Queue but i'm not sure how to do it...Also I have this error, I think from here I can solve my problem
User-added image

I want to remove from my regex all content for my attributes. Below I have my regular expression and I want to happen is to, for example, I have this: style=" padding:0cm 0cm 0cm 0cm" this is an HTML attribute and I want to remove what's inside the "" which is the content. So from style="padding:0cm 0cm 0cm 0cm" I want to be only style=""; and also from
style="font-family:&quot;Open Sans&quot;,sans serif;color:#444444" to be only style=""....Can I remove my attribute content with regexp?

regexpStart = '(?<=Name:<o:p></o:p></span></p>###LB###</td>###LB###<td 
   style="padding:0cm 0cm 0cm 0cm">###LB##';
regexpStart += '#<p class="MsoNormal" style="line-height:18.0pt;mso-line- 
       height-rule:exactly"><span style="fon';
regexpStart += 't-family:&quot;Open Sans&quot;,sans serif;color:#444444">)'; 
regexpEnd = '(?=<o:p>)';
regexp = regexpStart + '.*?' + regexpEnd;

Hi, I have a very basic question.. But I don't know whats happening in this method, I know its an embarrassing question.

public String conversionPageDescription {
        get {
            return Label.CONTACT_CONV_MSG_TEXT_DESCRIPTION.replace('{1}', pageForm.contact.FirstName + ' ' + pageForm.contact.LastName);
        }
    }

Hi, I have the following text:

    String target = '<br><br>I love computers and I love to program. <br>Do you love to program? <br><br>Or not?';
I want to replace all the `<br>`with the new line `\n`.

So I used this function:

    target = target.replaceAll('<br>', '\n');  but I have this error: Error on line 38, column 1: System.StringException: No match found. And if I try to replace with another string for example:

    target = target.replaceAll('<br>', 'test');   It works like a charm...

Here it's the full code for this:
 
String target = '<br><br>I love computers and I love to program. <br>Do you love to program? <br><br>Or not?';
    
    target = target.replaceAll('<br>', '\n');
    
    String regExp = '(.*)';
    Pattern myPattern = Pattern.compile(regExp);
    Matcher myMatcher = myPattern.matcher(target);
    
    System.debug('Matches: ' + myMatcher.matches());
    System.debug('Group 0: ' + myMatcher.group(1));

 

Hello, I have to extract the message from an HTML file... I managed to extract the message but I have the <br> in message in it looks ugly because after i extract the message from HTML file i want to map this to my description field, into Leads. So my message is this:

Goedendag,
<br>
<br>
Ik ben geïnteresseerd in uw BMW 5-Serie met kenteken 5-TFR-74. <br>
Wilt u contact met mij opnemen? <br>
<br>
Met vriendelijke groet,

And i want to remove the <br> and replace it with the new line break which is \n.

Okay, I tried to replace by using replaceAll function from String class and it looks like this:

target.replaceAll('<br>', '\n');
But I have an error.. are there any methods to solve this problem?

Hello, I'm very new to Salesforce Development and I am struggling to figure this out. So i want to create 2 VF pages and 2 controllers and I want to create new account and insert that account when I'm pressing the Save button, then i want to redirect to second visualforce page and on the second visualforce page i want to fetch the id from the account which is just created and outputfield the value, the name of account. I just started creating the first visualforce page and controller. I dont know if i'm doing this right.

apex:page controller="screen1">
   <apex:form>
       <apex:pageBlock>
           <apex:pageBlockSection>
               <apex:inputField value="{!account.name}"/>
               <apex:commandButton value="Save" action="{!save}"/>
           </apex:pageBlockSection>
       </apex:pageBlock>
   </apex:form>
</apex:page>


Controller:

public class screen1 
{
  
    public Account account;

    public Account getAccount()
    {
      if(account == null)
      {
         account = new account();
      }
      return account;
    }

     public PageReference save()
     {
       getAccount();
       if(account != null)
       {
           insert account;
       }
       PageReference pageRef = new PageReference('/apex/screen2');
       pageRef.setRedirect(true);
       return PageReference;
     }
}
I have an error here: Error: Compile Error: DML requires SObject or SObject list type: Account at line 20 column 12

Hello guys, I want to make a Visualforce page and in that visualforce page i want to make a button, called "Trimite Facturi" and when i press that button I want to display a message "Email was sent out successfully ". I was wondering what is the easiest way to make to accomplish this.

I created my VF page and now when i press that button i want to display a message "Email was sent out successfully", in the right of that button and  when the message shows up i don't want for whole page to load.User-added image 
static void testUpdate() {
    User userStandard = TestUtil.getUserStandardDE(0);
    System.runAs(userStandard) {
        Account accountBusiness= [Select Id from Account where Name = :TestUtil.ACCOUNT_BUSINESS_NAME LIMIT 1];
        Account accountBusinessDuplicate= [Select Id from Account where Name = 'DuplicateCompany' LIMIT 1];

        AccountDuplicate__c ad = new AccountDuplicate__c();
        ad.Account1__c = accountBusiness.Id;
        ad.Account2__c = accountBusinessDuplicate.Id;
        ad.Status__c = 'Open';
        ad.Criteria__c ='Other matches';

        Test.startTest();
        insert ad;


        ad.Remarks__c = 'changed';
        update ad;


        ad.Status__c = 'Rejected';
        update ad;


        ad.Status__c = 'Open';
        update ad;


        Test.stopTest();
    }
}

Hello,

Today I am in this topic about testing in Salesforce and I study all day about this so what I understand is:

1. These methods exists primarily to allow you to reset the governor limits within the context of your execution
2. These 2 methods cannot be called more than once within a method
3. These methods use it's own governor limit
4. Before calling startTest, you should create all the information required for the test.

So in theory, I would say i understand, BUT.. in practical, I really need a simple example and explained on why & when to use these methods?

So the following task is this:

User-added image

And I have the following class in which I have to write my Test.StartTest() and Test.StopTest(). I don't know how to connect the dots, I really don't know how these methods Test.StartTest() and Test.StopTest() works, as I'm new to Salesforce.

@isTest 
public with sharing class AccountDealerSignSelectControllerTest {
    
    @testSetup 
    private static void setupTestData() {
        
        TestUtil.insertBaseData(1);
        
        User userStandard = TestUtil.getUserStandardDE(0);
        
        System.runAs(userStandard) {
            Account dealerAccount = new Account(    Name                            = 'Dealer Test', 
                                                    RecordTypeId                    = SystemUtil.getRecordTypes(Account.SObjectType).get(Label.RECORDTYPE_ACCOUNT_ACCOUNTBUSINESSINTERNAL_DEVNAME).getRecordTypeId(), 
                                                    SourceSystem__c                    = Label.GLOBAL_PICKLIST_SOURCESYSTEM_RSPCRM_VALUE, 
                                                    CustomerMainType__c                = Label.ACCOUNT_PICKLIST_CUSTOMER_MAINTYPE_DEALER_VALUE, 
                                                    CustomerType__c                    = Label.ACCOUNT_PICKLIST_CUSTOMERTYPE_SPECIAL_VALUE, 
                                                    CustomerSubType__c                = Label.ACCOUNT_PICKLIST_CUSTOMER_SUBTYPE_OTHER_VALUE,
                                                    BusinessAddressCountry__c       = 'DE',
                                                    BusinessAddressPostalCode__c    = '10000',
                                                    BusinessAddressCity__c          = 'TestCity',
                                                    BusinessAddressStreet__c        = 'TestStreet',
                                                    BusinessAddressStreetNumber__c  = '1');
            insert dealerAccount;
        }
    }
    
    static testMethod void signatureSelection1Test() {
        
        User userStandard = TestUtil.getUserStandardDE(0);
        
        System.runAs(userStandard) {
            
            Account dealerAccount = [SELECT Id FROM Account WHERE Name = 'Dealer Test'];
            
            if (!UserUtil.IsDisabledTestClassesAssert) {
                
                system.assertNotEquals(null, dealerAccount);
            }
            Attachment att = new Attachment(Name='Test Att', ParentId=dealerAccount.Id, Body=Blob.valueOf('Test Body String') );
            insert att;
            
            ApexPages.CurrentPage().getParameters().put('id', dealerAccount.Id);
            AccountDealerSignatureSelectController controller = new AccountDealerSignatureSelectController();
            
            if (!UserUtil.IsDisabledTestClassesAssert) {
                
                system.assertNotEquals(null, controller);
            }
            controller.isSignature1 = true;
            controller.selectedAttachmentId = att.Id;

            controller.selectSignature();
            Account dealerAccountFromDB = [SELECT SignatureAuthorization1__c FROM Account WHERE Id = :dealerAccount.Id];
            
            if (!UserUtil.IsDisabledTestClassesAssert) {
                
                system.assertEquals(att.Id, controller.selectedAttachmentId, dealerAccountFromDB.SignatureAuthorization1__c);
                system.assertEquals(controller.currentSignatureId, dealerAccountFromDB.SignatureAuthorization1__c);
            }
            controller.deselectSignature();
            dealerAccountFromDB = [SELECT SignatureAuthorization1__c FROM Account WHERE Id = :dealerAccount.Id];
            
            if (!UserUtil.IsDisabledTestClassesAssert) {
                
                system.assertEquals(null, dealerAccountFromDB.SignatureAuthorization1__c);
            }
        }
    }
    
    static testMethod void signatureSelection2Test() {
        
        User userStandard = TestUtil.getUserStandardDE(0);
        
        System.runAs(userStandard) {
            
            Account dealerAccount = [SELECT Id FROM Account WHERE Name = 'Dealer Test'];
            
            if (!UserUtil.IsDisabledTestClassesAssert) {
                
                system.assertNotEquals(null, dealerAccount);
            }
            Attachment att = new Attachment(Name='Test Att', ParentId=dealerAccount.Id, Body=Blob.valueOf('Test Body String') );
            insert att;
            
            ApexPages.CurrentPage().getParameters().put('id', dealerAccount.Id);
            AccountDealerSignatureSelectController controller = new AccountDealerSignatureSelectController();
            
            if (!UserUtil.IsDisabledTestClassesAssert) {
                
                system.assertNotEquals(null, controller);
            }
            controller.isSignature1 = false;
            controller.selectedAttachmentId = att.Id;

            controller.selectSignature();
            Account dealerAccountFromDB = [SELECT SignatureAuthorization2__c FROM Account WHERE Id = :dealerAccount.Id];
            
            if (!UserUtil.IsDisabledTestClassesAssert) {
                
                system.assertEquals(att.Id, controller.selectedAttachmentId, dealerAccountFromDB.SignatureAuthorization2__c);
                system.assertEquals(controller.currentSignatureId, dealerAccountFromDB.SignatureAuthorization2__c);
            
                controller.deselectSignature();
                dealerAccountFromDB = [SELECT SignatureAuthorization2__c FROM Account WHERE Id = :dealerAccount.Id];
                system.assertEquals(null, dealerAccountFromDB.SignatureAuthorization2__c);
            }
            
        }
    }
}

I'm kinda confused how this works line by line. Can someone explain it to me?

 

I have this piece of code, but I don't know how this works, line by line.

public class PassNonPrimitiveTypeExample {
               public static void createTemperatureHistory() {
                              List <Integer> fillMe = new List<Integer>();
                              reference(fillMe);
                              System.assertEquals(fillMe.size(),5);
 
                               List <Integer> createMe = new List<Integer>();
                               referenceNew(createMe);
                               System.assertEquals(createMe.size(),0);
               }
               public static void reference(List <Integer> m) {
                               m.add(70);
                               m.add(68);
                               m.add(75);
                               m.add(80);
                               m.add(82);
                }
                public static void referenceNew(List <Integer> m) {
                               m = new List{55, 59, 62, 60, 63};
               }
 }
 

Hello, i have a simple trigger:


trigger TriggerA on Account (before insert) {
    for(Account a : Trigger.new){
      if(a.Description == NULL)
         a.addError('You must add a value');
    }
}

Error: Compile Error: Variable does not exist: Description at line 3 column 12. I don't understand why.
Hello,  
We want to integrate Salesforce with a  Service, for example I want to create some Accounts and some fields from those Accounts we want to be able to transmit those Accounts to a Service and vice versa. I am a newbie to this, i never done integration and all this integration is gonna be in Java language. So the question is how can we make this, what are the best ways to make this, and from where can I read more about integration to a Service ?
So i have 2 custom Objects. Object_C1, Object_C2. How can i make a trigger when i create a record on Object_C2 automatically after insert make a record on Object_C1 ? How can i relate these 2 objects through what ?

 
Hello, im a newbie and i need some help. I have the next logic in my apex class, i just copied from internet so i dont know exactly whats happening, im not convinced. So, here it is:

Account a =[SELECT name, phone, fax, industry where name = 'Dell'];
if(a.Industry != 'Industry')
a.Industry = 'Industry';
update a;

So basically it saying that fetch name, phone, fax, industry from an existing account with the name Dell. And here on if im confused. If industry field not equal to industry then update that field to industry? Did i say wrong? On if then else statement why we dont have curly brackets? and where is the else statement?

Hello, I'm trying to convert my trigger to a batch class. Can anyone help me with this one, I would much appreciate:

 

trigger SetTitleToAttachment on Attachment (before insert) { 
//store the id of the WO related to the attachment
 List<String> woIDs= new List<String>();
    for (Attachment  orderRec : Trigger.new) {
        woIDs.add(orderRec.ParentID);
    }
System.Debug('>>>>'+woIDs);

//store the work order(s) where the ID in woIDs
Map<String, SVMXC__Service_Order__c > woByIds= new Map<String, SVMXC__Service_Order__c >([
        SELECT Id, Name, SVMX_PS_Ship_To_Name__c, SVMXC__Order_Type__c, SerialNumberIP__c
        FROM SVMXC__Service_Order__c 
        WHERE Id =: woIDs
    ]);
  
//change the name of the attachment
 System.debug('woByIds'+ woByIds);
        for(Attachment a: Trigger.new){
           SVMXC__Service_Order__c workorder = woByIds.get(a.ParentId);
            System.debug('workorder '+ workorder );
                if(workorder != null){
                    if(a.Name.startsWith('SIG_Work_Order_Service__Reports')){
                        a.Name =  'SR'+ '_'+  date.today().format()+ '_'+workorder.SVMX_PS_Ship_To_Name__c+ '_' + workorder.Name+ '_'+ workorder.SVMXC__Order_Type__c+'_'+ workorder.SerialNumberIP__c +'.pdf';
                    }
                    else if (a.Name.startsWith('SIG_HandoverCheckList_Customer_To_SIG_Report')){
                        a.Name = 'Handover Customer To SIG' +'.pdf';
                    } 
                    else if (a.Name.startsWith('SIG_HandoverCheckList_SIG_To_Customer')){ 
                        a.Name = 'Handover SIG_To_Customer'+'.pdf';
                    }
                    else if (a.Name.startsWith('SIG_Work_Order_Service')){ 
                        a.Name = 'SR'+ '_'+  date.today().format()+ '_'+workorder.SVMX_PS_Ship_To_Name__c+ '_' + workorder.Name+ '_'+ workorder.SVMXC__Order_Type__c+'_'+ workorder.SerialNumberIP__c+'.pdf' ;
                    }
                }
             
         } 

}

i want to set my field isActive to true:

User-added image
but if i try to debug this, i get two records:

 

User-added image

 

Hi all,

i'm trying to figure it out what I'm doing wrong here, when I'm looking for my Debog Logs I see this error:

User-added imageUser-added imageand my part of code where is the error.

Can anyone help me with this error?

Hi all,

I'm trying to create a validation rule via trigger when two multiselect picklist values are the same then the validation to fire.

trigger differentValues on User (before insert) {

    for(User u : Trigger.New) {
        if(u.Restrict_access_by_Country__c =='DE' && u.TestMultiSelectCountry__c== 'DE' ) {
        u.addError('Values cannot be the same');
    }
    }
}

This trigger it's not firing.. I'm confused why not?

Hi, I have a very basic question.. But I don't know whats happening in this method, I know its an embarrassing question.

public String conversionPageDescription {
        get {
            return Label.CONTACT_CONV_MSG_TEXT_DESCRIPTION.replace('{1}', pageForm.contact.FirstName + ' ' + pageForm.contact.LastName);
        }
    }

Hi, I have the following text:

    String target = '<br><br>I love computers and I love to program. <br>Do you love to program? <br><br>Or not?';
I want to replace all the `<br>`with the new line `\n`.

So I used this function:

    target = target.replaceAll('<br>', '\n');  but I have this error: Error on line 38, column 1: System.StringException: No match found. And if I try to replace with another string for example:

    target = target.replaceAll('<br>', 'test');   It works like a charm...

Here it's the full code for this:
 
String target = '<br><br>I love computers and I love to program. <br>Do you love to program? <br><br>Or not?';
    
    target = target.replaceAll('<br>', '\n');
    
    String regExp = '(.*)';
    Pattern myPattern = Pattern.compile(regExp);
    Matcher myMatcher = myPattern.matcher(target);
    
    System.debug('Matches: ' + myMatcher.matches());
    System.debug('Group 0: ' + myMatcher.group(1));

 

Hello, I'm very new to Salesforce Development and I am struggling to figure this out. So i want to create 2 VF pages and 2 controllers and I want to create new account and insert that account when I'm pressing the Save button, then i want to redirect to second visualforce page and on the second visualforce page i want to fetch the id from the account which is just created and outputfield the value, the name of account. I just started creating the first visualforce page and controller. I dont know if i'm doing this right.

apex:page controller="screen1">
   <apex:form>
       <apex:pageBlock>
           <apex:pageBlockSection>
               <apex:inputField value="{!account.name}"/>
               <apex:commandButton value="Save" action="{!save}"/>
           </apex:pageBlockSection>
       </apex:pageBlock>
   </apex:form>
</apex:page>


Controller:

public class screen1 
{
  
    public Account account;

    public Account getAccount()
    {
      if(account == null)
      {
         account = new account();
      }
      return account;
    }

     public PageReference save()
     {
       getAccount();
       if(account != null)
       {
           insert account;
       }
       PageReference pageRef = new PageReference('/apex/screen2');
       pageRef.setRedirect(true);
       return PageReference;
     }
}
I have an error here: Error: Compile Error: DML requires SObject or SObject list type: Account at line 20 column 12