• Alexander Tsitsura
  • PRO
  • 2367 Points
  • Member since 2014
  • Salesforce Developer
  • Softheme


  • Chatter
    Feed
  • 56
    Best Answers
  • 0
    Likes Received
  • 3
    Likes Given
  • 2
    Questions
  • 322
    Replies
Can someone give me detailed references/articles of how triggers work in asynchronous apex. in normal synchronous apex trigeers inserts records in the batch count of 200s each for every iteration. mean 1000 rows go in 5 batches. what happens in asynchronous processing. If i have a queueable inserting 1000 rows how they are processed.
Can someone give me detailed references/articles of how triggers work in asynchronous apex. 

Hi everyone!

I'm trying to validate a Event field with a trigger. I'm using a trigger because it's dependent on values in the Account object. I want to show the user an error with sObject.addError() method. The test scenarios in the Salesforce GUI for 1 record at a time is working fine however the test class is failing. I'm creating 200 event records and inserting them at the same time. 

/*test class*/
try{
insert eventList;
 }
catch (Exception e) {
System.assert(e.getMessage().contains('The error message that should be shown'), e.getMessage());
 }

/*Event handler method*/
public void displayErrorMessage(List<Account> accountList){
      for (Account acc : accountList){
             if(acc.Type == 'Agency')
                eventMap.get(acc.Id).WhatID.addError('The error message that should be shown', false);
      }
}

/*Trigger*

trigger EventBefore on Event (before insert, before update) {
      if(Trigger.isInsert || Trigger.isUpdate){
          Event_TypeOfMeetingHandler handler = new Event_TypeOfMeetingHandler( trigger.new );
      }
}

THIS IS THE ERROR MESSAGE I'M GETTING:

 
Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Too many retries of batch save in the presence of Apex triggers with failures: when triggers are present partial save requires that some subset of rows save without any errors in order to avoid inconsistent side effects from those triggers. Number of retries: 2: []

THE TEST WORKS FINE FOR THE FOLLOWING TRIGGER CODE. INSERT ONLY THOUGH.  
trigger EventBefore on Event (before insert) {
      if(Trigger.isInsert){
          Event_TypeOfMeetingHandler handler = new Event_TypeOfMeetingHandler( trigger.new );
      }
}

What am I doing wrong in the Trigger handler alternative what can I do in the test class to make this work for multiple insert and updates on  Event records? 

Thanks!

public class accountprioritysort {
    public list<Company_Priorities__c> acts {set;get;}
    public accountprioritysort (){
        acts = [select Field1__c,Account_Priorities__c from Company_Priorities__c];
    }    
}

The Field1__c (has priority number) so i want to have the SOQL with where condition, that i want to display all the first 5 records which have Field1__c with numbers. Please see the below screen shot. Your help is really appreciated.

 

Priority

Hi ,
 i have uplaoded the java script  file in staticresoure.  iam getting the pop up correctly. but  ih ave written the function in that file which will return multiplication of 2 numbres . Please suggest me how to display the value returned form the java script.

my ststic resource code is,

function popup() { alert("Hello World") }
function myFunction(a, b) {
    return a * b;


 And the vf code is,

<apex:page >

<html>

<head>
<apex:includeScript value="{!$Resource.jsss}"/>

</head>
</html>

<script type="text/javascript" >
popup()

 myFunction(4,5);
 
 
 

</script>

<apex:pageBlock>


</apex:pageBlock>
</apex:page>
   
Any body suggest me aboutthis.


Regards,
Siva.

 
We have a visualforce 'edit' page for a custom object. The variable is stored in a String (eg: " a;b;c"). I want to be able to pull the saved values and preselect them on a multi selectList so users don't have to reselect the old values when editing. 

value = [select ....];

<apex:selectList value="{!value}" size="3" multiselect="true" label="blah" id="blah" >
                        <apex:selectOptions value="{!options}" />
                    </apex:selectList>

I've tried string format and String[] list format for 'value' and neither gets me any default selected values for this select list. 

Hi,

I have a dynamically created Opportunity where i assign values according to some formula:
 

Opportunity opp = new Opportunity(Name='SomeName', Amount=2000, Probability=20);
Whatever the values might be.

Then i convert it to a JSON String:

return JSON.serialize(opp);



My problem here is: The JSON String only contains the Values used/assigned by me. That would be Name, Probability, Amount.

Result: 

{"Name":"SomeName", "Probability":"20", "Amount":"2000"}

But I need it to also contain ExpectedRevenue, which is calculated by Probability*Amount. It is a read-only field, so i cannot set it in the code.

Desired Result:

{"Name":"SomeName", "Probability":"20", "Amount":"2000", "ExpectedRevenue":"400"}
How can i accomplish this?
I am writing an controller and VF component to email opportunitylineitemschedule details as an attachment. I am able to include schedule details to the attachment, but i am not able to include the opportunitylineitem's field in the same table. 

My requirement - for each line item schedule row, i would like to have one column populating the opportunitylineitem.Product_Name__c values. I am getting unknown property error 'String.Product_Name__c' if i try to add this field. 
my controller: 
public class emailtemplatev2{
    public emailtemplatev2() {    
    }
  List<OpportunityLineItemSchedule> revenue = new List<OpportunityLineItemSchedule>(); 
   public Id opportunityId {get;set;} 
   public List<OpportunityLineItemSchedule> getrevenue()
   { 
       revenue=[Select OpportunityLineItemId, CurrencyIsoCode, ScheduleDate,Revenue                           
                 from OpportunityLineItemSchedule where OpportunityLineItemId IN (Select ID from OpportunityLineItem 
                 where OpportunityId =:opportunityid )  ];
     return revenue;
        }  
}


VF Component: 
<apex:component controller="emailtemplatev2" access="global">
    
   
    <apex:attribute name="AcctId" type="Id" description="Id of the account" assignTo="{!opportunityId}"/>
    <table border = "2" cellspacing = "0" >
        <tr>
            <td>Product</td>
            <td>Forecast Period</td>
            <td>Currency</td>   
            <td>Amount</td> 
                         
        </tr>
        <apex:repeat value="{!revenue}" var="o">
        <tr>
            <td>{!o.OpportunityLineItemId.Product_Name__c}</td> //having issue in this line
            <td>   
            <apex:outputText value="{0,date,MMM, yyyy}">
            <apex:param value="{!o.ScheduleDate}" /> 
            </apex:outputText>
            </td>  
        
            <td>{!o.CurrencyIsoCode}</td>  
            <td>{!o.Revenue}</td> 
                        
        </tr>
        </apex:repeat>        
    </table>
</apex:component>


 
I have been looking at other posts for my questions on how Apex batch works when there is an Error. Somehow I am not able to clear my self. I have couple of questions. Can someone please clarify.

1. Assume a batch process has 3 iterations processing 200 records each. The batch process is doing an insert and I am using Database.Insert with AllorNone parameter set to False. Assume there was an error during the second iteration while processing 101 record.I understand that all the records in the first iteration will be committed and also the 100 records in the second iteration. My question is will the batch process continue to process other records in the second iteration and also the third iteration.

2. Assume all the 3 iterations (execute method) completed without any error but some error occured in the Finish method. Finish method just sends an email. How does this work, considering that I am using Database.Insert and AllorNone parameter set to False. My understanding is that all the records will be committed to the database but user will not be receiving email that the batch was successfull or not. I am confused how this scenario will work in the real time.
Hi,
I have trigger calling an external Api once an account is updated, I don't have any DML in the trigger and
I'm calling a handler and assigning @future(callout = true) for the method calling the external Api
but having this issue:
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out*
I have deactivated the workflow assigned to account but still having this issue
and don't see how to debug it even after looking to the developer logs
any thoughts please how to debug this issue ?
Hello there,

I have triggers on Contact and User objects. Contact trigger updates user record in future method. The user trigger on the other hand updates related contact in future method.

As future method is an asynchronous apex, I cannot track the execution using static variable. Is there any standard way that my scenario can be handled?

Thanks in advance.
Hi,

Where can I get all img icon of salesforce?
I am using the following site.
http://blogforce9dev-developer-edition.ap1.force.com/salesforceicons
But I need such as chalkboard icon that used when custom tab created.
Is there other site?

Regards,
LinThaw

by the way I want to use icon something like this...
<apex:pageblock id="ContactRecord" >
   
    <apex:facet name="header">
        <apex:panelGrid columns="1" width="100%" columnClasses="colstyleLeft,colstyleRight">
            <div class="pbTitle" style="width:100%;padding-left:0px;padding-top:0px;">
                <img src="/img/icon/computer24.png" class="relatedListIcon" style="width:24px;display:block;" />
                <h3 class="mainTitle">&nbsp;Title1</h3>
            </div> 
    </apex:facet>  

    ...

 </apex:pageblock>
Thanks.




 
I have a query inside a trigger and one of the conditions is that a reference field (lookup) is not null. My query is:
List<Contract> contratti=[Select Id,Opportunitl__c from Contract 
        where Id IN: Trigger.new AND Opportunitl__c !=null ];

where Opportunitl__c is the reference field, but it's not working. The list "contratti" contains Contracts with an empty Opportunitl__c. What is wrong in this query?
Hi All,

I need to return the values from apex class to batch class. The below code throws constructor not defined. Can any one let me know how to pass list of inserted accounts to batch class.
 
public with sharing class CalloutBatchApex implements Database.Batchable<Integer>, Database.AllowCallouts {
    public Iterable<String> start(Database.BatchableContext BC) {
        return new List<Integer> { 1, 2, 3 };
    }
 
    public void execute(Database.BatchableContext info, List<integer> iteration) {
        // Make the callout to the web service and import the records to Salesforce for the iteration.
       String responseStrng = response.getBody();
        insertAccountMethod.methodone(responseStrng);
    }
 
    public void finish(Database.BatchableContext info) {}
}

//Calling Apex class here

public class insertAccountMethod{
   List<Account> accList = new List<Account>();
         public methodone(String responseStrng){
         //my code here
         I need to return the above accList to batch class.I have tried with the below line
          
         CalloutBatchApex c = new CalloutBatchApex();
         DataBase.execute(c,1);

        }
}

Thanks
​Arjun
Hi All,

I need to return the values from apex class to batch class. The below code throws constructor not defined. Can any one let me know how to pass list of inserted accounts to batch class.
 
public with sharing class CalloutBatchApex implements Database.Batchable<Integer>, Database.AllowCallouts {
    public Iterable<String> start(Database.BatchableContext BC) {
        return new List<Integer> { 1, 2, 3 };
    }
 
    public void execute(Database.BatchableContext info, List<integer> iteration) {
        // Make the callout to the web service and import the records to Salesforce for the iteration.
       String responseStrng = response.getBody();
        insertAccountMethod.methodone(responseStrng);
    }
 
    public void finish(Database.BatchableContext info) {}
}

//Calling Apex class here

public class insertAccountMethod{
   List<Account> accList = new List<Account>();
         public methodone(String responseStrng){
         //my code here
         I need to return the above accList to batch class.I have tried with the below line
          
         CalloutBatchApex c = new CalloutBatchApex();
         DataBase.execute(c,1);

        }
}

 
I have an apex class that copies data from a custom field on the close case screen  into case comments when the case is closed, however it is creating the comments twice each time.  Can anyone tell me why it is doing this and how I can fix it?  Below is the apex class;

public without sharing class CaseManagement {
    
    //*****************************************************************************
  //Method called on after update of Case
  //****************************************************************************/
  public static void onAfterUpdate(List<Case> lstCase, Map<Id, Case> oldMap){ 
    checkCloseCase(lstCase, oldMap);   
  } 

  //*****************************************************************************
  //Method called to check the Close Case
  //****************************************************************************/
  public static void checkCloseCase(List<Case> lstCase, Map<Id, Case> oldMap) { 
    
    List<CaseComment> comments = new List<CaseComment>();
               
    for(Case caseUpdate : lstCase) {
            
      if( caseUpdate.Case_Close_Notes_To_Customer__c != null && caseUpdate.Case_Close_Notes_To_Customer__c != oldMap.get(caseUpdate.Id).Case_Close_Notes_To_Customer__c) {
        comments.add( new CaseComment(CommentBody = caseUpdate.Case_Close_Notes_To_Customer__c, IsPublished = false, ParentId = caseUpdate.Id));
      }
    }
    insert comments;
  }
}
Hi all,

global class batchprocessdesc implements Database.Batchable<sObject>
{

    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'select id from Account';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Account> accounts)
    {
        list<Entitlement> ents = [select AccountId, id, Product_Family__c, EndDate from Entitlement where AccountId IN :accounts ORDER BY AccountId,Product_Family__c,EndDate DESC];
        //Map<Id, Entitlement> pfmap= new Map<Id, Entitlement>(ents);
       
        map<Product_Family__c,EndDate> PFMAP = new map<Product_Family__c,EndDate>(ents); // Error: Compile Error: Invalid type: EndDate at line 15 column 74

        for (Entitlement objent: ents)
        {
          
           pfmap.put('Product_Family__c','EndDate');

        }
        
    } 
    global void finish(Database.BatchableContext BC)
    {
    }
}
I am new and I just need a basic video showing me how this works.  Each video I find shows a different home page.  It looks nothing like my home page in salesforce.  Where do I find a basic video??!!???  I am very fustrated, I have called Salesforce TWICE to ask this question.
Hello,

I have written a test class, for code coverage.
the code coverage is not proper for a fucntion.
it accepts no paramenters.
but it stop inside for loop.
i am making query inside for loop and it doesnt not enter this loop,whe i execute the query it is passing

User-added image

Any suggestion