• harry.free
  • NEWBIE
  • 5 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 19
    Replies

Hi Guys,

 

I'm running into the issue while working with a trigger. The query is something like:

 

[select Id from Lead where Name in :newNames and Phone in :newPhones]

It works fine when the newNames values are {'Harry Zhang', 'Tom'}, but if the values are {'/// ////', '__ __'} or some othe special characters like '-, ., *, the non-selective queries error happen. Can anyone give any suggestion why these special characters would cause the error? 

 

To be clear, this is not a syntax error with the query, even the newNames with the value of {'/// ////', '__ __'} can get the correct lead in the system log window, it just doesn't work in the trigger. Following are details about non-selective queries issue from SF documentation.


For more efficient SOQL queries, particularly for queries inside of triggers, use selective (indexed) queries. Selective queries filter on primary keys, foreign keys, names, audit dates (such as LastModifiedDate), or External ID fields. In large organizations, non-selective queries could be stopped at runtime in order to prevent very long running operation times. If you need them for your application, contact your salesforce.com representative.


Note: If you use a non-selective query in a trigger against an object that contains more than 100000 records an error is generated. You should include indexed fields in the WHERE clause to avoid these exceptions.

Is there a way to create a function that can take in a varying number of parameters? 

 

I know in java to do such a thing you can have a function like this: 

 

public double average(double...values) { 

 ....function body....

}

 

Is there a simliar method to do this in APEX? 

 

Thanks in advance! 

  • September 04, 2013
  • Like
  • 0

Can't seem to get this to work.  I have a left outer join query but it doesn't like the relationship syntax:

 

for (Account acct:[SELECT Id,(SELECT Solution__c FROM Org_ID__r)FROM Account WHERE Id in :list_Accts.ID]) {

 

It says it doesn't understand the relationship from Org_ID__r but I check and thats the name of the child object as shown in the lookup field.  

 

Here is what i'm trying to do.  I have a related list under the Account that is lookup, not master-detail.  It holds different external IDs an account could possibly have (duplicates).  There is a field on the account that functions the same and is the old way we did it when it was a one to one relationship.  To speed things up for our service teams to enter accounts they just put the account number on the account and a trigger decides if a new entery in the related list needs to be added or not.

 

1. user enteres a number in a text field to represent an external Key.

2. If that number doesn't match any of the numbers in the related list then create a new one, else leave it alone.

 

Is the Left Outer Join the way to go?  I did something like this on another trigger but that was a master-detail and also standard objects so I don't know if my syntax is correct.

 

Here is the old code with the nested SOQL that I am trying to fix:

trigger CPMOrgIDCreate on Account (after insert, after update) {
    try {
        // List of account IDs
        List<Id> list_Accts = new List<Id>();

        // Add to the list all opps associated with an agreement in the trigger that has been signed
        for (Account AcctID: Trigger.New) {
            if ((trigger.isInsert && AcctID.CPM_Org_ID__c != NULL)|| ( trigger.isUpdate && AcctID.CPM_Org_ID__c != NULL && trigger.oldMap.get(AcctID.id).CPM_Org_ID__c != AcctID.CPM_Org_ID__c )){
                list_Accts.add(AcctID.ID); 
            }
        }

    
        // Loop through all accounts who were added to the list previously
        for (Account acct:[SELECT Id, CPM_Org_ID__c FROM Account WHERE Id in :list_Accts]) {

        
            // Check to see if a project already exists that is related to the opportunity
            List<ORG_ID__c> list_OrgIDs = new List<ORG_ID__c>();
            for (ORG_ID__c SystemID:[SELECT Id FROM ORG_ID__c WHERE ID__c = :acct.CPM_Org_ID__C AND Account__c = :acct.id]) {
                list_OrgIDs.add(SystemID);
            }
        
            if (list_OrgIDs.size() == 0) {
                // If ID does not exist, create one
                ORG_ID__c OID = new ORG_ID__c();
                OID.Account__c = acct.Id;
                OID.ID__c = acct.CPM_Org_ID__c;
                OID.Solution__c = 'CPM';
            
                // Create the new project
                insert OID;
            }            
        }
    } catch (Exception e) {Trigger.new[0].addError(e.getMessage());}   
}

 

Hi,

 

Can anyone help me to write the apex trigger for snding email notifcation to the customer when the new case is created using email template and email notification for assigning the case to the case team and case owner(queues)?

 

 

Please help me.

 

 

Thanks.,

Ambiga

Hi All,

 

How to migrate the data from one salesforce organization to another salesforce organization. Here first organization have Five custom objects with Look up Relationships, how to insert first organization object records  to second organization with out manual mapping between the objects(Relationship objects). Is this possible? If yes which tool is better for doing this work. Please guide me.

 

Thank you.

hi,

can some help me

 List<SObject> ObjectContents;

String query=Select name from contact;

 ObjectContents = database.query(query);

 

if my query returns 2 rows then size of objectcontents wll be how much?

 

Thanks.

  • September 03, 2013
  • Like
  • 0

In Account object, I have a custom field named "Company" which in a managed package (Namespace Prefix: act).
How can I get the value from this custom field by SOQL?

Thanks in advance!

Hi i have jst added a prog in this i want to add the elements is this possible or not can any one help

 

trigger GettingPrice on Bookings__c (before insert , before update) 
{
   set<string> BookingModelSet = new set<string>();
    for(integer i=0;i<trigger.size;i++)
        {
        BookingModelSet.add(trigger.new[i].Model__c);
        }
   list<Vehicle_Rental_Price__c> PriceOfVehicles = new list<Vehicle_Rental_Price__c>();
   PriceOfVehicles = [select name , Rental_Price__c from Vehicle_Rental_Price__c where name in:BookingModelSet];
    Map<string,decimal> MappingPriceToModel = new Map<string , decimal>(); 
    for(integer i=0;i<PriceOfVehicles.size();i++)
    {   
        MappingPriceToModel.put(PriceOfVehicles[i].name , PriceOfVehicles[i].Rental_Price__c);
    }
    for(integer i=0 ; i<trigger.size ; i++)
    {
    if(MappingPriceToModel.containskey(trigger.new[i].Model__c))
            trigger.new[i].price_per_day__C = MappingPriceToModel.get(trigger.new[i].model__c);
        }
}

 

in this the model__c is a multi picklist field so wen i select a single value from model the price_per_day is automatically generated but in case of selecting multiple values from Model__C the price_per_day is empty  ???

 

can we add such type of values????

  • September 03, 2013
  • Like
  • 0

I have master detail relationship between Book and Lents object. I want a control in order to avoida  book to be issued second time. I have added following code on Lent object creation before inserting I am checking if Book is already in OldMap it should give an error mesage else it should insert the record. But the code is not working:

 

trigger UpdateCount on Lent__c (before insert,after insert,after delete) {
List<Contact> counts_toUpdate = new List<Contact>();
Map<String, Integer> contact_newCount_Map=new Map<String, Integer>(); //for each contact the CountNumber

if(trigger.isinsert){
List<Lent__c> counts =[select Book__c,Contact__c, Contact__r.Count__c,Book__r.Name
from Lent__c where id IN :Trigger.new FOR UPDATE];

for(Lent__c lent:counts){
if((lent.Book__c!= null) && (lent.Book__c != Trigger.oldMap.get(lent.id).Book__c))
{
lent.Book__c.addError('Another new lead has the same email address.');
}else{
contact_newCount_Map.put(lent.Contact__c, Integer.valueOf(lent.Contact__r.Count__c==null ? 0 : lent.Contact__r.Count__c) + 1);
}}
}
else if(trigger.isdelete){
Set<Id> contactIds = new Set<Id>();
for (Lent__c l : Trigger.old)
contactIds.add(l.Contact__c);
//List<Lent__c> counts = [select Contact__c, Contact__r.Count__c
//from Lent__c where id IN :contactIds];
Map<Id,Contact> oldContacts = new Map<Id,Contact>([SELECT Count__c From Contact where Id IN :contactIds]);
for(Lent__c lent : Trigger.old)
contact_newCount_map.put(lent.Contact__c, Integer.valueOf(oldContacts.get(lent.Contact__c).Count__c == null ? 0 : oldContacts.get(lent.Contact__c).Count__c ) -1);
}

for(Contact con : [select id, Count__c from Contact WHERE ID IN : contact_newCount_Map.KeySet()]){
con.Count__c=contact_newCount_Map.get(con.id);
counts_toUpdate.add(con);
}

update counts_toUpdate;
}

 

Someone please help.

  • September 02, 2013
  • Like
  • 0

Two objects are there object1 & object2 

 

if object1 is update then automatically object2 is updating, vice versa object2 is update automatically update object1

 

these two objects are in loop conditions.

 

My question is how u will stop the updating. 

Explain me how many ways we can stop the updating..

 

Please reply this question...

 

 

if we exceed the governer limits of soaql queries 

 

what error will be shown ?

what is the solution

 

please reply to this question......

Hi Guys,

 

I'm running into the issue while working with a trigger. The query is something like:

 

[select Id from Lead where Name in :newNames and Phone in :newPhones]

It works fine when the newNames values are {'Harry Zhang', 'Tom'}, but if the values are {'/// ////', '__ __'} or some othe special characters like '-, ., *, the non-selective queries error happen. Can anyone give any suggestion why these special characters would cause the error? 

 

To be clear, this is not a syntax error with the query, even the newNames with the value of {'/// ////', '__ __'} can get the correct lead in the system log window, it just doesn't work in the trigger. Following are details about non-selective queries issue from SF documentation.


For more efficient SOQL queries, particularly for queries inside of triggers, use selective (indexed) queries. Selective queries filter on primary keys, foreign keys, names, audit dates (such as LastModifiedDate), or External ID fields. In large organizations, non-selective queries could be stopped at runtime in order to prevent very long running operation times. If you need them for your application, contact your salesforce.com representative.


Note: If you use a non-selective query in a trigger against an object that contains more than 100000 records an error is generated. You should include indexed fields in the WHERE clause to avoid these exceptions.