• Charan Thumma 15
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 10
    Replies
This is the error:
Apex trigger QuoteLineItemTrigger caused an unexpected exception, contact your administrator: QuoteLineItemTrigger: execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: QuoteLineItem.QuoteId: Trigger.QuoteLineItemTrigger: line 34, column 1

Here is my code:
trigger QuoteLineItemTrigger on QuoteLineItem (after insert, after update){  
    
    // prevent recursion
    if (!QuoteLineItemUtility.TriggerIsRunning){
        QuoteLineItemUtility.TriggerIsRunning = true;

        Set<Id> QuoteIds = new Set<Id>();
 
        List<QuoteLineItem> lineItemsForUpdate = new List<QuoteLineItem>();

        // gather IDs first of quotes
        for (QuoteLineItem ql : trigger.new) {
            
                 QuoteIds.add(ql.QuoteId);
        }

        if (!QuoteIds.isEmpty()) {
            // get all line items for all of the above quotes in bulk so that we don't hit governor limits
            Id prevQuoteId;
            Double lastLineNumber;
            // we can query all and these triggered records in an after trigger, nothing missing
            for (QuoteLineItem ql : [Select Id, Item_Numbering__c
                                       From QuoteLineItem 
                                      Where QuoteId in :QuoteIds
                                   Order By QuoteId, Item_Numbering__c NULLS LAST]) {

                // These are coming in already grouped by the same quote
                // and are sorted by the line number within that group
                
                if (prevQuoteId == null || prevQuoteId != ql.QuoteId) {

                    // start fresh because this is the first iteration OR we made it to 
                    // another group of line items
                    prevQuoteId = ql.QuoteId;
                    lastLineNumber = 0.0; //back to default                   
                }

                // Set the new line numbers as needed
                if(ql.Item_Numbering__c == null || ql.Item_Numbering__c == 0) {

                    ql.Item_Numbering__c = lastLineNumber + 1;
                    
                    // Need to create a "new" in memory line item to break reference to the 
                    // trigger reference, otherwise you will get an error like "cannot update in an After trigger"
                    lineItemsForUpdate.add(new QuoteLineItem(id = ql.id, Item_Numbering__c = ql.Item_Numbering__c));
                }
                
                lastLineNumber = ql.Item_Numbering__c;

            } // end for

        }

        if (!lineItemsForUpdate.isEmpty())
            update lineItemsForUpdate; // DML only the changed line items

        QuoteLineItemUtility.TriggerIsRunning = false;
    }
}
i am integrating  asp.net webapp with salesforce
i have to perform CRUD operations on account object
how can i do it without apex cpde
 
This is the error:
Apex trigger QuoteLineItemTrigger caused an unexpected exception, contact your administrator: QuoteLineItemTrigger: execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: QuoteLineItem.QuoteId: Trigger.QuoteLineItemTrigger: line 34, column 1

Here is my code:
trigger QuoteLineItemTrigger on QuoteLineItem (after insert, after update){  
    
    // prevent recursion
    if (!QuoteLineItemUtility.TriggerIsRunning){
        QuoteLineItemUtility.TriggerIsRunning = true;

        Set<Id> QuoteIds = new Set<Id>();
 
        List<QuoteLineItem> lineItemsForUpdate = new List<QuoteLineItem>();

        // gather IDs first of quotes
        for (QuoteLineItem ql : trigger.new) {
            
                 QuoteIds.add(ql.QuoteId);
        }

        if (!QuoteIds.isEmpty()) {
            // get all line items for all of the above quotes in bulk so that we don't hit governor limits
            Id prevQuoteId;
            Double lastLineNumber;
            // we can query all and these triggered records in an after trigger, nothing missing
            for (QuoteLineItem ql : [Select Id, Item_Numbering__c
                                       From QuoteLineItem 
                                      Where QuoteId in :QuoteIds
                                   Order By QuoteId, Item_Numbering__c NULLS LAST]) {

                // These are coming in already grouped by the same quote
                // and are sorted by the line number within that group
                
                if (prevQuoteId == null || prevQuoteId != ql.QuoteId) {

                    // start fresh because this is the first iteration OR we made it to 
                    // another group of line items
                    prevQuoteId = ql.QuoteId;
                    lastLineNumber = 0.0; //back to default                   
                }

                // Set the new line numbers as needed
                if(ql.Item_Numbering__c == null || ql.Item_Numbering__c == 0) {

                    ql.Item_Numbering__c = lastLineNumber + 1;
                    
                    // Need to create a "new" in memory line item to break reference to the 
                    // trigger reference, otherwise you will get an error like "cannot update in an After trigger"
                    lineItemsForUpdate.add(new QuoteLineItem(id = ql.id, Item_Numbering__c = ql.Item_Numbering__c));
                }
                
                lastLineNumber = ql.Item_Numbering__c;

            } // end for

        }

        if (!lineItemsForUpdate.isEmpty())
            update lineItemsForUpdate; // DML only the changed line items

        QuoteLineItemUtility.TriggerIsRunning = false;
    }
}
Hello,
I've got a simple BatchApex-Cronjob which should delete all objects of a custom objects. 
global class BatchDeleteWorklogsJob implements Database.Batchable<sObject>, Schedulable  {

    global final String query = 'SELECT Id FROM Issue_Worklog__c LIMIT 20000';

    global void execute(SchedulableContext sc) {
        deleteWorklogs();
    }

    global void deleteWorklogs() {
        BatchDeleteWorklogsJob deleteJob = new BatchDeleteWorklogsJob();
        ID batchprocessid = Database.executeBatch(deleteJob);
    }

    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<sObject> scope){
        delete scope;
        Database.emptyRecycleBin(scope);
    }

    global void finish(Database.BatchableContext BC){

        if(!Test.isRunningTest()) {

            List<Issue_Worklog__c> liste = [SELECT Id FROM Issue_Worklog__c LIMIT 20000];
            if(liste.size() > 0) {

                //Die Liste ist noch nicht leer, daher erneut ausfuehren
                deleteWorklogs();
            }
            else {
                //wenn alle Worklogs geloescht sind, dann loesche anschließend die Issues
                BatchDeleteIssuesJob.deleteIssues();
            }
        }
    }
}

The cronjob gets executed every night and always fails with a REQUEST_RUNNING_TOO_LONG exception. So the problem is my soql query, right? I've already added the LIMIT 20000 condition hoping that it will fix the problem. But nope. 
If I execute the query in the developer console I also get a "No response from server" message.

Any guesses how I can solve this problem? Thanks in advance ;-)
I'm going through the trailhead course on Apex and I am trying to understand why 'return acct;' is a necessary line in this class.
public class AccountHandler {
	public static Account insertNewAccount(String name)
    {
        Account acct = new Account(Name= name);
        insert acct;
        return acct;
    }
}
Originally I wrote this class without searching the developer community for the answer. The only thing I was missing was 'return acct;'. I'm trying to understand why that line is needed. 
Hello,

I am new to SF development and have written my first few triggers. For the trigger below, I keep running into the error message "Apex CPU time limit exceeded" on production. The trigger is counting the number of contacts, that meet a set of criteria, on an account that are active and use the mobile app.

I have removed nested loops and attemped to do the majority of the work on the DB side but I still receive the same error. Does anoyone have any suggestions on how I can improve the effiency of this code and decrease CPU time? In particular, any suggestions for the first for loops?
trigger sum_active_mobile_users on Contact (after delete, after insert, after undelete, 
after update) {

    // Trigger to calculate the number of active mobile users on an account 

    List<Contact> contacts = Trigger.isDelete ? Trigger.old : Trigger.new;

    Set<ID> acctIds = new Set<ID>();
    
    for (Contact c : contacts) {

         if (c.AccountId != null) {

            acctIds.add(c.AccountId);
        }

    }
    
    List<Account> acctsToRollup = new List<Account>();

      for (AggregateResult ar : [select AccountId AcctId, 

                                        Count(id) ContactCount

                                   from Contact

                                  where AccountId in: acctIds

                                    and Source_of_data__c = 'Sync from site A'

                                    and Active__c = 'Yes'

                                    and User_suspended__c = 'No - active' 

                                    and Date_Of_Mobile_Use__c != null

                               group by AccountId]){

          Account a = new Account();

          a.Id = (Id) ar.get('AcctId'); 

          a.active_mobile_users__c = (Integer) ar.get('ContactCount');

          acctsToRollup.add(a);

      }

    try{

       update acctsToRollup;

    }Catch(Exception e){

      System.debug('Exception :'+e.getMessage());

    }

}

 
Requirment is to clone the opportunity with all of the related record information,  contact roles, activity history, ect..  Is this possible and if so how.  This will also need to be used in Lightning
  1. @isTest
  2. public class OpportunityOwnerUpdate_test {
  3.     
  4.     static testMethod void data1(){
  5.         List<Opportunity> Opportunitys = new List<Opportunity>();
  6.         Opportunity a = New Opportunity();
  7.         a.Name = 'myOpportunity';
  8.         a.StageName='Stage 1 - Expressed Interest';
  9.         a.CloseDate=date.today();
  10.         Opportunitys.add(a);
  11.         insert Opportunitys;
  12.          
  13.     
  14.         ApexPages.StandardSetController  sac = new ApexPages.StandardSetController (Opportunitys);
  15.         sac.setSelected([SELECT Id, OwnerId FROM Opportunity LIMIT 2]);
  16.         OpportunityOwnerUpdate aop = new OpportunityOwnerUpdate(sac);
  17.         aop.isSelected = true;
  18.         
  19.       
  20.      aop.updateOpportunity();
  21.              
  22.     }
  23.     
  24.    static testMethod void data2(){
  25.         List<Opportunity> Opportunitys = new List<Opportunity>();
  26.         Opportunity a = New Opportunity();
  27.         a.Name = 'myOpportunity';
  28.         a.StageName='Stage 1 - Expressed Interest';
  29.         a.CloseDate=date.today();
  30.         Opportunitys.add(a);
  31.         insert Opportunitys;
  32.          
  33.     
  34.         ApexPages.StandardSetController  sac = new ApexPages.StandardSetController (Opportunitys);
  35.         OpportunityOwnerUpdate aop = new OpportunityOwnerUpdate(sac);
  36.         aop.isSelected = false;
  37.     }
  38. }
i have a class and trigger that takes a string from a custom field on an account that it is associated with a custom object "Wholesale Pipeline" and places the account name into the account lookup field in the custom object. 
 
public with sharing class addNMLSPipeline 
{
	public void addNMLS(List<Wholesale_Pipeline__c> lstPipeline)
	{
		addNMLSPrivate(lstPipeline);
	}
	private void addNMLSPrivate(List<Wholesale_Pipeline__c> lstPipeline)
	{
		Set<String> accId = new Set<String>();
		for(Wholesale_Pipeline__c accloop : lstPipeline)
			accId.add(accloop.NMLS__c);
		List<Account> lstAcc = new List<Account>([SELECT Id, Name, NMLS_Number__c FROM Account WHERE NMLS_Number__c =: accId LIMIT 1]);
		for(Account accloop2 : lstAcc)
		{
			for(Wholesale_Pipeline__c pipe : lstPipeline)
				if(pipe.NMLS__c != null)
					pipe.Account__c = accloop2.Id;
		}
	}
}

when i update the pipeline object records with a nmls using the data loader i get about 200 records succeed and 800 fail saying "Apex CPU time limit exceeded"

can someone please help me, i have looked at a million links and even other posts that deal with similar problems but dont seem to understand where i have gone wrong. 
 
Hello!

I am trying to write some SOQL so that I can perform some bulk operations on opportunties. However, whenever I run this SOQL I get an error: "unexpected token: AND"

Here is the SOQL:
 
String query2 = 'SELECT Id FROM Opportunity WHERE NOT StageName LIKE \'%'+'closed'+'%\' AND division__c = \'IT Solutions\'';

Here is the System.debug output:
 
SELECT Id FROM Opportunity WHERE NOT StageName LIKE '%closed%' AND division__c = 'IT Solutions'

I am just unsure what is wrong with this SOQL, seems I am escpaing the single quotes correctly... 

Thank you!