• salesforcecrap
  • NEWBIE
  • 0 Points
  • Member since 2011

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

In the absence of ContractContactRole triggers, is there a recommended strategy for causing a Contract to be updated when an associated ContractContactRole is created or updated?

 

For example, via the SF gui, when I add a new Role to a Contract and click "Save" I'd like the associated Contract to also be saved. So to speak.

 

Can anyone (especially if you're from the SF team) tell me why we still don't have triggers on association objects like ContractContactRole?

 

As it sits, my stakeholders add a Contact to a Contract Role, then have to edit/save the Contract, which does have a trigger, in order for my Apex code to grab all the ContractContactRoles associated with the Contract.

 

Thanks for any insight.

Hi fellow hackers,

A fellow developer voiced that integrating directly with the SF REST API could be unreliable since in the event of an outage, our core application functionality would directly suffer.

As such, I implemented a proxy service on Heroku. This proxy represents a "clone" of our salesforce data and provides RESTful endpoints for our applications. So currently, our applications only talk directly to the proxy, and never directly to SF. I implemented a simple, effective approach to keeping the proxy "in sync" with SF data.

 

I'd love to remove this proxy from our infrastructure, but I am wondering about how to properly handle cases when SF is down. What approaches have you taken? Any good online resources or best practices for how to handle unavailable services that directly impact the functionality of the application that consumes those services?

 

Thanks for your insight.

 

Hi hackers,

Ok, I've read the docs, I've pared down my queries and DML, and placed some work in a Batch Apex class.

 

This Batch Apex class' start() method returns a QueryLocator based off of


[SELECT Id, myAttribute__c from Contact]

 

It's execute() method then calls three functions, say fA, fB and fC.

 

fA() executes one dml update on a list of Contacts, say 6,000 of them.

 

fB() executes one dml update on a list of Contacts, say 2,000 of them.

 

fC() executes one dml update on a list of Contacts, about 4,000 of them.

 

When I execute the batch, I can see in the Monitor interface that it queues up 328 batches, which makes sense since 200 per batch x 328 is about 65,600 Contacts, which is about the number of Contact records in our SF domain.

 

What am I not understanding about Batch Apex that is related to my job raising the LimitException?

 

 

 

Hi fellow SF hackers,

I've got a Schedulable class, and now I just want to actually schedule the thing. I realize that I can:

System.schedule('Job Name', s, m); 

But is there a mechanism in the SF interface itself that lets me schedule a Schedulable?


Without this, it seems like I have to implement a simple view/controller and do this manually.

 

Thanks for any tips.

 

Hi fellow hackers, I'm wondering if any of you SOQL jocks can help steer me in the right direction.

 

I have a function that basically:

  • creates a list of all Contracts
  • for each Contract's Account, create a list of Contacts from that Account and all child Accounts.

Given that I have an Account object, let's call it root,  I basically execute some simple recursion to obtain a List of all Account objects in the heirarchy below root.

 

This works great. But then I run into an issue when trying to grab all the Contacts for all of those Accounts. I thought that I would iterate over each account and query for its Contacts, but that exceeds my SOQL query limit. Then I realized that instead of a SOQL query for the Contact objects, I could just access each Account object's Contacts (eg, account.Contacts). However, I then get a different Exception:

 

System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.Contacts

 

Which I understand. My question is, can I create a SOQL query that allows me to access all the Contacts of the Account associated with Contracts?

 

Here is my code. I'll point out some highlights below.

 

/**
   Find all enterprise contracts
   For each contract, instantiate the account
   Find the account's child accounts
   Create a list of all contacts from the main and child accounts
   Set each contact's "Subscription" attribute to the contract "product" attribute, if the contract is active (current date is within contract start/end dates) and the contact's email domain matches the contract "domains" attribute.
 */
private void updateEnterpriseContactSubscriptions() {
  List<Contract> enterpriseContracts = [SELECT Id,startDate,endDate,product__c,subscription_type__c,enterprise_email_extensions__c, Account.Id, Account.parentId FROM Contract];
  List<Contact> allSubscribersToUpdate = new List<Contact>();
  for (Contract contract : enterpriseContracts) {
    if (contract.startDate <= Date.today() && contract.endDate >= Date.today()) {
      
      List<Account> accounts = accountListFromHeirarchy(contract.Account);
      List<Contact> subscribers = new List<Contact>();
      for (Account account : accounts) {
        // The following line is what I want, but exceeds my SOQL limit.
// List<Contact> contacts = [SELECT Id,email,subscriptions__c FROM Contact WHERE accountID=:account.Id]; List<Contact> contacts = account.Contacts; List<Contact> contactsWithValidEmail = new List<Contact>(); for (Contact c : contacts) { if (contractEmailDomainsIncludeContactEmail(contract.enterprise_email_extensions__c, c.email)) { contactsWithValidEmail.add(c); } } subscribers.addAll(contactsWithValidEmail); } for (Contact subscriber : subscribers) { subscriber.subscriptions__c = appendEditionName(subscriber.subscriptions__c, contract.product__c); } allSubscribersToUpdate.addAll(subscribers); } } update allSubscribersToUpdate; }

 
And here is my recursive accountListFromHeirarchy function:

 

public List<Account> accountListFromHeirarchy(Account root) {
  List<Account> accounts = new List<Account>();
  accounts.add(root);
  List<Account> children = [SELECT Id FROM Account WHERE parentId = :root.Id];
  for (Account child : children) {
    accounts.addAll(accountListFromHeirarchy(child));
  }
  return accounts;
}

 

In my updateEnterpriseContactSubscriptions function, the line

 

List<Contact> contacts = account.Contacts;

 

is what raises the exception I mentioned above. And just above that line, I've commented out what I inteded to do originally, but it's that loop and query that busts my SOQL limit.


Is there a way to modify the query that generates enterpriseContracts (the first line of the first function shown above) such that I would be able to access each Account object's Contacts?

 

Thanks for your time.

Can anyone (especially if you're from the SF team) tell me why we still don't have triggers on association objects like ContractContactRole?

 

As it sits, my stakeholders add a Contact to a Contract Role, then have to edit/save the Contract, which does have a trigger, in order for my Apex code to grab all the ContractContactRoles associated with the Contract.

 

Thanks for any insight.

 

 

I am new to apex and am trying to build an apex schedule class that runs everyday. If the account review date for commisions is two weeks (14 days) away the scheduler will send an email to our Sales Department.

 

I think I have all the information I need. I have a made a class that implements the schedulable interface.

 

I have a system schedule method but I don't know where to put it....in the scheduable class or in a new class?

 

Do I have to make a test class for this once my other code is all right? How do I build a test class?

 

Here is my code:

 

global class AccountReviewScheduler implements Schedulable {

 

   global void execute (SchedulableContext ctx) { //what does this line of code do?//

 

{

SendEmail();

}

 

 

public void SendEmail()

{

 

      if (Account.Next_Account_Review_Date_c == System.Today().addDays(14))

{

 

                 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

                 Mail.setTemplateId('00XF0000000LfE1;);

                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail });

}

 

}

 

// I'm not sure how to link this information to the previous class, make another one? I don't think I can put it in the above class. This schedules my class to run every day at 2:00 am.

 

newScheduledClass m = new newScheduledClass();  

//schedule set for 2am everyday //

String s = '0 0 2 * * ?';

 

// I'm not sure what "Job Name" specifies. I got this code from someone else. //  

system.schedule('Job Name', s, m);

 

Thanks for your help. I have read over the tutorial in the Apex workbook and the Apex Scheduler in the documentation...but I still don't know where to put my system.schedule method or what "job name" means in my code.

 

Please help!

Hi hackers,

Ok, I've read the docs, I've pared down my queries and DML, and placed some work in a Batch Apex class.

 

This Batch Apex class' start() method returns a QueryLocator based off of


[SELECT Id, myAttribute__c from Contact]

 

It's execute() method then calls three functions, say fA, fB and fC.

 

fA() executes one dml update on a list of Contacts, say 6,000 of them.

 

fB() executes one dml update on a list of Contacts, say 2,000 of them.

 

fC() executes one dml update on a list of Contacts, about 4,000 of them.

 

When I execute the batch, I can see in the Monitor interface that it queues up 328 batches, which makes sense since 200 per batch x 328 is about 65,600 Contacts, which is about the number of Contact records in our SF domain.

 

What am I not understanding about Batch Apex that is related to my job raising the LimitException?

 

 

 

Hi fellow SF hackers,

I've got a Schedulable class, and now I just want to actually schedule the thing. I realize that I can:

System.schedule('Job Name', s, m); 

But is there a mechanism in the SF interface itself that lets me schedule a Schedulable?


Without this, it seems like I have to implement a simple view/controller and do this manually.

 

Thanks for any tips.

 

Hi fellow hackers, I'm wondering if any of you SOQL jocks can help steer me in the right direction.

 

I have a function that basically:

  • creates a list of all Contracts
  • for each Contract's Account, create a list of Contacts from that Account and all child Accounts.

Given that I have an Account object, let's call it root,  I basically execute some simple recursion to obtain a List of all Account objects in the heirarchy below root.

 

This works great. But then I run into an issue when trying to grab all the Contacts for all of those Accounts. I thought that I would iterate over each account and query for its Contacts, but that exceeds my SOQL query limit. Then I realized that instead of a SOQL query for the Contact objects, I could just access each Account object's Contacts (eg, account.Contacts). However, I then get a different Exception:

 

System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.Contacts

 

Which I understand. My question is, can I create a SOQL query that allows me to access all the Contacts of the Account associated with Contracts?

 

Here is my code. I'll point out some highlights below.

 

/**
   Find all enterprise contracts
   For each contract, instantiate the account
   Find the account's child accounts
   Create a list of all contacts from the main and child accounts
   Set each contact's "Subscription" attribute to the contract "product" attribute, if the contract is active (current date is within contract start/end dates) and the contact's email domain matches the contract "domains" attribute.
 */
private void updateEnterpriseContactSubscriptions() {
  List<Contract> enterpriseContracts = [SELECT Id,startDate,endDate,product__c,subscription_type__c,enterprise_email_extensions__c, Account.Id, Account.parentId FROM Contract];
  List<Contact> allSubscribersToUpdate = new List<Contact>();
  for (Contract contract : enterpriseContracts) {
    if (contract.startDate <= Date.today() && contract.endDate >= Date.today()) {
      
      List<Account> accounts = accountListFromHeirarchy(contract.Account);
      List<Contact> subscribers = new List<Contact>();
      for (Account account : accounts) {
        // The following line is what I want, but exceeds my SOQL limit.
// List<Contact> contacts = [SELECT Id,email,subscriptions__c FROM Contact WHERE accountID=:account.Id]; List<Contact> contacts = account.Contacts; List<Contact> contactsWithValidEmail = new List<Contact>(); for (Contact c : contacts) { if (contractEmailDomainsIncludeContactEmail(contract.enterprise_email_extensions__c, c.email)) { contactsWithValidEmail.add(c); } } subscribers.addAll(contactsWithValidEmail); } for (Contact subscriber : subscribers) { subscriber.subscriptions__c = appendEditionName(subscriber.subscriptions__c, contract.product__c); } allSubscribersToUpdate.addAll(subscribers); } } update allSubscribersToUpdate; }

 
And here is my recursive accountListFromHeirarchy function:

 

public List<Account> accountListFromHeirarchy(Account root) {
  List<Account> accounts = new List<Account>();
  accounts.add(root);
  List<Account> children = [SELECT Id FROM Account WHERE parentId = :root.Id];
  for (Account child : children) {
    accounts.addAll(accountListFromHeirarchy(child));
  }
  return accounts;
}

 

In my updateEnterpriseContactSubscriptions function, the line

 

List<Contact> contacts = account.Contacts;

 

is what raises the exception I mentioned above. And just above that line, I've commented out what I inteded to do originally, but it's that loop and query that busts my SOQL limit.


Is there a way to modify the query that generates enterpriseContracts (the first line of the first function shown above) such that I would be able to access each Account object's Contacts?

 

Thanks for your time.

Hello.  the documentation for each DML statement says that "You can pass a maximum of 1000 sObject records to a single  

method."

 

Does this apply in Batch Apex as well?  I need to iterate through thousands of imported records and create a list of 2000+ opportunities that will be inserted on a monthly basis.

 

I understand that heap size could be an issue if my opps list gets even larger than 2000, so perhaps I'll just have to manually chunk the insert anyway, but I'd like to know if the 1000 obj DML limit applies in batch Apex.

 

Thanks

David

Hi,
 
Yesterday I had deployed aan apex trigger from sandbox to production env. The trigger is an "before insert, before update" to check for duplicate account names. The trigger works fine in prodiuction for preventing duplicate Account names.
 
But today when I tried to mass update Accounts for some other field using Apex Data Loader, I get the following error:
 

Apex script unhandled trigger exception by user/organization: 00530000000nHi3/00D300000006QZD

Trg_Account_Name_Dedup: execution of BeforeUpdate

caused by: System.Exception: Too many SOQL queries: 21

Trigger.Trg_Account_Name_Dedup: line 1, column 143

Can anyone please advise on how to disable triggers in production env so that I can carry out other mass updates in Account using Apex Data loader tool.

Thanks and regards,
Ambili

  • February 12, 2008
  • Like
  • 0