• Box
  • NEWBIE
  • 25 Points
  • Member since 2008

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 44
    Replies
Hi All,

I've been looking at the "set methods" in the apex lnaguage reference and see that there is no 'get' method for sets.
How does someone iterate through a set of values?

For example I have a Map of type Map<String, List<String>> myMap;

for each of the keys I'd like to do something with the list of values in the map.... to find the list of keys I use the Map Method "keySet()"

so I have a Set<String> s = myMap.keySet();

then I want a loop to iterate through this set and get the list from the map based on the set.value .....

help please???

Hey guys,

 

I have an interesting question for you and would like to see how you guys would protect against the gov limit as I cannot see how this is possible with the current APEX functionality.

 

Scenario

 

We have a trigger that processes all sub accounts and contacts to a parent account.  This processing is relatively simple and quick and populates information down for partner portals and the like.

 

A new account is created on Salesforce and its bigger than anything that has come before, let’s say there is a parent account, many sub accounts and we have a lot of contact records.  The total sum of records that would be returned from the database is now greater than 1000 which as we all know will blow the gov limit.

 

My Expected solution (doesnt work)

 

I was hoping that I would be able to either:

 

a)      Put the query in a try catch block and nicely handle the error to the User and infrom them that they would have to initiate the population logic from the nice button and get a nice big gov limit

b)      Inspect the limits object while processing but you can never tell if the SOQL is going to push you over i.e.

 

For(Account[] arrAccount : ([select what, I, need from Account]))

{

                // Inspecting limits here is useless as we will raise an error before getting here

                For(Account sAccount : arrAccount)

{

                // and we cant do it here as there is already a big nasty error message on the UI

 

                // TODO : my logic

}

}

 

Let me know what you think,

 

Chris

  • June 11, 2008
  • Like
  • 0
Hello.  I wrote a trigger which prevents Tasks and Events from being deleted by anyone other than their creator.  Code is easy enough - compare the current user with the createdbyid.  The issue is in writing the test code.  How do I create a test for the scenario where the current user and createdbyid are different?

thanks
chris
  • August 29, 2008
  • Like
  • 0
Hello.  I am writing a trigger which does the following: when Account ownership is changed, query all associated Notes, Open Activities, Contacts (and related Notes and Open Activities), and Open Opportunities (and related Notes and Open Activities) - and change the ownership of all of those records.  I'm concerned that in some rare cases I may be updating more than 100 records as a result of this.

So my question: If i divide this functionality into three triggers - one which does Account Notes and Open Activities, a second trigger which does related Contacts (with Notes and Activities), and a third which does Opportunities (with Notes and Activities) - will this help?   Or will the platform calculate the sum of the records being processed by all three triggers?

Thanks
Chris
  • July 30, 2008
  • Like
  • 0

I am developing a page in which i want to show total number accounts who have certain condition, my code is like this:
Code:
 if (ptotalRecords == 0)
       {
            try
            {
              ptotalRecords = [select count() from Account WHERE (Hierarchy_Status__c = 0 OR Hierarchy_Status__c = null) AND (parent_duns_number__c != null OR Ultimate_Parent_D_B_Number__c != null)];
            }
            catch(Exception ex)
            {
                 ptotalRecords = -1; 
            }
      }
       
      if (ptotalRecords == -1)
         return '10,000+';
      else
         return ptotalRecords+ '';

 Even though i have put everything in try and catch block i still get the following error:

System.Exception: Too many query rows: 10001

it seems as a developer i do not have the right to choose the fate of my App!



Hey,
Is there anyway i could keep track of some inventory using native applications only.
For eg i have 100 boxes and 4 are sent out, my opportunity should show 96 and the opportunity that the boxes are shipped to will now show 4.
If the boxes are returned then my opportunity will show 100 again and the corresponding opportunity will show 0.
Let me know if there is a solution to this, even if its a non-native solution.

Thanks

We are currently working ona  problem where we want to dynamically update certain fields in Salesforce when the user opens the object.  We don't want to store the data within Salesforce, but rather retrieve it from one of our internal servers with another integration tool we currently use.
 
The in-house integration tool can be kicked off via HTTP Request, so we thought of going there first, and using the return results to dynamically update a VisualForce page.  However due to security issues, it does not appear as though this is possible.
 
What other ways can this be accomplished?  What is a best practice for a "mash-up" into Salesforce?
I am trying to develop a trigger to automatically convert Lead record into an Account record.  I had code
working before I requested Person Account to be activated in my Developer Edition to match my Enterprise Edition.
Now I get the following error message:
 
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger LeadToAccount caused an unexpected exception, contact your administrator: LeadToAccount:
execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0;
first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, record type missing for: Account: Trigger.LeadToAccount:
line 54, column 9
 
The trigger code is included below:
 
trigger LeadToAccount on Lead (before insert) {
 for (Lead lead : System.Trigger.new) {
  System.debug('lead = ' + lead);
  Account LeadAccount  = new Account();
  LeadAccount.Account_Group__c = lead.Account_Group__c;
  LeadAccount.Affiliate_Code__c = lead.Affiliate_Code__c;
  LeadAccount.RD_Age__pc = lead.Age__c;
  LeadAccount.AnnualRevenue = lead.AnnualRevenue;
  LeadAccount.Assistance_to_build_your_portfolio__c = lead.Assistance_to_build_your_portfolio__c;
  LeadAccount.Booking_Code__c = lead.Booking_Code__c;
  LeadAccount.Business_Code__c = lead.Business_Code__c;
  LeadAccount.BillingCity = lead.City;
  LeadAccount.Company_Name__c = lead.Company_Custom_field__c;
  LeadAccount.BillingCountry = lead.Country;
  LeadAccount.DateofFirstContact__c = lead.DateofFirstContact__c;
  LeadAccount.Description = lead.Description;
  LeadAccount.PersonDoNotCall = lead.DoNotCall;
  LeadAccount.PersonEmail = lead.Email;
  LeadAccount.PersonHasOptedOutOfEmail = lead.HasOptedOutOfEmail;
  LeadAccount.E_minis_Global_Workshop__c = lead.E_minis_Global_Workshop__c;
  LeadAccount.Fax = lead.Fax;
  LeadAccount.PersonHasOptedOutOfFax = lead.HasOptedOutOfFax; 
  LeadAccount.FirstName = lead.FirstName;
  LeadAccount.RD_Income__c = lead.Income__c;
  LeadAccount.Industry = lead.Industry;
  LeadAccount.LastName = lead.LastName;
  LeadAccount.PersonLeadSource = lead.LeadSource;
  LeadAccount.Lead_Source__c = lead.Lead_Source__c;
  LeadAccount.Mail_Opt_Out__pc = lead.Mail_Opt_Out__c;
  LeadAccount.PersonMobilePhone = lead.MobilePhone;
  LeadAccount.NumberOfEmployees = lead.NumberOfEmployees;
  LeadAccount.RD_Other_Investment_Interests__c = lead.Other_Investment_Interests__c;
  LeadAccount.Phone = lead.Phone;
  LeadAccount.PO_Box__c = lead.PO_Box__c;
  LeadAccount.RDPhonecall__c = lead.Q1_Would_you_like_receive_a_phonecall__c;
  LeadAccount.RDLearnStockMarket__c = lead.RDLearnStockMarket__c;
  LeadAccount.RDLearnInvestProperty__c = lead.RDLearnInvestProperty__c;
  LeadAccount.RDLearnInternetBusiness__c = lead.RDLearnInternetBusiness__c;
  LeadAccount.RDLearnInvestor__c = lead.Q3_Someone_investing_on_your_behalf__c;
  LeadAccount.RDEmploymentStatus__c = lead.Q4_Current_employment_situation__c;
  LeadAccount.Q5_Total_assets_less_total_liabilities__c = lead.Q5_Total_assets_less_total_liabilities__c;
  LeadAccount.Rating = lead.Rating;
  LeadAccount.Referral_Code__c = lead.Referral_Code__c;
  LeadAccount.Salutation = lead.Salutation;
  LeadAccount.BillingState = lead.State;
  LeadAccount.BillingStreet = lead.Street;
  LeadAccount.Website = lead.Website;
  LeadAccount.Website_Origin__c = lead.Website_Origin__c;
  // LeadAccount.Web_Source__c = lead.SFGA__Web_Source__c;
  LeadAccount.Work_Phone__pc = lead.Work_Phone__c;
  LeadAccount.BillingPostalCode = lead.PostalCode;
  insert LeadAccount;
  System.debug('LeadAccount = '+ LeadAccount);
  
 }
}
Hello.  I'm trying to populate a list with some dummy records so I can do some unit testing.  However, when I do a for loop, the list remains null and the assertion fails.  I've tried two different assignment techniques but neither works.  If I get rid of either for loop and just put in a line j = 0, then the list is populated.  I can't figure out what I'm doing wrong here.

Thanks
David
Code:
public class Util {

 static testmethod void testAllTriggers() {
  Integer i, j;
 
  //Set up a contact and payments for testing.
  Contact person = new Contact(FirstName = 'John', LastName = 'Qwertyuiop');
  insert person;
  Id contactID = [select id from Contact where LastName = 'Qwertyuiop'].Id;
  Membership_Payment__c[] payments = new Membership_Payment__c[23];

//THIS LOOP FAILS TO POPULATE
//  for (j = 0; j == 22; j++) {
//   payments[j] = new Membership_Payment__c(Contact__c = ContactID, Name = (2010 + j).format(),
//    Posted_Date__c = Date.newInstance(2010 + j, 1, 2), Amount__c = 20);
//  }

//THIS LOOP ALSO FAILS TO POPULATE
//  for (j = 0; j == 22; j++) {
//   payments.add(new Membership_Payment__c(Contact__c = ContactID, Name = (2010 + j).format(),
//    Posted_Date__c = Date.newInstance(2010 + j, 1, 2), Amount__c = 20));
//  }

  system.assertEquals(date.newInstance(2010, 1, 2), payments.get(0).Posted_Date__c);  


 

Does anyone know what does this define:
System.ListException: Missing id at index: 0

I am trying to delete in my testmethod the item i created during my testmethod and it does not work...
anyone have an example of using delete in there test methods or what
that message defines.
Thanks
Hello all,

my first thread in the community forum...:smileyvery-happy:

I wrote a trigger in the sandbox environment and a test class that invokes that trigger.
the trigger works perfectly, and got 100% coverage.

the problem is that other triggers that were already in which I didn't wrote/change, didn't  pass the tests.

those triggers were already in the environment, I didn't change a thing. I assumed that someone wrote test classes for them in order to deploy them to the production.

anyway, I understood that I need to write a test class that invokes the trigger I just wrote, which I did.

what am I missing here?

Thank a lot , Assaf
  • July 15, 2008
  • Like
  • 0

select a.ID from PricebookEntry a   Product2 b where Product2.ProductCode =:productCode    

error is appeared.

unexpected token: Product2 

 

 

how can i make the SOQL[select a.ID from PricebookEntry a   Product2 b where Product2.ProductCode =:productCode ] to be right?

  • July 02, 2008
  • Like
  • 0
Hi,
    I thought I saw a post recently that it would be possible to store custom settings in Salesforce and access them through APEX. I don't see anything in Summer '08. Is this on the way?
 
Thanks,
Mike
Our users can target in on data sets with over 10,000 Contacts.

I have a VF page to gather criteria. Once I have the criteria, I'd want to say,

"Narrow your selection criteria, you're about to get too many Contacts."

How do I do that? I thought I'd run a SOQL 'intNumberOfContacts = SELECT count() FROM Contact WHERE ....'

but when it goes over 10,000, it bombs.

I thought I'd use try ... catch ...    But, as the documentation says, you can't catch from a blown
governor limit.

What am I to do?

Thanks.
hi All,

Everytime a contact is updated I have to look for the lead that matches with it and update it too. My problem is that I have a lot of Contact updated at the same time and they are imported with data Loader. At this time the ApexApplication give me a lot of error with this message:

contactAfterUpdate: execution of AfterUpdate

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

Trigger.contactAfterUpdate: line 90, column 24

I attach you my code and the line 90 is in bold:

// List of Lead IDs
List<ID> leadIDs = new ID[] {};

// List to hold the leads that will be updated
List<Lead> leadsToUpdate = new Lead[] {};
// List to hold the Contacts that changed and have an open & active account now
List<Contact> ContactwithAccount = new Contact[] {};
//Map of Contacts, indexed by matching lead ids - added 03/04/08 SH
Map<ID, Contact> cMap = new Map<ID, Contact>();

// Loop through all the incoming contacts and get the lead ID
for(Integer j = 0; j<Trigger.new.size(); j++) {
//If the lead__c change from a value null to a value not null we have to look for the lead that marches the contact and update the lead
if (Trigger.new[j].Lead__c != null && Trigger.old[j].Lead__c == null){
ContactwithAccount.add(Trigger.new[j]);
leadIDs.add(Trigger.new[j].Lead__c);
//insert matching contact info into map - added 03/04/08 SH
cMap.put(Trigger.new[j].Lead__c, Trigger.new[j]);
}
}


// issue one query to get all leads for all incoming IDs and store in map (to avoid Apex restrictions)
Map<ID, Lead> matchingLeads = new Map<ID, Lead> ([SELECT Id, Status, MMB__c, Market_Update__c FROM Lead WHERE status = 'Open' and id IN :leadIDs]);
// loop through the incoming contacts again, for each, get the lead from the map
for(Contact loopContact : ContactwithAccount){
Lead foundLead = matchingLeads.get(loopContact.Lead__c);
if(foundLead!=null){
foundLead.Status = 'Converted';
foundLead.Date_Converted__c = System.today();
leadsToUpdate.add(foundLead);
}

}
// finally update any leads that have been marked for update
update leadsToUpdate;

//empty Lists for updated objects - added 03/04/08 SH
List<Event> updateE = new List<Event>();
List<Task> updateT = new List<Task>();
List<Note> insertN = new List<Note>();
List<Note> deleteN = new List<Note>();
List<Attachment> insertA = new List<Attachment>();
List<Attachment> deleteA = new List<Attachment>();
List<CampaignMember> insertCM = new List<CampaignMember>();
List<CampaignMember> deleteCM = new List<CampaignMember>();

//loop through lead events and assign them to corresponding contact from cMap - added 03/04/08 SH
for (Event[] arre : [Select Id, WhoId from Event where WhoId IN :matchingLeads.KeySet()]) {
for(Event e : arre){
e.WhoId = cMap.get(e.WhoId).Id;
updateE.add(e);
}
}
update updateE;

//loop through lead tasks and assign them to corresponding contact from cMap - added 03/04/08 SH
for (Task[] arrt : [Select Id, WhoId from Task where WhoId IN :matchingLeads.KeySet()]) {
for(Task t : arrt){
t.WhoId = cMap.get(t.WhoId).Id;
updateT.add(t);
}
}
update updateT;

//loop through campaign member records for lead and recreate for contact, then delete lead version
for (CampaignMember[] arrcm : [Select Id, ContactId, LeadId, CampaignId, Status from CampaignMember where LeadId IN :matchingLeads.KeySet()]) {
for(CampaignMember cm : arrcm){
CampaignMember cmNew = new CampaignMember(CampaignId = cm.CampaignId, ContactId = cMap.get(cm.LeadId).Id, Status = cm.Status);
insertCM.add(cmNew);
deleteCM.add(cm);
}
}
insert insertCM;
delete deleteCM;

for (Note[] arrn : [Select Body, Id, IsPrivate, OwnerId, ParentId, Title from Note where ParentId IN :matchingLeads.KeySet()]) {
for(Note n : arrn){
Note nNew = new Note(Body = n.Body, IsPrivate = n.IsPrivate, OwnerId = n.OwnerId, Title = n.Title, ParentId = cMap.get(n.ParentId).Id);
insertN.add(nNew);
deleteN.add(n);
}
}
insert insertN;
delete deleteN;

for (Attachment[] arra : [Select Id, Body, BodyLength, ContentType, IsPrivate, Name, OwnerId, ParentId from Attachment where ParentId IN :matchingLeads.KeySet()]) {
for(Attachment a : arra){
Attachment aNew = new Attachment(Body = a.Body, ContentType = a.ContentType, IsPrivte = a.IsPrivate, Name = a.Name, OwnerId = a.OwnerId, ParentId = cMap.get(a.ParentId).Id);
insertA.add(aNew);
deleteA.add(a);
}
}
insert insertA;
delete deleteA;
}


I guess that there are too many query in that line but I don't know I could do it in another way... any help???

Many Thanks