• rahulsharma
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies

Hello guys,

 

I am able to created JSON data from records.

Can we create JSON data for parent child relation(records) dynamically using apex.

 

Thanks in advance.

Hello guys,

 

I was just wondering about it.

Can we upload/show a video in VF page.

If yes then please tell me the methods for the same.

 

Thanks in advance.

Rahul Sharma

Hello everyone,

I'm currently working on Approval process but had stuck at a point any help will be highly appreciated,

I just want to avoid multiple pending status for a record.

Means if a record is waiting for to be 'Approved/Rejected' with status as 'pending', and if I again click 'Submit for Approval' button,

then it's previous status should be 'rejected' and record should be again send for approval.

Thanks

Hello Everyone,

Im facing problem with date.

i want to send records to batch apex filtered by createddate, but facing error as  "no viable Character".

as its from Class or Trigger, i can filter it by putting IF condition's in batch but that will be a long way.

so, Is there a way to do this: To filter the records in Query itself which we are sending to batch (String format)

 

Thanks & Regards

Rahul

Hello,

I'm facing problem with Batch..

Two batches are called one after another .. such that final result of first batch is providing data to second Batch,

My Code is working if its an Ideal condition, i.e. second batch starts after first batch is fully executed..

but if second batch executes while first is still executing then it creates problem..

So my problem is that, i want to control the execution of second batch..

im already using other schedulars so im trying to avoid it....

is there any way to monitor batch jobs means to put conditions on when second batch executes

Thank You

 

trigger CreateAccountContact on Opportunity (after insert, after update,before Delete)
{
List<Account__c> accList=new List<Account__c>();
List<Contact__c> conList=new List<Contact__c>();
List<Lead__c> l=new List<Lead__c>();
//List<Opportunity__c> OppList=new List<Opportunity__c>();
for(Opportunity__c Opp:trigger.new)
{
if(Opp.Stage__c=='Closed Won') 
 {
Opportunity__c objopp =[select Lead__c from Opportunity__c where id =:Opp.id];
Lead__c objlead = [select First_Name__c,Company__c,Last_Name__c,Email__c from Lead__c where id=:objopp.Lead__c];
Account__c ac=new Account__c(Company__c=objlead.Company__c);
accList.add(ac);
Contact__c con=new Contact__c(Last_Name__c=objlead.Last_Name__c,First_Name__c =objlead.First_Name__c,Email__c=objlead.Email__c);   // map the other fields of lead to contact as you required
conList.add(con);    
//l=[select id,name,Company,LastName,Email from Lead where id=:objopp.Lead__c];
//Opportunity objopp1=new Opportunity(Description=objlead.Name);
//OppList.add(objopp1);
  }  
 } 
 insert accList;
 insert conList;
 //update OppList;
 
  Delete l;
 
 
}

trigger CreateAccountContact on Opportunity (after insert, after update,before Delete){List<Account__c> accList=new List<Account__c>();List<Contact__c> conList=new List<Contact__c>();List<Lead__c> l=new List<Lead__c>();//List<Opportunity__c> OppList=new List<Opportunity__c>();for(Opportunity__c Opp:trigger.new){if(Opp.Stage__c=='Closed Won')  {Opportunity__c objopp =[select Lead__c from Opportunity__c where id =:Opp.id];Lead__c objlead = [select First_Name__c,Company__c,Last_Name__c,Email__c from Lead__c where id=:objopp.Lead__c];Account__c ac=new Account__c(Company__c=objlead.Company__c);accList.add(ac);Contact__c con=new Contact__c(Last_Name__c=objlead.Last_Name__c,First_Name__c =objlead.First_Name__c,Email__c=objlead.Email__c);   // map the other fields of lead to contact as you requiredconList.add(con);    //l=[select id,name,Company,LastName,Email from Lead where id=:objopp.Lead__c];//Opportunity objopp1=new Opportunity(Description=objlead.Name);//OppList.add(objopp1);  }   }  insert accList; insert conList; //update OppList;   Delete l; 
 }

 

Hi, 

 

I am having trouble getting this query working in a batchable class. 

 

In my start method when I use the following query : 

 

 

String query = 'Select a.Id, a.Name, a.OwnerId ,(Select Id, OwnerId From Contacts) from Account a Where a.Type IN: '+ accTypesToInclude ;
 return Database.getQueryLocator(query);

 

 

I am getting the error :

 

System.QueryException: unexpected token: '(' 

 

Any ideas whats wrong

 

Thanks

Hello:

 

I am creating a list button to mass create new opportuies based on records from a custom object.  I am in a bind to get this into production early next week and would appreciate the communities help...

 

We have a policy sales record (PSR) custom object  and need to create renewal opportunities from selected records in a policy sales record  list view.  I have very little Javascript knowledge but using several postings from the boards & blogs I came up with the following code that throws the following error after selecting the policies in the view and clicking on the button to execute.  

 

When clicking onthe button we want to create new opportunities of a specific record type and prepopulate sevaral key records from the values on the policy sales record.

 

 

Error message in a windows  dialog box:
A problem with the OnClick JavaScript for this button or link was encountered:
unterminated string literal
I have reviewed the code and cannot find where these error seems to be coming from as the code in my limited knowledge seem properly formed.
Also, I am not sure if the insert portion is the correct syntax for Javascript to push the insert of the new records.

 

 

Here is the code for my button:

 

 

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}    //adds the proper code for inclusion of AJAX toolkit
var url = parent.location.href;    //string for the URL of the current page
var records = {!GETRECORDIDS($ObjectType.Policy_Sales_Record__c)};    //grabs the Policy Sales Records records that the user is requesting to update
var CreateNewRecords = [];    //array for holding records that this code will ultimately update

if (records[0] == null) { //if the button was clicked but there was no record selected
	alert("Please select at least one record to update.");    //alert the user that they didn't make a selection 
} else {   //otherwise, there was a record selection
	for (var a=0; a<records.length; a++) {    //for all records
		var create_new_opportunity = new sforce.SObject("opportunity");    //create a new sObject for storing updated record details
		create_new_opportunity.RecordTypeId = "012A0000000R4UX";    //set the record type to Renewal Opportunities
		create_new_opportunity.AccountId = "{!Policy_Sales_Record__c.Account__c}";    //set the account ID value from PSR 
		create_new_opportunity.Closedate = "{!Policy_Sales_Record__c.Policy_Renewal_Date__c}";     //set the value for renewal date from policy data
		create_new_opportunity.OwnerId = "{!Policy_Sales_Record__c.Account_Owner__c}";    //set the value for account owner
		create_new_opportunity.Primary_Producer__c = "{!Policy_Sales_Record__c.Producer__c}";    //set the value for the producer
		create_new_opportunity.Renewal_Base_Premium__c = "{!Policy_Sales_Record__c.Renewal_Base_Premium__c}"
		create_new_opportunity.Renewal_Base_No_of_Contracts__c = {!Policy_Sales_Record__c.Renewal_Base_No_of_Contracts__c}";

		CreateNewRecords.push(create_new_opportunity);   //add the updated record to our array
	}
	result = sforce.connection.insert(CreateNewRecords);    //insert new records into to Salesforce
	parent.location.href = url; //refresh the page
}

 

 

Regards and thanks in advance

 

Quique

 

Hi,

 

i have a trigger on Opportunity that fires "after Update" operation and whenever opportunity stage is "Won".

Also, i have a workflow that is being executed , which updates 5 fields whenever stage of the opportunity is set to "Won".

 

Due to this workflow update, the trigger is fired again. How can i stop this from happening?

 

1 thing i can think is:

create  another field (preferably check box) and also update this field to "True" as part of workflow update.

And in my trigger check for the field status as "false".

 

Any other way we could accomplish this without creating a field?

 

Your help is highly appreciated.

 

Trigger code:

 

trigger createEntitlement on Opportunity (after update) {
  
  List<Entitlement> newEntitlement=New List<Entitlement>();
  Set<Id> oppIds=New Set<Id>();
  
  for(Opportunity op : Trigger.New){
    
    if(op.StageName=='Won' && Trigger.oldMap.get(op.Id).StageName!='Won')
      oppIds.Add(op.Id);
  }
  
  List<Opportunity> oppty=[Select Id,Name,AccountId,CloseDate,Contract_Activation_Date__c From Opportunity Where Id IN:oppIds];
  System.Debug('List Size=='+oppty.size());
  for(Integer i=0;i<oppty.size();i++){
    
    Entitlement ent=New Entitlement();
    String name='Entitlement For-';
    ent.Close_Date__c=oppty[i].CloseDate;
    ent.Contract_Activation_Date__c=oppty[i].Contract_Activation_Date__c;
    ent.AccountId=oppty[i].AccountId;
    ent.Name=name+oppty[i].Name;
    //ent.Status='Active';
    ent.Opportunity__c=oppty[i].Id;
    newEntitlement.Add(ent);
    
  }
  System.debug('Entitlement Size=='+newEntitlement.size());
  Database.insert(newEntitlement);

}

 

Thanks,

Sales4ce

I am running into the governor limit issue since I have the SQls inside the for loop. I am trying to optimize the code to get the case and owner information outside the for loop.

 

New to Apex development. Would appreciate some pointers on writing efficient SOQls outside the For loop in a trigger.

 

/* Trigger logic.. If transportation case type, and status = "awaiting internal response, case creator alias = "CS agents" and case owner = regional call center, MVC agent field = TASR agent, then assign then case back to the MVC agent *./

'

 

trigger TR_2 on Case (before update) {
   Case[] cases = Trigger.new;
   for (Case a:cases){ 
    string creatorid;
    string casecreatoriwdalias;
      String caseowner;
    string iWdAliasCaseOwner;
    String caseno;
    String err_msg = '';
    String MVCowner;
      String iWDMVCOwner;
                     
             creatorid = a.CreatedById;
          caseno = a.CaseNumber;
          
          case c = [select ownerid from case where casenumber = :caseno limit 1];
           caseowner = a.ownerid;
          MVCowner  = a.MVC_Owner__c;
    
         // get user alias information for the case creator   
    User userinfor = [select alias, iWD_Alias_Case_Owner__c, Iwd_Case_Creator__c from User where id = :creatorid];
    casecreatoriwdalias = userinfor.Iwd_Case_Creator__c;
    
      if (caseowner.substring(0,3) == '005'){
    // get case owner alias information
    User caseowneruserinfor = [select alias, iWD_Alias_Case_Owner__c, Iwd_Case_Creator__c from User where id = :caseowner limit 1];
    iWdAliasCaseOwner = caseowneruserinfor.iWD_Alias_Case_Owner__c;
     
     // check for status and SRCL Transportation record type and case owner and case creator alias
        if ((a.STATUS == 'Awaiting Internal Response'&& a.RecordTypeID == '012300000004rDZ')&& 
            (casecreatoriwdalias =='CAS' ||casecreatoriwdalias =='TASR/P1')&& 
                 (iWdAliasCaseOwner == 'DISP'|| iWdAliasCaseOwner == 'RCC'))  {
       a.IWD_Testing__c = 'trigger 2 enter the loop'; 
          }// status 'internal response'
                   
   if ((a.STATUS == 'Closed'&& a.RecordTypeID == '012300000004rDZ')&& 
            (MVCowner =='CAS' ||MVCowner =='TASR/P1')&& 
                 (iWdAliasCaseOwner == 'DISP'|| iWdAliasCaseOwner == 'RCC'))  {
       a.IWD_Testing__c = 'trigger2 working!!'; 
       a.ownerid = creatorid;  
       a.status = 'Awaiting internal response';   
        }// status 'closed'
                    } //if case owner 
      }// FOR LOOP
} // EOF

  • September 29, 2010
  • Like
  • 0

Hi ,

 

I have written a batch apex to create/update  custom object records. I have two custom objects Purchase_Sales_Report__c and Portfolio_Report__c. Portfolio_Report__c is basically a summary of Purchase_Sales_Report__c records based on a Unique Key. They are both child of the Account object.

 

Every day I get a feed of Purchase_Sales_Report__c objects and based on those records I either need to create a new Portfolio_Report__c record or update the existing record based on a Unique key.

 

In the Database.queryLocator I send all the Purchase_Sales_Report__c records but inorder to update the existing Portfolio_Report__c report, I also require a list of all the existing Portfolio_Report__c records where I face an issue of 'Too many query rows 100001' as the number of records returned is more than 10 k.

 

here is my piece of code. The one in red is where I get an error,

 

 

global class CreateSummaryReport implements Database.Batchable<sObject>, Database.Stateful {
    global String query; 
    global Map<String, Portfolio_Report__c>  existingPortMap = new Map<String, Portfolio_Report__c>();
    global Map<String, Double> purchaseAmountMap = new Map<String, Double>();
    global Map<String, Double> productMap = new Map<String, Double>();
    global Map<String, Double> unitsMap = new Map<String, Double>();
    global Map<String, Purchase_Sales_Report__c> otherDetailsMap = new Map<String, Purchase_Sales_Report__c>();
    global String email;
    
    global CreateSummaryReport(){
        for(Portfolio_Report__c por: [Select Gain__c, 
                                            Units_Quanitity__c,
                                            Scheme_Scrip_Name__c, 
                                            Purchase_Amount__c, 
                                            Portfolio_Type__c, 
                                            Folio_Number__c, 
                                            Current_Value__c,
                                            Absolute_Ret__c,
                                            Annualized_Ret__c, 
                                            UniqueName__c,
                                            Dividend_Reivestment__c,
                                            Transaction_Type__c,
                                            Nav_p__c
                                            From Portfolio_Report__c] ){
            existingPortMap.put(por.UniqueName__c, por);
            
        }
        //email = email;
    }
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<sObject> scope){
       
        for(sObject s: scope){
            Purchase_Sales_Report__c ps = (Purchase_Sales_Report__c)s;
            if(purchaseAmountMap.containsKey(ps.Unique_Name__c)){
            	if(ps.Amount__c != null){
	        		Double d = ps.Amount__c + purchaseAmountMap.get(ps.Unique_Name__c);
	                purchaseAmountMap.put(ps.Unique_Name__c, d);
            	}
            	                
            }
            else {
                   if(ps.Amount__c == null)
                   {
                   		ps.Amount__c = 0;
                   }
                purchaseAmountMap.put(ps.Unique_Name__c, ps.Amount__c);
            }
            if(productMap.containsKey(ps.Unique_Name__c)){
            	if(ps.Product__c != null) {
	                Double d = ps.Product__c + productMap.get(ps.Unique_Name__c);
	                productMap.put(ps.Unique_Name__c, d);
            	}
                
            }
            else {
                  if(ps.Product__c == null)
                  {
                  	ps.Product__c = 0;
                  }
                productMap.put(ps.Unique_Name__c, ps.Product__c);
            }
            if(unitsMap.containsKey(ps.Unique_Name__c)){
            	if(ps.Units__c != null){
	                Double d = ps.Units__c + unitsMap.get(ps.Unique_Name__c);
	                unitsMap.put(ps.Unique_Name__c, d);
            	}
                
            }
            else {
                  if(ps.Units__c == null)
                  {
                  	ps.Units__c = 0;
                  }
                unitsMap.put(ps.Unique_Name__c, ps.Units__c);
            }
            if(!otherDetailsMap.containsKey(ps.Unique_Name__c)){
                otherDetailsMap.put(ps.Unique_Name__c, ps);
            }
        }
        
    }
    global void finish(Database.BatchableContext BC){
        List<Portfolio_Report__c> updateList = new List<Portfolio_Report__c>();
        List<Portfolio_Report__c> newList = new List<Portfolio_Report__c>();
        
        for(String s: purchaseAmountMap.keySet()){
            if(existingPortMap.containsKey(s)){
                Portfolio_Report__c pr = existingPortMap.get(s);
                pr.Purchase_Amount__c = purchaseAmountMap.get(s);
                pr.Product__c = productMap.get(s);
                pr.Units_Quanitity__c = unitsMap.get(s);
                updateList.add(pr);
            }
            else {
                Portfolio_Report__c pr = new Portfolio_Report__c(UniqueName__c=s, 
                                                                 Scheme_Scrip_Name__c=otherDetailsMap.get(s).Scheme_Name__c,
                                                                 Folio_Number__c = otherDetailsMap.get(s).Folio_Number__c,
                                                                 Entity__c = otherDetailsMap.get(s).Entity__c,
                                                                 Product__c = productMap.get(s),
                                                                 Units_Quanitity__c = unitsMap.get(s),
                                                                 Purchase_Amount__c = purchaseAmountMap.get(s));
                newList.add(pr);
            }
        }
        
        insert newList;
        update updateList;
        
        AsyncApexJob a = [Select Id, 
                                 Status,
                                 NumberOfErrors, 
                                 JobItemsProcessed,  
                                 TotalJobItems, 
                                 CreatedBy.Email 
                                 from AsyncApexJob 
                                 where Id =:BC.getJobId()];
        // Create and send an email with the results of the batch.
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(new String[] {email});
        mail.setReplyTo('tech@ffreedom.in');
        mail.setSenderDisplayName('Batch Processing');  
        mail.setSubject('Detailed Portfolio Report Update ' + a.Status);
        mail.setPlainTextBody('The batch apex job processed ' + a.TotalJobItems +   ' batches with ' + a.NumberofErrors + ' failures.');
    
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}

 

Can someone please give me a workaround for this?

 

Many Thanks,

Jina