function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
d.tejdeep@nicomatic.ind.tejdeep@nicomatic.in 

hi am getting this error to my mail help me to get rid of this error

Developer script exception from Nicomatic : quotepotential : quotepotential: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0Q90000005Q9RWEA0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: [] Trigger.quotepotential: line 17, column 1


caused by: System.DmlException: Update failed. First exception on row 0 with id a0Q90000005Q9RWEA0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []

Trigger.quotepotential: line 17, column 1

 

 

this is my Trigger:

 

trigger quotepotential on Quote_Line_Item__c (after insert,after update) {
    Set<Id> quoteIds = new Set<Id>();
    List<Quote__c> quotes = new List<Quote__c>();
    for(Quote_Line_Item__c record: Trigger.new) {
    if (record.Quote1__c != null){
        quoteIds.add(record.Quote1__c);
    }
    }
    for(AggregateResult ar:[SELECT Quote1__c , SUM(Max_Batch__c)sumMax FROM Quote_Line_Item__c WHERE Quote1__c IN :quoteIds GROUP BY Quote1__c]) {
      Quote__C qu=new quote__c();
      qu.id=(Id)ar.get('Quote1__c');
      qu.Potential__c=(Decimal)ar.get('sumMax');
       quotes.add(qu);
}
if(quotes.isempty() == false)
    {
  update quotes;
  }
}
we have one more button in quote email template at the time click this button i am getting exception to my mail.

the function of quote email template it will send the quote pdf into email which sending to other user
digamber.prasaddigamber.prasad

Hi,

 

I have modified your trigger below. Could you please try this:-

 

trigger quotepotential on Quote_Line_Item__c (after insert,after update) {
    Set<Id> quoteIds = new Set<Id>();
    List<Quote__c> quotes = new List<Quote__c>();
	
    for(Quote_Line_Item__c record: Trigger.new) {
		if (record.Quote1__c != null){
			quoteIds.add(record.Quote1__c);
		}
    }
	
	Map<Id, Quote__c> mapQuote = Map<Id, Quote__c>([Select Id, Potential__c from Quote__c Where Id in: quoteIds]);
	
    for(AggregateResult ar:[SELECT Quote1__c , SUM(Max_Batch__c)sumMax FROM Quote_Line_Item__c WHERE Quote1__c IN :quoteIds GROUP BY Quote1__c]) {
		if(mapQuote.containsKey(Quote1__c)){
			Quote__C qu = mapQuote.get(Quote1__c);
			qu.Potential__c=(Decimal)ar.get('sumMax');
			quotes.add(qu);
		}  
	  

 Let me know if you still see any problem with it.

 

Happy to help you!

 

APEX 123APEX 123

Error: Compile Error: unexpected token: 'Map' at line 11 column 33

 

I am getting error like this

APEX 123APEX 123

trigger quotepotential on Quote_Line_Item__c (after insert,after update) {
Set<Id> quoteIds = new Set<Id>();
List<Quote__c> quotes = new List<Quote__c>();

for(Quote_Line_Item__c record: Trigger.new) {
if (record.Quote1__c != null){
quoteIds.add(record.Quote1__c);
}
}
Map<Id, Quote__c> mapQuote = Map<Id, Quote__c>([Select Id, Potential__c from Quote__c Where Id in: quoteIds]);
for(AggregateResult ar:[SELECT Quote1__c , SUM(Max_Batch__c)sumMax FROM Quote_Line_Item__c WHERE Quote1__c IN :quoteIds GROUP BY Quote1__c]) {
if(mapQuote.containsKey(Quote1__c)){
Quote__C qu = mapQuote.get(Quote1__c);
qu.Potential__c=(Decimal)ar.get('sumMax');
quotes.add(qu);
}
}
if(quotes.isempty() == false)
{
update quotes;
}
}

d.tejdeep@nicomatic.ind.tejdeep@nicomatic.in

 

  Error: Compile Error: unexpected token: 'Map' at line 3 column 29

digamber.prasaddigamber.prasad

Hi,

 

My mistake, missed new keyword. Could you please try below:-

 

trigger quotepotential on Quote_Line_Item__c (after insert,after update) {
	Set<Id> quoteIds = new Set<Id>();
	List<Quote__c> quotes = new List<Quote__c>();

	for(Quote_Line_Item__c record: Trigger.new) {
		if (record.Quote1__c != null){
			quoteIds.add(record.Quote1__c);
		}
	}
	Map<Id, Quote__c> mapQuote = new Map<Id, Quote__c>([Select Id, Potential__c from Quote__c Where Id in: quoteIds]);
	for(AggregateResult ar:[SELECT Quote1__c , SUM(Max_Batch__c)sumMax FROM Quote_Line_Item__c WHERE Quote1__c IN :quoteIds GROUP BY Quote1__c]) {
		if(mapQuote.containsKey(Quote1__c)){
			Quote__C qu = mapQuote.get(Quote1__c);
			qu.Potential__c=(Decimal)ar.get('sumMax');
			quotes.add(qu);
		}
	}
	if(quotes.isempty() == false)
	{
		update quotes;
	}
}

 Let me know if you see any other problem.

 

d.tejdeep@nicomatic.ind.tejdeep@nicomatic.in

hi i have already kept that new before only

 

still i am facing the error it is not taking Quote!__C

 

Variable does not exist: Quote1__c

 

digamber.prasaddigamber.prasad

Hi,

 

Another amendment. Could you please try below:-

 

trigger quotepotential on Quote_Line_Item__c (after insert,after update) {
	Set<Id> quoteIds = new Set<Id>();
	List<Quote__c> quotes = new List<Quote__c>();

	for(Quote_Line_Item__c record: Trigger.new) {
		if (record.Quote1__c != null){
			quoteIds.add(record.Quote1__c);
		}
	}
	Map<Id, Quote__c> mapQuote = new Map<Id, Quote__c>([Select Id, Potential__c from Quote__c Where Id in: quoteIds]);
	for(AggregateResult ar:[SELECT Quote1__c , SUM(Max_Batch__c)sumMax FROM Quote_Line_Item__c WHERE Quote1__c IN :quoteIds GROUP BY Quote1__c]) {
		if(mapQuote.containsKey((ID)ar.get('Quote1__c'))){
			Quote__C qu = mapQuote.get((ID)ar.get('Quote1__c'));
			qu.Potential__c=(Decimal)ar.get('sumMax');
			quotes.add(qu);
		}
	}
	if(quotes.isempty() == false)
	{
		update quotes;
	}
}

 

Please let me know if you still see any problem.

 

d.tejdeep@nicomatic.ind.tejdeep@nicomatic.in

hi thank you for your program it is executing fine .still i am getting execution mails which i posted first unable to LOCK_ROW

the same issue.could you try another possible way to try it out.

 

this program is fine .thankyou for ur help.

 

can you help so that i cannot get the exception mails.

digamber.prasaddigamber.prasad

Hi,

 

Is this error mails coming for same trigger or for some other code?

APEX 123APEX 123

Ya the same Trigger

digamber.prasaddigamber.prasad

Hi,

 

Can you please confirm if Quote records are getting updated as per your requirement?

APEX 123APEX 123

trigger is working fine .i got the replies as try with future method in the triiger

digamber.prasaddigamber.prasad

Hi,

 

Could you please paste the trigger, where you want to call the future method.

APEX 123APEX 123

ya surely i will paste it .i a m on that work only .you need the old trigger which is not modified or the new one 

digamber.prasaddigamber.prasad

Hi,

 

I need both the triggers, one which is working fine and the one which have problem.

APEX 123APEX 123

I will send you soon

APEX 123APEX 123

hi this is the old trigger  i am sending you 

 


trigger quotepotential on Quote_Line_Item__c (after insert,after update) {
Set<Id> quoteIds = new Set<Id>();
List<Quote__c> quotes = new List<Quote__c>();
for(Quote_Line_Item__c record: Trigger.new) {
if (record.Quote1__c != null){
quoteIds.add(record.Quote1__c);
}
}
for(AggregateResult ar:[SELECT Quote1__c , SUM(Max_Batch__c)sumMax FROM Quote_Line_Item__c WHERE Quote1__c IN :quoteIds GROUP BY Quote1__c]) {
Quote__C qu=new quote__c();
qu.id=(Id)ar.get('Quote1__c');
qu.Potential__c=(Decimal)ar.get('sumMax');
quotes.add(qu);
}
if(quotes.isempty() == false)
{
update quotes;
}
}

 

this was the new trigger with future method but not working 

 

trigger quotepotential on Quote_Line_Item__c (after insert,after update) {
Set<id> uniqueNames=new Set<id>();
for(Quote_Line_Item__c a :Trigger.new) {
if(a.IsFutureContext__c) {
a.IsFutureContext__c = true;
} else {
uniqueNames.add(a.id);
}
}
if(!uniqueNames.isEmpty())
asyncApex.processAccounts(uniqueNames);
}

 

global class asyncApex {
@future
public static void processAccounts(set<id> id) {
Set<Id> quoteIds = new Set<Id>();
List<Quote__c> quotes = new List<Quote__c>();
for (Quote_line_item__c a : [Select Id, Name, IsFutureContext__c From Quote_line_item__c where ID IN :ID]) {
a.IsFutureContext__c = true;
if (a.Quote1__c != null){
quoteIds.add(a.Quote1__c);
}
for(AggregateResult ar:[SELECT Quote1__c , SUM(Max_Batch__c)sumMax FROM Quote_Line_Item__c WHERE Quote1__c IN :quoteIds GROUP BY Quote1__c]) {
Quote__C qu=new quote__c();
qu.id=(Id)ar.get('Quote1__c');
qu.Potential__c=(Decimal)ar.get('sumMax');
quotes.add(qu);
}
if(quotes.isempty() == false)
{
update quotes;
}
}
}
}

 

can you correct this one .

digamber.prasaddigamber.prasad

Hi,

 

Keeping your trigger unchanged, could you please try below version of async class:-

 

global class asyncApex {
	@future
	public static void processAccounts(set<id> id) {
		Set<Id> quoteIds = new Set<Id>();
		List<Quote__c> quotes = new List<Quote__c>();
		for (Quote_line_item__c a : [Select Id, Name, IsFutureContext__c From Quote_line_item__c where ID IN :ID]) {
			a.IsFutureContext__c = true;
			if (a.Quote1__c != null){
				quoteIds.add(a.Quote1__c);
			}
			Map<Id, Quote__c> mapQuote = new Map<Id, Quote__c>([Select Id, Potential__c from Quote__c where Id in :quoteIds]);
			for(AggregateResult ar:[SELECT Quote1__c , SUM(Max_Batch__c)sumMax FROM Quote_Line_Item__c WHERE Quote1__c IN :quoteIds GROUP BY Quote1__c]) {
				if(mapQuote.containsKey(Quote1__c)){
					Quote__C qu=new mapQuote.get(Quote1__c);
					qu.Potential__c=(Decimal)ar.get('sumMax');
					quotes.add(qu);
				}
			}
			if(quotes.isempty() == false)
			{
				update quotes;
			}
		}
	}
}

 Let me know if you still see error.

 

Happy to help you!

 

 

APEX 123APEX 123

sorry .i am not the value for potential.any different idea

APEX 123APEX 123

I am not getting the value of potential in this program can any crack this error?

the previous program i am getting error too many future call 11.like this i am getting the error while deploying .then i converted my code in this way .it is not calculating the potential value. can you crack it where it went wrong?



Trigger :

trigger quotepotential on Quote_Line_Item__c (after insert, after update) {
    if(System.isFuture()) {
        return;
    }
    asyncApex.processAccounts(Trigger.newMap.keySet());
}

class :

global class asyncApex {
    @future public static void processAccounts(Set<Id> quoteIds) {
        Map<Id, Quote__c> quotes = new Map<Id, Quote__c>();
        for(Id quoteId: quoteIds) {
            quotes.put(quoteId, new Quote__c(Id=quoteId, Potential__c=0.0));
        }
        for(AggregateResult ar:[SELECT Quote1__c Id, SUM(Max_Batch__c) sumMax FROM Quote_Line_Item__c WHERE Quote1__c IN :quoteIds GROUP BY Quote1__c]) {
            quotes.get((Id)ar.get('Id')).Potential__c = (Decimal)ar.get('sumMax');
        }
        update quotes.values();
    }
}