• Ajay Gautam
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hey Experts,

Need suggestions about implementing a VF page (that has ReadOnly annotation = true).
Controller needs to deal with Really large data set with less SOQL filters to query, and then loop on based on Maps.
This situation is making us face the CPU time limit, where a LARGE portion of execution is in SOQL. Any suggestion to avoid this? Offset? Tuning?

Please advise. Thanks in advance!
 
Basic Logic is :
For insert trigger case --- processNewContact is the class. 
Whenever a new contact is created of the type 'customer', it is inserted into objQ object.
Now, when the contact is created, a custom field 'PID' needs to be updated from external system into Salesforce. 


After Update Trigger Case --->
Whenever an existing contact is updated - If any of the fields change with 'PID' value null, updated record needs to be pushed into objQ object. Then the external system will reply back with 'PID' value which will assigned to Salesforce record.

Behavior now :
Whenever a  new contact  is created, 2 copies of the same record are inserted into the Queue object. This I am assuming is happening because 'after insert' and 'after update' triggers aer firing for every new contact created. 


I don't understand why this is happening. There are no workflows impacting the behavior . It has to do with logic in the class below. UpdateContact  is similar to processNewContact method below ; only difference is checking whether any of the fields have changed. If they have and 'PID' value is null, record will be pushed into Queue object.  Please assist. I have been trying to fix for sometime without any luck...I need to fix it as soon as possible. I had posted the same earlier but didn't get any reply.  I am new to  programming and can't figure out how to fix it. Thanks...




public static void processNewContact(Map<Id, Contact> newContactMap, Map<Id, Contact> oldContactMap)
02{
03    List<Queue__c> lstQ = new List<Queue__c>();   
04    Id idContactCustomerRecType;
05    Map<Id, String> mapIdToAccountName = new Map<Id, String>();
06     
07    // Assuming Contact type Name is 'Customer'
08    List<RecordType> lstRecType = new List<RecordType>([SELECT Id FROM RecordType WHERE Name = 'Customer' AND SobjectType = 'Contact']);
09    if(!lstRecType.isEmpty())
10        idContactCustomerRecType = lstRecType[0].Id;
11         
12    if(idContactCustomerRecType != null)
13    {
14        // we can;t fetch parent fields directly, so collect account Ids first
15        for(Contact objContact : newContactMap.values())
16        {
17            if(objContact.AccountId != null)
18                mapIdToAccountName.put(objContact.AccountId, null);
19        }
20    }
21     
22    // iterate over account with matching collected Ids and fetch names
23    for(Account objAccount : [SELECT Id, Name FROM Account WHERE Id IN : mapIdToAccountName.keySet()])
24    {
25        mapIdToAccountName.get(objAccount.Id, objAccount.Name);
26    }
27     
28    // loop again to perform business logic
29    for(Contact objContact : newContactMap.values())
30    {
31        /* 1. If Contact RecordType is Customer AND if LastName != Account.Name, insert Queue **/
32        if(objContact.RecordTypeId == idContactCustomerRecType && objContact.AccountId != null && objContact.LastName != mapIdToAccountName.get(objContact.AccountId))
33        {
34            Queue__c objQ = new Queue__c();
35            objQ.Object_Name__c='Contact';
36            objQ.Description__c= 'New Contact';
37            objQ.Record_Id__c = objContact.Id;
38            objQ.Notification_Timestamp__c= objContact.CreatedDate;
39            lstQ.add(objQ);
40        }
41             
42    }
43     
               isCreated = true;

44    if(!lstQ.isEmpty())
45        insert lstQ;
46     
47  }

Trigger Invocation :  After UPDATE
if(ContactController.isCreated==false ){
        ContactController.UpdateContact(Trigger.newMap, Trigger.oldMap);
    } 

AFTER INSERT 
    ContactController.processNewContact(Trigger.newMap, Trigger.oldMap);

 
I'm very new to apex and have been working on a custom 'proposal object.'  The object is related to the lead object through a lookup field.  There are a number of fields the sales person has to fill in on the proposal object in order to generate a proposal (using loop document generation).  Once all fields are filled in and values are calculated, I want to push a number (at least 10) fields back to the related lead.  

I don't really know how to do this.  I'm trying to use the put method, but it doesn't seem to be working.  Here is the relevant code:
 
for(Proposal__c p:Trigger.new){
	        
	        Lead lead = mLead.get(p.Lead__c);

lead.put('Panel_Type__c',p.Panel_Type__c);
Any advice would be appreciated.  Thanks in advance.  
 
I have written apex code to get the controlling field values and corresponding field values but to test that I need to add some values in both controlling and dependent fields and map them in the test class. Most of the posts tell how to get get the mapped values but they dont say how to add the values and map them.