• stcforce
  • NEWBIE
  • 175 Points
  • Member since 2011

  • Chatter
    Feed
  • 7
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 16
    Questions
  • 75
    Replies

Hi All

I am a newbie writing apex.I understand why I am getting this but I can not find a work around. I am writing a trigger that creates a custom object every time a new opportunity is created.  The possible workaround I may have,  is to pull all the data of Rep_assignments__c in a list and then use logic to get the values I need. I have about 27,000 record in there and do not find it an effective way to program. Any suggestions are appreciated,

Thanks

 

 

Here is my code:

I am calling this from a trigger.

 

public static void setpipeline (Opportunity [] opps)
 {
Date maxvalue = NULL ;
//build list of records
list<Rep_assignments__c> Records = new list<Rep_assignments__c>() ;
    list <date> dates = new List<date>();

List <print_pipeline__c> pipelinetoinsert = new List<print_pipeline__c>();

//need to put list of opportunities
list<Opportunity> Oppty = new List<Opportunity> ();

//build list of records of rep assignments
for (Opportunity z:opps)
    {
    
    
  if (z.RecordTypeId ==record_type &&  z.integration__c <> 1)
  records = [select r.id, r.Rep1_id__c,  r.Rep1_pct__c, r.Rep2_id__c, r.Rep2_pct__c, r.Rep3_id__c, r.Rep3_pct__c,  r.Rep4_id__c, r.Rep4_pct__c, r.effective_date__c
    from Rep_assignments__c r where r.brand__c = :z.brand__c and r.pub_id__c =:z.pub_id__c and r.effective_date__c <=:z.CloseDate ];
 }


//if more than one record found, then we need to get the max date and the array ref number to get the correct rep assignment
if (records.size() !=0)
{
    integer ref_num = 0;

    date maxdate;
    if (records.size() > 1)
        {
    
        for (integer i = 0; i < records.size(); i++)
        {
            
          dates.add((records.get(i).effective_date__c));  
         }
         //get max date
         maxdate = dates[0];
         
         for (integer i = 0; i < dates.size(); i ++){
           if (dates[i] > maxdate)
           maxdate = dates[i];    
         }
        }
        //get ref number
        
        for (integer i=0; i <Records.size(); i++){
            if (records[i].Effective_Date__c == maxdate)
            ref_num= i;
        }  

//create print pipe
    
    for (Opportunity o:opps){
    
    if (records.get(ref_num).rep1_id__c != null)
    {
            print_pipeline__c pipeline = new print_pipeline__c (Opportunity__c=o.id ,
             Rep_assignment__c=records.get(ref_num).id,     Sales_Rep__c=records.get(ref_num).Rep1_id__c,
            Rep_split__c=records.get(ref_num).Rep1_pct__c );
                pipelinetoinsert.add(pipeline);    
       
    }
    if (records.get(ref_num).rep2_id__c != null){
               print_pipeline__c pipeline = new print_pipeline__c (Opportunity__c=o.id , Rep_assignment__c=records.get(ref_num).id,     Sales_Rep__c=records.get(ref_num).Rep2_id__c,
                Rep_split__c=records.get(ref_num).Rep2_pct__c );
                pipelinetoinsert.add(pipeline);    
    }
    if (records.get(ref_num).rep3_id__c != null)
    {
               print_pipeline__c pipeline = new print_pipeline__c (Opportunity__c=o.id , Rep_assignment__c=records.get(ref_num).id,     Sales_Rep__c=records.get(ref_num).Rep3_id__c,
                Rep_split__c=records.get(ref_num).Rep3_pct__c );
                pipelinetoinsert.add(pipeline);    
    }
    if (records.get(ref_num).rep4_id__c != null)
    {
               print_pipeline__c pipeline = new print_pipeline__c (Opportunity__c=o.id , Rep_assignment__c=records.get(ref_num).id,     Sales_Rep__c=records.get(ref_num).Rep4_id__c,
                Rep_split__c=records.get(ref_num).Rep4_pct__c );
                pipelinetoinsert.add(pipeline);    
    }
    }


if (!pipelinetoinsert.isEmpty())
database.insert(pipelinetoinsert);
}

}

REQUIREMENT :- Need to be able to delete Opportunities via data loader. 
i.e when i'm trying to delete some opportunites through DATA LOADER i'm getting the below ERROR :-


Getting the following message: 
tgrOpportunityBefore: execution of BeforeDelete 
caused by: System.NullPointerException: Attempt to de-reference a null object 
Trigger.tgrOpportunityBefore: line 379, column 1 

 

 

 

TRIGGER :-

 

 // --- This is used since most of the triggers are for Insert and Update on Opportunity.
    if(trigger.isInsert || trigger.isUpdate) {  
      //#101OICD - Variable Declaration -- Start    
      StaticVariables.setAccountDontRun(true); // stop account trigger from running
      List<Id> accIds = new List<Id>();
      Set<id> accidset = new set<id>();
      //#101OICD - Variable Declaration -- End
      
   
 
      //#101OICD -- Loop Through Opp records  and assign values -- Start
      for(Opportunity o:Trigger.new) {
        
        system.debug('Originator EIN ' + o.Originator_EIN__c);
        allCampaignIds.add(o.CampaignId);//CR2180        
        //if(o.Opportunity_Owner_EIN__c == '802558891') o.ABR_Count__c =1;  
        
     
        
        if(o.CloseDate ==null)o.CloseDate = (Date.today()+ 365);
        
        if(o.AccountId != null && o.Auto_Assign_Owner__c)accIds.add(o.accountId);
        
        if(o.OwnerId != null)o.owner__c = o.OwnerId;
        
        //add flag for org to org
        if (
        (o.Routing_Product__c == 'Engage IT' || o.Product_Family__c == 'ENGAGE IT') 
        && o.CreatedDate >= (date.newinstance(2011, 11, 19))  
        //    || ((trigger.newmap.get(o.id).Routing_Product__c != trigger.oldmap.get(o.id).Routing_Product__c)
        //    || (trigger.newmap.get(o.id).Product_Family__c != trigger.oldmap.get(o.id).Product_Family__c ))
        ){
            o.s2s_Link__c = 'BTB to Engage IT';  
        }
        

    //#101OICD -- Part of 101OICD Trigger to Modify Opportunit Owner By Account -- End
     
     //#101OICD -- Part of 101OICD Trigger to Modify Account Information -- Start
        //Added by GS to update account last call date.
        //Update the account last call date field for these accounts      
        list<account> updateCallDate = new list<account>();          
        updateAccountLastContacted updateAccountCallDate = new updateAccountLastContacted();                     
        //updateCallDate = updateAccountCallDate.updateAccount(accidset);
        String objName='Opportunities';
        updateCallDate = updateAccountCallDate.updateAccount(accidset, objName);           
        update updateCallDate;               
    //#101OICD -- Part of 101OICD Trigger to Modify Account Information -- End
    }
     
    //Set RAG Status to None if Leasing History has 0 records -- Start
   LINE 379 :- for(Opportunity o : trigger.new){
    Integer i = [SELECT count() FROM Leasing_History__c WHERE Opportunity__c =: o.Id LIMIT 1];
    if(i < 1){
      o.Finance_Available__c = 'None';
     }
    }    
    //Set RAG Status to None if Leasing History has 0 records -- End   
}

Hello, senior,

 

and I met above problem 'No standard price defined for this product',
I try to use

      'Pricebook2 pricebook = [Select p.I d, p.N ame from Pricebook2 p where isActive = true and isStandard = true Limit 1];       'code for object, but called the

      ' List has no rows for assignment to SObject 'mistakes

       don't know what to do, hope to get solutions thank

Hello all. I'm creating a controller to send an email but the heap size is 6mb and the act of creating attachments has the effect of creating duplicates (however briefly) of the list of attachments, which would suggest that for a synchronous execution, you can at most have 3mb (total) of attachments. This seems impossibly restrictive. Does anyone have any ideas (other than asynchronous apex) to address this? The requirement is to produce a custom email send functionality in an image heavy org. Consequently, they want to be able to send the maximum size of attachments. The question becomes: does this deep copy behavior represent an absolute limit or is there a potential workaround?

I would appreciate any help anyone is able to give.

thank you.

 

code/debug results to illustrate the problem:

 

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

Messaging.EmailFileAttachment[] someAttach= newlist<Messaging.EmailFileAttachment>();

attachment a = [Select a.Name, a.ContentType,a.Body FromAttachment a limit 1];

Messaging.EmailFileAttachment attach=new Messaging.EmailFileAttachment();

attach.setFileName(a.Name);

attach.setInline(false);

attach.Body=a.body;

attach.setContentType(a.ContentType);

someAttach.add(attach);

a = null;

System.debug('Limit pre: '+Limits.getHeapSize()+' out of '+Limits.getLimitHeapSize()+'.\n ');

if(!someattach.isEmpty()) mail.setFileAttachments(someAttach);

System.debug('xxx Limit post: '+Limits.getHeapSize()+' out of '+Limits.getLimitHeapSize()+'.\n ');

 

the above code produces:

 

09:51:51.686 (3686665000)|USER_DEBUG|[79]|DEBUG|Limit pre: 16761 out of 6000000.

09:51:51.687 (3687050000)|USER_DEBUG|[81]|DEBUG|xxx Limit post: 32386 out of 6000000.

 

which would seem to be a deep copy of the entire list and consequently presents problems for the heap limit.

I currently have this written which isn't working out because sometimes people reopen cases

trigger UpdateResoTCategor on Case (before update) {

  Double timeStat;
  BusinessHours bh = [select id from businesshours where isDefault = true];
  
  for (Case c : Trigger.new){
    Case oldCase = Trigger.oldMap.get(c.ID);
      
      if (oldCase.Status != 'Closed' && (c.Status == 'Closed' || c.Status == 'Escalated')){
        timeStat = BusinessHours.diff(bh.id, c.CreatedDate, System.now())/3600000.0;
           
        c.TimeBetweenCase__c = timeStat;    
      }    
  }
}

 I want to calculate the time difference between open and closed in BusinessHouses based on CreatedDateTime and ClosedDateTime but the problem is that isClosed and the ClosedDate don't actually get genereated til afterwards. I tried to do the same thing on after update and used the ClosedDate field but I keep getting errors on it: "execution of AfterUpdate caused by: System.FinalException: Record is read-only"

 

Does anyone have any ideas on how to do this?

 

I have a simple vf page, I am trying to set the checkbox value selected to true. But it doesnt work when the page is displayed the checkboxes are  unchecked.

 

<apex:page standardController="Opportunity" extensions="Test">
 
  <apex:form id="theform">
      <apex:actionFunction action="{!click}" name="displayFunction"  rerender="" id="afunc">
                <apex:param name="stageV" value="" id="aparam"/>
      </apex:actionFunction>
      
      <apex:pageBlock id="pageblock">
            <apex:repeat value="{!stageValue}" var="s">
                <apex:outputLabel value="{!s.Name}"/>
                <apex:inputCheckbox selected="true" />
            </apex:repeat>
        </apex:pageBlock>  
  </apex:form>
</apex:page>

I have a scheduled job that runs nightly which basically updates any team member that is active and becomes inactive due the the start and end date and visa versa.  When update these records there are a lot of triggers that get set off.  If the list of active --> Inactive or the inactive -->active is too big I will run into soql limits

 

In my code put a limit on the query to only retrieve x amount for inactive or active lists.  but really I need it to run all of them

 

any way of accomplishing this.

 

Hi ,

In my application, I want to write scheduler.The code from schduler is executing for each user from organization.

For each user, I have to execute arrount 20 DML +SOQL statements.
I have more than 100 user so getting Limit exception :Too many SOQL :101


Can anyone help?

 

Thanks in advance.

 

Regards,
Dipak

i have some code that is running in a class that observes sharing but have observed that the code is sucessfully returning entries from emailtemplates, brandtemplates, users, profiles, folders while testing as a non-sysadmin user. My issue is, i don't know quite what to expect with these object - I don't know where they fit into the scheme of things. Can anyone direct me to a explanation of what objects or individual records a user can access when talking about objects on which the object permissions and the sharing model don't describe what is available (as seems to be the case) ?

thank you.

 

Hi friends,

 

Below given code I have taken directly from a tutoria.It works in the tutorial.However,when I run in salesforce,It just doesn't do anything .I do not what is wrong.Can somebody point out.

<Apex:page >
<html>
<head>
<script type="text/javascript">
function OnUnload()
{
alert ("The current document will be unloaded!");
}
</script>
</head>
<body onunload="OnUnload()">

<p>Close this window or press F5 to reload the page.</p>

</body>
</html>
</apex:page>

 

 

Thanks,

Trick

Naive question, how to update a custom master object  with distinct child counts on nightly basis?

Any input is highly appreciated.

 

Thanks

Hi,

 

I am writing trigger to delete custom objects upon deletion of a Campaign. 

 

Is there a limit of how many records can be deleted in a trigger?

 

I need to delete upto 300,000 records so wondering if this is possible to delete in a trigger. If not, is it possible to create Apex Job and execute in a trigger?

 

Thanks,

how to create and put dropdownlist in visualforce page?i mean to say take an example country.no.of countries is there.how to take it as a dropdown or picklist in visaul force page.is there any need to create a custom controller.if it is need.pls clarify this how to create apex class for this purpose in visual force page.pls clarify i will wait.

thanks in advance.

Hi,

 

We are planning to build a functionality where we need to have a report to check the number of times a record is viewed on the Account object. 

 

I need to build a apex code which will capture the number of times a record is opened. Can anybody help or suggest me how can I achieve this. 

 

Would appreciate any help regarding this as it is critical.

 

 

Hello all,

 

I have a trigger (case before update) in which I want to do different things depending upon whether the trigger occurs in a batch or single context. (This is to get around a problem I have with a @future method being called from within batch mode)

 

Is there a way to tell if the context is in batch mode? I haven't found anything about this in the docs or forums.

 

Thanks for any help,

Graeme