• Jay16
  • NEWBIE
  • 50 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 15
    Replies

I have a custom object which is a child to the Opportunity object. The custom object is viewed via visualforce page. Sometimes Users need to create payment records for the child object. This is achieved by calling a method on a controller extension. When pressed, the method will automatically create detail records using information in the custom object record. 

I am trying to write a test class that will check the controller is working correctly and that the values copied over from the custom object are correct. I can't figure out how to call the method to create the payments. Can anyone help? 

Here is the test class: 

@isTest                 
public class sipExt_Test {
    public static testMethod void testSIPExtController() {
        
    // Create Opportunity from test utilities class
    List<Opportunity> OppList = testUtilities.createTestOpps(1); 

    // Create the SIP
    bonus_calculator__c bc1 = new bonus_calculator__c(opportunity__c = OppList[0].Id);
    insert bc1;    
        
    PageReference ref = new PageReference('/apex/SIP2?id=' + bc1.Id);
    Test.setCurrentPage(ref);
        
    // Create SIP standard controller, pass it the SIP Record
    ApexPages.StandardController controller = new ApexPages.StandardController(bc1);
        
    // Pass the Controller to the Extension
    sipExt stdController = new sipExt(controller); 
        
    stdController.createPayments();           
  
    // Query for Payments fields
    List <Bonus_Payments__c> bPayList = [SELECT Id FROM Bonus_Payments__c WHERE Bonus_Record__c = :bc1.Id];    
        
        system.debug(bPayList[0].id);                
        
    }
}

  • December 12, 2014
  • Like
  • 0

Hey Guys, 

My query is returning this error when I search using * . Other characters are fine. 

System.UnexpectedException: Invalid character '*' found in the filter value "%*%" used with the "like" operator.

Here's the part of the query that's causing the error:

qString+= ' and (Product2.Name like \'%' + searchString + '%\' or Product2.Description like \'%' + searchString + '%\' or Product2.Family like \'%' + searchString + '%\' )';

Does anyone know how I can update it to allow asterics *  ??

Thanks

  • December 03, 2014
  • Like
  • 0

Hi everyone,

I'm sometimes asked to write code as part of my role, maybe once every 3/4 months. So although I can get by, my code isn't perfect.
I wrote a bunch of triggeres a while back and have just noticed that I left a SOQL query inside a For loop and I can't figure out how to move it out. Could anyone give me some pointers on how I can chieve this please? I'm concerned I will hit governour limits.

Thanks in advance.

Here's the part of the code in question:

trigger setupBonusFields on bc__c (before insert) {
   
        // Create a set of related opps
        set <id> ids = new set <id>();
            for (bc__c newSet : Trigger.new) {
                ids.add(newSet.opportunity__c);
            }

        // Add SA1 & SA2 to map
        map <id,Opportunity> sa1Oppmap= new map<id,Opportunity>();
            for (Opportunity o:[select Sales_Associate_1__c, Sales_Associate_2__c,
                 Sales_Associate_1__r.division__c, Sales_Associate_1__r.region__c, Sales_Associate_2__r.division__c, Sales_Associate_2__r.region__c
                 from opportunity where id in :ids]) {
                sa1Oppmap.put(o.id, o);
            }

  • November 24, 2014
  • Like
  • 0

Hey guys, 

I have a custom object which has a custom button. When pressed it calls a standard controller with custom extension and creates 2 or 4 child records depending on how many are required. The only problem is that if the user presses the same button again, they get 2 or 4 more identical records. 

Does anyone have any ideas as to how I can prevent this from happening? I'm not after code, just general thoughts. 

So far my best idea is to add a check box that gets updated when records are created or deleted (note that i will use 2 buttons, create all and delete all for this to work) and then a visualforce rule to prevent records from being created if the checkbox is true. Ideally I would like to keep this as code light as possible. 

Thanks in advance!
J
  • September 18, 2014
  • Like
  • 0
Hi, 

I could really use some guidence on a current problem I'm faced. Any help would be much appreciated.

I have 2 custom objects with a master detail relationship: parent__c and child__c. 

A Parent__c record  contains information for 4 payments. Chilld__c will be the recipt for each individual payment. 

What I want is for a user to be able to press a button on the parent and create 4 new child records. Each child record will be a recipt for one of the 4 payments.

Can anyone tell me how this can be achieved?

So far I've seen similar examples using Apex, Flows, Custom Controllers, VF pages and more. All of them are fine, I just don't know which would be most appropriate. 

Thanks in advance. 
  • August 19, 2014
  • Like
  • 0

Hi, 

I'm trying to check a checkbox on the parent opportunity when a child record is created. 

When I test the trigger below, the debug log says the checkbox has been updated to true. However when I check the opportunity is has not. I'm quite new to developing in general so apologies if this is something obvious: 

trigger updateOppCb on Bonus_Calculator__c (before insert) {
   
        // Create a set of related opps
        set <id> ids = new set <id>();
        for (Bonus_Calculator__c newSet : Trigger.new)
        ids.add(newSet.opportunity__c);

        // Add child? checkbox to map
        map <id,Opportunity> childMap = new map<id,Opportunity>();
        for (Opportunity o:[select child__c from opportunity where id in :ids])
        childMap.put(o.id, o);
   
     for (Bonus_Calculator__c newBonus : Trigger.new) {
           
            Opportunity o = childMap.get(newBonus.opportunity__c);
            o.child__c = true;
            system.debug('opportunity = '+ o);
   }
}

 

...Thanks a million for any help!

  • July 10, 2014
  • Like
  • 0

Hi everyone, 

I would appreciate some guidence on how to achieve the following if possible: 

I have an opporutnity with 2 fields, region and division. 

I then have some records in Custom Settings, which contain the fields - region, division, sales leader name, sales leader id, 

an example would be - EMEA, IT, John Nix, 069D0000001KMqh

I'm trying to write a before insert trigger that takes the region and division from the opportunity, then looks at Sales_Leaders__c in Custom Settings and returns the sales leader id that is associated to that region and division (there will only be one). 

So far I've been looking at maps, the custom settings methods and SOQL queries but nothing seems to work. Here's an example: 

for (Opportunity newOpp : Trigger.new) {
           
  String div = newOpp.Opporuntity_Lead_Region__c;
  String reg = newOpp.Opportunity_Division__c;
  Id SL1 = newOpp.Sales_Leader_1__c;
           
          
         map <id,Sales_Leader_List__c> SL_Map = new map<id,Sales_Leader_List__c>();
         for (Sales_Leader_List__c sl:[select user_id__c from Sales_Leader_List__c where region__c = :reg AND division__C = :div])
         SL_Map.put(sl.user_id__c, sl);

a) this returns null
b) i have a SOQL query nested in a loop (trying to bulkify where possible)

Can anyone shed some light on this for me? I'm almost a complete noob to SF dev and have tried to figure this one out without leaning on the dev community but I'm spending way too much time on this now so could use a hand. If it can be achived using the Custom Settings methods that would be super awesome too.

Thanks in advance 

 

 

  • July 03, 2014
  • Like
  • 0
Hi everyone,

I have been a SF admin for a while now and I'm staring to dive into some customization.

In theory, what I'm trying to do is simple. I have a custom object, which has a lookup relationship with the Opportunity object.

Here's the user journey:

1) New record is created via related list on opportunity (has to be this way)

2) Edit page loads with opportunity name lookup field pre populated

3) User clicks save

4) All lookup and formula fields get to work and the record is completed

This is all working fine.

However, I needed to build a visualforce page for the custom object records (detail page).

How do I replace the custom object record page layout with my visualforce page?

When I test the page by adding the id to the URL (?=id.....) the page works great. I can't work out how to do this automatically. 

I have tried creating a new Save button, but the page loads blank.

I have also been reading up on extending the VF page, and then overriding the save button with a new Save method. When I do this, I don't know how to format the pageReference URL because the record id has not been created yet.

Can anyone provide some guidance please? Im happy to provide code, although the VF is quite long.

Thanks
  • May 30, 2014
  • Like
  • 0

I have a custom object which is a child to the Opportunity object. The custom object is viewed via visualforce page. Sometimes Users need to create payment records for the child object. This is achieved by calling a method on a controller extension. When pressed, the method will automatically create detail records using information in the custom object record. 

I am trying to write a test class that will check the controller is working correctly and that the values copied over from the custom object are correct. I can't figure out how to call the method to create the payments. Can anyone help? 

Here is the test class: 

@isTest                 
public class sipExt_Test {
    public static testMethod void testSIPExtController() {
        
    // Create Opportunity from test utilities class
    List<Opportunity> OppList = testUtilities.createTestOpps(1); 

    // Create the SIP
    bonus_calculator__c bc1 = new bonus_calculator__c(opportunity__c = OppList[0].Id);
    insert bc1;    
        
    PageReference ref = new PageReference('/apex/SIP2?id=' + bc1.Id);
    Test.setCurrentPage(ref);
        
    // Create SIP standard controller, pass it the SIP Record
    ApexPages.StandardController controller = new ApexPages.StandardController(bc1);
        
    // Pass the Controller to the Extension
    sipExt stdController = new sipExt(controller); 
        
    stdController.createPayments();           
  
    // Query for Payments fields
    List <Bonus_Payments__c> bPayList = [SELECT Id FROM Bonus_Payments__c WHERE Bonus_Record__c = :bc1.Id];    
        
        system.debug(bPayList[0].id);                
        
    }
}

  • December 12, 2014
  • Like
  • 0

Hey Guys, 

My query is returning this error when I search using * . Other characters are fine. 

System.UnexpectedException: Invalid character '*' found in the filter value "%*%" used with the "like" operator.

Here's the part of the query that's causing the error:

qString+= ' and (Product2.Name like \'%' + searchString + '%\' or Product2.Description like \'%' + searchString + '%\' or Product2.Family like \'%' + searchString + '%\' )';

Does anyone know how I can update it to allow asterics *  ??

Thanks

  • December 03, 2014
  • Like
  • 0

Hi everyone,

I'm sometimes asked to write code as part of my role, maybe once every 3/4 months. So although I can get by, my code isn't perfect.
I wrote a bunch of triggeres a while back and have just noticed that I left a SOQL query inside a For loop and I can't figure out how to move it out. Could anyone give me some pointers on how I can chieve this please? I'm concerned I will hit governour limits.

Thanks in advance.

Here's the part of the code in question:

trigger setupBonusFields on bc__c (before insert) {
   
        // Create a set of related opps
        set <id> ids = new set <id>();
            for (bc__c newSet : Trigger.new) {
                ids.add(newSet.opportunity__c);
            }

        // Add SA1 & SA2 to map
        map <id,Opportunity> sa1Oppmap= new map<id,Opportunity>();
            for (Opportunity o:[select Sales_Associate_1__c, Sales_Associate_2__c,
                 Sales_Associate_1__r.division__c, Sales_Associate_1__r.region__c, Sales_Associate_2__r.division__c, Sales_Associate_2__r.region__c
                 from opportunity where id in :ids]) {
                sa1Oppmap.put(o.id, o);
            }

  • November 24, 2014
  • Like
  • 0
Hi, 

I could really use some guidence on a current problem I'm faced. Any help would be much appreciated.

I have 2 custom objects with a master detail relationship: parent__c and child__c. 

A Parent__c record  contains information for 4 payments. Chilld__c will be the recipt for each individual payment. 

What I want is for a user to be able to press a button on the parent and create 4 new child records. Each child record will be a recipt for one of the 4 payments.

Can anyone tell me how this can be achieved?

So far I've seen similar examples using Apex, Flows, Custom Controllers, VF pages and more. All of them are fine, I just don't know which would be most appropriate. 

Thanks in advance. 
  • August 19, 2014
  • Like
  • 0

Hi, 

I'm trying to check a checkbox on the parent opportunity when a child record is created. 

When I test the trigger below, the debug log says the checkbox has been updated to true. However when I check the opportunity is has not. I'm quite new to developing in general so apologies if this is something obvious: 

trigger updateOppCb on Bonus_Calculator__c (before insert) {
   
        // Create a set of related opps
        set <id> ids = new set <id>();
        for (Bonus_Calculator__c newSet : Trigger.new)
        ids.add(newSet.opportunity__c);

        // Add child? checkbox to map
        map <id,Opportunity> childMap = new map<id,Opportunity>();
        for (Opportunity o:[select child__c from opportunity where id in :ids])
        childMap.put(o.id, o);
   
     for (Bonus_Calculator__c newBonus : Trigger.new) {
           
            Opportunity o = childMap.get(newBonus.opportunity__c);
            o.child__c = true;
            system.debug('opportunity = '+ o);
   }
}

 

...Thanks a million for any help!

  • July 10, 2014
  • Like
  • 0

Hi everyone, 

I would appreciate some guidence on how to achieve the following if possible: 

I have an opporutnity with 2 fields, region and division. 

I then have some records in Custom Settings, which contain the fields - region, division, sales leader name, sales leader id, 

an example would be - EMEA, IT, John Nix, 069D0000001KMqh

I'm trying to write a before insert trigger that takes the region and division from the opportunity, then looks at Sales_Leaders__c in Custom Settings and returns the sales leader id that is associated to that region and division (there will only be one). 

So far I've been looking at maps, the custom settings methods and SOQL queries but nothing seems to work. Here's an example: 

for (Opportunity newOpp : Trigger.new) {
           
  String div = newOpp.Opporuntity_Lead_Region__c;
  String reg = newOpp.Opportunity_Division__c;
  Id SL1 = newOpp.Sales_Leader_1__c;
           
          
         map <id,Sales_Leader_List__c> SL_Map = new map<id,Sales_Leader_List__c>();
         for (Sales_Leader_List__c sl:[select user_id__c from Sales_Leader_List__c where region__c = :reg AND division__C = :div])
         SL_Map.put(sl.user_id__c, sl);

a) this returns null
b) i have a SOQL query nested in a loop (trying to bulkify where possible)

Can anyone shed some light on this for me? I'm almost a complete noob to SF dev and have tried to figure this one out without leaning on the dev community but I'm spending way too much time on this now so could use a hand. If it can be achived using the Custom Settings methods that would be super awesome too.

Thanks in advance 

 

 

  • July 03, 2014
  • Like
  • 0
Hi everyone,

I have been a SF admin for a while now and I'm staring to dive into some customization.

In theory, what I'm trying to do is simple. I have a custom object, which has a lookup relationship with the Opportunity object.

Here's the user journey:

1) New record is created via related list on opportunity (has to be this way)

2) Edit page loads with opportunity name lookup field pre populated

3) User clicks save

4) All lookup and formula fields get to work and the record is completed

This is all working fine.

However, I needed to build a visualforce page for the custom object records (detail page).

How do I replace the custom object record page layout with my visualforce page?

When I test the page by adding the id to the URL (?=id.....) the page works great. I can't work out how to do this automatically. 

I have tried creating a new Save button, but the page loads blank.

I have also been reading up on extending the VF page, and then overriding the save button with a new Save method. When I do this, I don't know how to format the pageReference URL because the record id has not been created yet.

Can anyone provide some guidance please? Im happy to provide code, although the VF is quite long.

Thanks
  • May 30, 2014
  • Like
  • 0