• sroberts_ME
  • NEWBIE
  • 0 Points
  • Member since 2011

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

Hi all,

 

We have had an apex class in place for some time now that queries a significant number of accounts at one point. 13,000 prospect accounts have been added to our org and as a result we receive a heap size error every time we try to run the code and when deploying due to the test case related to the class. I have deleted the class and the apex page in our sandbox org, but I am wondering how I push these changes over to production using change sets when the apex test fails every time. Any help would be greatly appreciated.

 

-Sam

static testMethod void AssetAtRiskTest(){

        Account acc = new Account(name = 'foo');

      insert acc;

 

        ApexPages.StandardController sc = new ApexPages.StandardController(acc);

        PageReference pageRef = sc.view();

               

        AssetAtRisk a = new AssetAtRisk(sc);                

        test.startTest();       

        test.setCurrentPage(pageRef);       

        pageRef = a.autoRun();                       

        test.stopTest();

}

 

so this is my test code minus the assertions of course. The issue is that when the autorun function is running the following line always produces null.

 

String theId = ApexPages.currentPage().getParameters().get('id');

 

I would expect this line to set theId to the Id of the new account I created in the test method, however this is not the case. Am I missing something simple here?

So, here's the plan. I've written two triggers, one for after update and after insert and one for before update. They look a lot like this:

 

trigger beforeCAP on Contact (before update) {
    Set<Id> accountIds = new Set<Id>();
    
    for (Contact c : Trigger.new) {
        accountIds.add(c.AccountId);
    }

    Map<Id, Account> accountsToUpdate = new Map<Id, Account>([SELECT Id, Contact_CAP_Score__c FROM Account where Id in: accountIds]);

    for (Contact c : Trigger.new) {
        Account a = accountsToUpdate.get(c.AccountId);
        a.Contact_CAP_Score__c = a.Contact_CAP_Score__c - c.Contact_CAP_Score__c;
    }
    update accountsToUpdate.values();

 

annnnd

 

trigger afterCAP on Contact (after update, after insert) {
    Set<Id> accountIds = new Set<Id>();
    
    for (Contact c : Trigger.new) {
        accountIds.add(c.AccountId);
    }

    Map<Id, Account> accountsToUpdate = new Map<Id, Account>([SELECT Id, Contact_CAP_Score__c FROM Account where Id in: accountIds]);

    for (Contact c : Trigger.new) {
        Account a = accountsToUpdate.get(c.AccountId);
        a.Contact_CAP_Score__c = a.Contact_CAP_Score__c + c.Contact_CAP_Score__c;
    }
    update accountsToUpdate.values();

 

 

Using these triggers our plan is to first deploy the after update trigger and run a mass update. This will set the initial values for account.Contact_CAP_Score. Then we will deploy the before update trigger which should appropriately handle all future edits/inserts. My question is essetially this: Do you see any major problems with this plan, and is there a better way to get the task done?

 

Thanks,

-Sam

The max for a long is 2^63 >> 99,999,999,999

 

Long max = 99999999999;

 

Error: Compile Error: Invalid Integer: 99999999999

 

WHY? its not an integer, at all. It is within the limits for the data type...

Hi all,

 

I have two VF pages that use the same controller. The first page has a button that searchs based on user input and redirects to the second page. The second page should open an excel sheet with the results of the search, but it always comes out blank. The search function works fine without the page redirect so I'm wondering if the redirect is reinitializing the controller. If that's the case how can I pass the results onto the next page?

 

-Sam

Hi all,

 

Im trying to deploy a single apex class and visualforce page into our production environment, but whenever I try to verify the change set I get the following error:

 

Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Class_Code__c]: [Class_Code__c]", Failure Stack Trace: "Class.OpportunityLineItemServicesTest.TRAINING_DOUBLE_ENTITLEMENT: line 161, column 9 External entry point"

 

Similar errors are shown as well, but all have to do with the field Class_Code__c. I looked into this field and found that it was in our production environment, but not our sandbox. I tried adding the field and uploading the changes again with no luck. I'm not sure where this error even comes from because my code doesnt touch the class object or any related objects. Any ideas?

 

Thanks,

sam

Hi all,

 

I've used the following query to get my data.

 

list<Account> accountList =  [SELECT Id, Name, (SELECT Id, Name, Product__r.Name FROM Assets__r) FROM Account];

 

Account is the parent to Assets in a master detail relationship. Because of this I used the subquery to get information from assets. The Product is the parent in the Asset/product relationship, so I used the dot notation in the subquery.

 

The question now is how do I access this info.

 

for(Account Acc : accountList)

{

if (Acc.Asset__r.Product__r.Name == 'something')

{

//do stuff

}

}

 

The above does not work because Acc.Asset__r is not a valid relationship because Account is the parent. If this is the case how can I access it?

 

Thanks, 

sam

Hi all,

 

I am trying to get a list of all of the products that a given account owns. I read the page on relationship queries but I can quite figure out how to get this working.

 

public list<account> Accounts = [SELECT Account.Name, (SELECT (SELECT Product__c.Name FROM Asset__c.Product__c) FROM Account.Asset__c) FROM Account];

 

That's the query ive been working on. Any help would be appreciated.

 

Thanks,

-Sam

Hi all,

 

I'm trying to figure out how to find the Id of the account the current user is associated with. I want to limit a query to find only records associated with that account. I thought there was a $User.account or something, but there doesn't seem to be. Any ideas?

 

Thanks,

Sam

Hi all,

 

I am new to the force.com platform and was wondering if you could help.

 

My goal is to output all of the contacts from all accounts that have asset "a" and do not have asset "b". Based on my understanding this can not be done with the normal reports section, but my guess is it is pretty simple in apex. The thing I can't quite figure out is how to check "a" and "b" against all the values of the assets related list for each account in our database.

 

I hope that's enough information, thanks for your help!

 

-Sam 

Hi all,

 

We have had an apex class in place for some time now that queries a significant number of accounts at one point. 13,000 prospect accounts have been added to our org and as a result we receive a heap size error every time we try to run the code and when deploying due to the test case related to the class. I have deleted the class and the apex page in our sandbox org, but I am wondering how I push these changes over to production using change sets when the apex test fails every time. Any help would be greatly appreciated.

 

-Sam

static testMethod void AssetAtRiskTest(){

        Account acc = new Account(name = 'foo');

      insert acc;

 

        ApexPages.StandardController sc = new ApexPages.StandardController(acc);

        PageReference pageRef = sc.view();

               

        AssetAtRisk a = new AssetAtRisk(sc);                

        test.startTest();       

        test.setCurrentPage(pageRef);       

        pageRef = a.autoRun();                       

        test.stopTest();

}

 

so this is my test code minus the assertions of course. The issue is that when the autorun function is running the following line always produces null.

 

String theId = ApexPages.currentPage().getParameters().get('id');

 

I would expect this line to set theId to the Id of the new account I created in the test method, however this is not the case. Am I missing something simple here?

I am new to this, so please bear with me ...

 

I am trying to setup a trigger that will automatically populate the product of a case if a support tech enters a serial number, but if there is no serial number, leave the product field alone for the tech to use normally.

 

Within the Case object, I have the field Product (Product__c) which is a type Lookup(Product) and I have a field Serial Number (Serial_Number__c) which is a type Lookup(Asset).  (Our assets' names are the same as the serial numbers)

 

Under the Asset object, I have a the standard field of Product (Product2) which is a type Lookup(Product).

 

I want the trigger to run after insert and after update.  Essentially I want it to check the case to see if there is a Serial Number and if so, use the Product defined within the Asset (Serial Number).  This way I will not have issues where we get the Serial Number later, enter it in and have the wrong product on the case.

 

Below is my meager code, I know I am not doing something right as it is giving me a compile error on the where clause that I put in.  I don't think it is the right way to do it.

 

Thanks.

 

trigger updateProduct on Case (after insert, after update) {

Case myCase = trigger.new[0];
if (myCase.Serial_Number__c) {myCase.Product__c = Asset.Product2.Name where Asset.Name = myCase.Serial_Number__c; update myCase;}

}

 

So, here's the plan. I've written two triggers, one for after update and after insert and one for before update. They look a lot like this:

 

trigger beforeCAP on Contact (before update) {
    Set<Id> accountIds = new Set<Id>();
    
    for (Contact c : Trigger.new) {
        accountIds.add(c.AccountId);
    }

    Map<Id, Account> accountsToUpdate = new Map<Id, Account>([SELECT Id, Contact_CAP_Score__c FROM Account where Id in: accountIds]);

    for (Contact c : Trigger.new) {
        Account a = accountsToUpdate.get(c.AccountId);
        a.Contact_CAP_Score__c = a.Contact_CAP_Score__c - c.Contact_CAP_Score__c;
    }
    update accountsToUpdate.values();

 

annnnd

 

trigger afterCAP on Contact (after update, after insert) {
    Set<Id> accountIds = new Set<Id>();
    
    for (Contact c : Trigger.new) {
        accountIds.add(c.AccountId);
    }

    Map<Id, Account> accountsToUpdate = new Map<Id, Account>([SELECT Id, Contact_CAP_Score__c FROM Account where Id in: accountIds]);

    for (Contact c : Trigger.new) {
        Account a = accountsToUpdate.get(c.AccountId);
        a.Contact_CAP_Score__c = a.Contact_CAP_Score__c + c.Contact_CAP_Score__c;
    }
    update accountsToUpdate.values();

 

 

Using these triggers our plan is to first deploy the after update trigger and run a mass update. This will set the initial values for account.Contact_CAP_Score. Then we will deploy the before update trigger which should appropriately handle all future edits/inserts. My question is essetially this: Do you see any major problems with this plan, and is there a better way to get the task done?

 

Thanks,

-Sam

The max for a long is 2^63 >> 99,999,999,999

 

Long max = 99999999999;

 

Error: Compile Error: Invalid Integer: 99999999999

 

WHY? its not an integer, at all. It is within the limits for the data type...

Hi all,

 

I have two VF pages that use the same controller. The first page has a button that searchs based on user input and redirects to the second page. The second page should open an excel sheet with the results of the search, but it always comes out blank. The search function works fine without the page redirect so I'm wondering if the redirect is reinitializing the controller. If that's the case how can I pass the results onto the next page?

 

-Sam

Hi all,

 

I've used the following query to get my data.

 

list<Account> accountList =  [SELECT Id, Name, (SELECT Id, Name, Product__r.Name FROM Assets__r) FROM Account];

 

Account is the parent to Assets in a master detail relationship. Because of this I used the subquery to get information from assets. The Product is the parent in the Asset/product relationship, so I used the dot notation in the subquery.

 

The question now is how do I access this info.

 

for(Account Acc : accountList)

{

if (Acc.Asset__r.Product__r.Name == 'something')

{

//do stuff

}

}

 

The above does not work because Acc.Asset__r is not a valid relationship because Account is the parent. If this is the case how can I access it?

 

Thanks, 

sam

Hi all,

 

I am trying to get a list of all of the products that a given account owns. I read the page on relationship queries but I can quite figure out how to get this working.

 

public list<account> Accounts = [SELECT Account.Name, (SELECT (SELECT Product__c.Name FROM Asset__c.Product__c) FROM Account.Asset__c) FROM Account];

 

That's the query ive been working on. Any help would be appreciated.

 

Thanks,

-Sam