• Linda 98
  • NEWBIE
  • 363 Points
  • Member since 2013

  • Chatter
    Feed
  • 8
    Best Answers
  • 3
    Likes Received
  • 0
    Likes Given
  • 167
    Questions
  • 258
    Replies
Having a trigger to fire when a value is changed.
On update of the field, it should consider multi-select picklist values(List of roles-As it's multi-select datatype, may have one role is chosen or multiple chosen) and use them in a query to contact(Multi-select picklist field). Further, I would like to use those contact ids to create records in another custom object.
I saved the roles on record(trigger.new) into a list. But when I try to query to contact, I am not able to get the values.

For instance,
Values on Record 1-
checkbox -checked to true(which fires trigger)
Roles- Manager; Owner; Supervisor

Contact records-
contact 1-
Roles :Manager;Supervisor
Contact 2-
Roles-Owner
Contact 3:
roles-Manager;Architect
Contact 4-
Roles-Manager
Contact 5-
Roles: Analyst;Architech

In the above example, I would like to get all the contact IDs except contact 5. I even want Contact 3 even his roles include Architect which is not in our record roles list. As he is having a manager role, I would like to collect it too.

I used 
conroles=[select id,Roles__c,Title from contact where Roles__c IN :Roleslist];
Roleslist=List of roles on Record.
But its only fetching first roles contact's.

Split(',') doesn't seem to work, What am I doing wrong?
My use case- Custom object linkedcontacts__c with Master detail relations on contact and customobject2__c objects.
Having two multi-select picklist fields on both the objects, Named as Roles.
I am having a trigger on customobject2 which fires when a field is changed, then I am trying to get those multi-select field values(roles) and check against contact roles, and link the related contacts.
My major issue is as they are multi-select values if multiple roles are chosen then how can I achieve this??

For instance, if I am having a CB2 record with roles director; manager, I should be able to query those contacts whose roles are director or manager or director and manager(if any) and should relate by inserting record in the linkedcontact__c object. 
Please guide me.Thank you.
 
Created a custom object on record detail page.VF page will search records by using query in controller.
It has a input field and holds search text.I want to have more flexibity with the search text.It is being filled with value from record field.Like name of record.But i would like to give user to change the search text if he wants and still fit in the query.Like dynamic text field.
It has to work two ways,value from standard field and also should work if user chnages the value and give new value.Please help.
 
I am changing one particular  field by checking lastmodifeddate in my code.All works fine but i am struck with test class.I am chnaging multiple records from multiple objects so my batch class looks like below.
 
global class editrecords implements Database.Batchable<string>, Schedulable{
global boolean bool = false;

global Iterable<string> start(Database.BatchableContext ctx) {
    return new list<String> { 'CO__c', 'CO2__c', 'CO3__c','CO4__c'};
}
global void execute(Database.BatchableContext ctx, list<string> listObj) {
    list<sObject> editrecords = new list<sObject>();
    for(string strObjName : listObj) {
        for(sObject objsObject : database.query('Select Id from ' + strObjName + ' where LastModifiedDate < LAST_N_DAYS:36')) {
                editrecords.add(objsObject);
            else {
                b = true;
                break;
            }
        }
    }
    update editrecords;
}
global void finish(Database.BatchableContext ctx) {

}        global void execute(SchedulableContext sc){
         Database.executebatch(new editrecords ());    
    }
}

my test class is as below which get 58% of coverage.How can i get lastmodified date and cover rest of code.please help.
 
@isTest
Public class testeditrecords{

    static testMethod void testMethod1(){

        CO__c CO =new CO__c(Name='testdata');
        insert CO;
        CO2__c co2 =new 
  co2__c(Name='testdata');
        insert co2;
        Co3__c co3 =new Co3__c(Name='test2');
        insert co3;

       for(CO__c c:[Select ID from CO__c where createddate=TODAY]){
        Test.startTest();
       
        editrecords obj = new editrecords();
        Database.executeBatch(obj);
        Test.stopTest();       
        }
   } 
}

 
I am using a Workflow field update and having IF conditions in it.
I want to trim left(6) and right(20) parts
My example is

'You can call on: 123456789 -thank you'

this is my string of which i want  only 123456789

IF(BEGINS(Info,'You can call on:  '),RIGHT(info,LEN(info) -15),
info))

This is giving me '123456789 -thank you'
I am struck with errors here.(If is not allowing me more than 3 conditions) Pointers please.
I am having a long text area field which has long information.
I am trying get one middle line,which is like this.

xxxxxxx
xxxxxxxx
xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx




salesforce office:Working hours 
XXXXXXXXXXXXXX
XXXXXXXXXXXXX
XXXXXXXXXXXXXXXX


So i want to get everything after 'salesforce office: '

output in this case= 'working hours' This is dynamic value.

and save that it another text field.I am able to get that everything after office: but its not recognizing line break.


thats were i am struck..I am having other reasons to use apex trigger.So workflow or Builder doesnt work for me.
Any help?Thanks!!


 
We are using professional org.
Having a process builder which updates a field on some condition with formula type.

this is how the formula is ,i am using & between them.

I am having datetime field which is used in the update field but the format is being changed 


"Start Date:" & TEXT(DATETIMEVALUE([Opportunity].Date_Time_Start__c )) &
"End Date:" &TEXT([Opportunity].Date_Time_End__c ) &

This is the format i am lookinh for 
2/27/2018 4:00 PM

but this is how i am getting

2017-02-27 21:00:00Z 

How can i get this fixed?? 

 
I am trying to get increase code coverage for this code which is part of unmanaged package.
I could get onlyy 12 lines out of 51 .Which is casuing for my other code to fail in deployment.

Please help me.

this is the apex class
public class CreateStatementPDFConroller{
public String todayDate {get;set;}
public  String ids {get;set;}
public Map<String,accountInDirectPrice> accountInDirectPriceMap{get;set;}

public Map< Account , List< AcctSeed__Billing__c > > accountBillingMap {get;set;}
    public CreateStatementPDFConroller(){
        
        accountInDirectPriceMap = new Map<String,accountInDirectPrice>();
        
        List<Account> accList = [Select Id,Name,Account_Code__c,AcctSeed__Billing_Contact__r.Email FROM Account WHERE Balance_Remaining__c > 0 AND RecordType.Name =: Label.SubAgentAccount];
        ids = '';                                             
        for(Account acc:accList) {
            ids += acc.Id + ',';
        }
        
        todayDate = Datetime.now().format('MM/dd/yyyy');
        accountBillingMap = New Map< Account , List< AcctSeed__Billing__c > >();
        // parameter ids 
             //ids = ApexPages.currentPage().getParameters().get('id');
        if( String.IsNotBlank( ids ) ){
            List< String > idLst = ids.split(','); 
            
            Map< Id , Account > accountMap = New Map< Id , Account >([SELECT Id, Account_Code__c, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry 
                                  FROM Account 
                                  WHERE Id IN : idLst]);
            // fill account to map                       
            for( Account ac : accountMap.values() ){
                accountBillingMap.put(ac , New List< AcctSeed__Billing__c >());
                accountInDirectPrice accval = new accountInDirectPrice();
                accountInDirectPriceMap.put(ac.id,accval);
            }   
                               
            List< AcctSeed__Billing__c > billing = [SELECT Id ,AcctSeed__Age__c ,Name, AcctSeed__Customer__r.Name,Insured__c,AcctSeed__Status__c,AcctSeed__Proprietary_Billing_Number__c,AcctSeed__Date__c,Policy__r.Billing_Company__r.Name,Policy__r.Effective_Date__c,Policy__r.Name,AcctSeed__Due_Date2__c,Policy__r.Name_Insured__c,Policy__r.Policy_Type__c,Policy__r.Status_Type__c,
                                          Sub_Agent_Percent__c,Sub_Agent_Commission_Total__c,Transaction__r.Transaction_Amount__c,Transaction__r.Account__r.Name,AcctSeed__Total__c,Transaction__r.Name,Amount_Due__c,Billing_Type__c,AcctSeed__Balance__c,AcctSeed__Received_Amount__c  FROM AcctSeed__Billing__c 
                                          WHERE AcctSeed__Customer__c IN : idLst  ];
            if( !billing.IsEmpty() ){
                for( AcctSeed__Billing__c ab : billing ){
                    if( accountMap.containsKey(ab.AcctSeed__Customer__c) && accountBillingMap.containsKey(accountMap.get(ab.AcctSeed__Customer__c) ) ){
                       
                        //ab.AcctSeed__Date__c = date.ValueOf(DateTime.newInstance(ab.AcctSeed__Date__c.month(),ab.AcctSeed__Date__c.day(),ab.AcctSeed__Date__c.year()).format('d-MM-YYYY'));
                        accountBillingMap.get(accountMap.get(ab.AcctSeed__Customer__c)).add(ab);
                    }
                    
                    if(accountMap.containsKey(ab.AcctSeed__Customer__c)){
                            
                            if(accountInDirectPriceMap.containsKey(ab.AcctSeed__Customer__c) && ab.AcctSeed__Age__c != null && ab.AcctSeed__Age__c != '' && ab.AcctSeed__Age__c != 'Closed'){
                                
                                accountInDirectPrice accval = accountInDirectPriceMap.get(ab.AcctSeed__Customer__c);
                                if(ab.AcctSeed__Age__c == '0-Current'){
                                    
                                    accval.currentPrice += ab.AcctSeed__Balance__c;
                                
                                } else if(ab.AcctSeed__Age__c == '1-30 Days'){
                                    
                                    accval.to30Days += ab.AcctSeed__Balance__c;
                                    
                                } else if(ab.AcctSeed__Age__c == '31-60 Days'){
                                    
                                    accval.to60Days += ab.AcctSeed__Balance__c;
                                    
                                } else if(ab.AcctSeed__Age__c == '61-90 Days'){
                                    
                                    accval.to90Days += ab.AcctSeed__Balance__c;
                                    
                                } else if(ab.AcctSeed__Age__c == 'Over 90 Days'){
                                                                    
                                    accval.over90days += ab.AcctSeed__Balance__c;
                                }
                                
                                accountInDirectPriceMap.put(ab.AcctSeed__Customer__c,accval);
                                
                                
                            }  
                     }
                }
            }
        }        
    }
    
    public class accountInDirectPrice{
      
      public Decimal currentPrice {get;set;}
      public Decimal to30Days{get;set;}
      public Decimal to60days{get;set;}
      public Decimal to90days{get;set;}
      public Decimal over90days{get;set;}
      
      public accountInDirectPrice(){
          
          currentPrice = 0;
          to30Days = 0;
          to60Days = 0;
          to90Days = 0;
          over90days = 0;
      }
    }
}

test class
 
@isTest
public class CreateStatementPDFConrollerTest {
    @isTest
    public static void unitTest(){
        List<Account> accountLst = new List<Account>();
        Account accObj1 = new Account(Name='test',Balance_Remaining__c=20);
        accountLst.add(accObj1);
        Account accObj2 = new Account(Name = 'test',Balance_Remaining__c=23);
        accountLst.add(accObj2);
        insert accountLst;

        RecordType RecordType1 = [SELECT Id from RecordType where name='General Liability' and sobjecttype = 'Policy__c'];
        
        Policy__c policyObj = new Policy__c();
        policyObj.recordTypeId = RecordType1.Id;
        policyObj.Account__c = accountLst[0].Id;
        policyObj.Name = 'test';
        policyObj.Agency_Commission__c = 10.1;
        policyObj.Billing_Type__c = 'Agency Bill';
        policyObj.Billing_Company__c = accountLst[1].Id;
        insert policyObj;
        
        Transaction__c transObj = new Transaction__c();
        transObj.Account__c = accountLst[0].Id;
        transObj.Policy_Name__c = policyObj.Id;
        transObj.Transaction_Amount__c = 10;
        transObj.Tran_Code__c = 'Audit Premium- Add';
        transObj.Client_Type__c='Direct Insured';
        insert transObj;
        
        AcctSeed__Accounting_Period__c accountingPeriod = new AcctSeed__Accounting_Period__c();
        accountingPeriod.Name = '2016-12';
        accountingPeriod.AcctSeed__Start_Date__c = System.today().addDays(792);
        accountingPeriod.AcctSeed__End_Date__c = System.today().addDays(7888);
        accountingPeriod.AcctSeed__Status__c = 'Open';
        insert accountingPeriod;
        
        AcctSeed__Billing_Format__c billingformatObj = new AcctSeed__Billing_Format__c();
        billingformatObj.name = 'test';
        billingformatObj.AcctSeed__Type__c = 'Billing';
        billingformatObj.AcctSeed__Visualforce_PDF_Page__c = 'BillingActivityStatementPDF';
        billingformatObj.AcctSeed__Default_Email_Template__c = 'Activity_Statement_Email_Template';
        insert billingformatObj;
        
        AcctSeed__Billing__c billingObj = new AcctSeed__Billing__c();
        billingObj.AcctSeed__Status__c = 'In Process';
        billingObj.AcctSeed__Customer__c = accountLst[1].Id;
        billingObj.Transaction__c = transObj.Id;
        billingObj.Policy__c = policyObj.Id;
        billingObj.AcctSeed__Date__c = System.today().adddays(76);
        billingObj.AcctSeed__Accounting_Period__c = accountingPeriod.Id;
        billingObj.AcctSeed__Billing_Format__c = billingformatObj.Id;
        insert billingObj;
        
        ApexPages.currentPage().getParameters().put('id',accountLst[0].id);
        CreateStatementPDFConroller controllerObj = new 
        CreateStatementPDFConroller();
        
       

    }
}

 
My company has decided to move entire metadata and data to new org.(Due to some reasons)
So i am trying to start with that.Apart from data,we are having apps,installed packages,std objects,custom objects,community, and many more

So where should i start with?what should i transport first?
Any pointers please.