• Prashant Tiwari
  • NEWBIE
  • 30 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 23
    Replies

Hi,

 

I'm doing a HTTP Callout from a trigger on a specific object. The trigger basically runs when a record is updated and checks online for related records.

 

I thought I had worked it out but I'm getting an error of:

 

System.ListException: Before Insert or Upsert list must not have two identically equal elements

here is my code basically it should go off to an external site - then grab the xml response - then go through an create a new record for each child element based on my if statements and also fill in the a lookup field with the record id the the trigger was initiated from.

 

i think it's because of how i'm grabbing the recordid and formid at the beginning but am not sure.

 

public class MonitoringQuestionsUpdater {
  @Future(callout=true)
  public static void updateMQ() {
    List<Monitoring_Form__c> mfcs = [SELECT Id, Form_Id__c FROM Monitoring_Form__c]; 
    for(Monitoring_Form__c a:mfcs){
    string formid = a.form_id__c;
    string recordid = a.id;
    Http http = new Http();
    HttpRequest req = new HttpRequest();
    req.setEndpoint('https://magpi.com/api/questions?username=myusername&accesstoken=mytoken&surveyid='+formid);
    req.setMethod('POST'); 
    HTTPResponse res = http.send(req);
    System.debug(res.getBody());
    List<Monitoring_Questions__c> newquestions = new List<Monitoring_Questions__c>();
    set<string> existingmQuestSetId = new set<string>();
 //iterate thru the existing mforms and add allthe form_id__c in a set. And then use this set to later check for duplicates
 for(monitoring_questions__c mquest: [SELECT Id, questionid__c FROM Monitoring_Questions__c]){
    existingmQuestSetId.add(mquest.questionid__c);
 }
    string s = res.getBody();
    Dom.Document docx = new Dom.Document();
        docx.load(s);
        dom.XmlNode xroot = docx.getrootelement();
        dom.XmlNode [] xrec = xroot.getchildelements(); //Get all Record Elements
        for(Dom.XMLNode child : xrec)
            {
        for(dom.XmlNode magpi : child.getchildren() ) {
           Monitoring_Questions__c mq = new Monitoring_Questions__c();
           if (magpi.getname() == 'Id') {
           System.debug(magpi.getname() == 'Id');
                   mq.QuestionID__c = magpi.gettext();
             }
           if (magpi.getname() == 'Prompt') {
           System.debug(magpi.getname() == 'Prompt');
                   mq.Question_Prompt__c = magpi.gettext();
             }
           if (magpi.getname() == 'Name'){
           System.debug(magpi.getname() == 'Name');
                  mq.Question_Name__c = magpi.gettext();  
         }
         mq.monitoring_form__c = recordid;
        if(!existingmQuestSetId.contains(mq.questionid__c)){
            Newquestions.add(mq);
                }
            }
        }
        insert newquestions;
      }
    }
}

 

any help is appreciated.

 

dan

 

Hi Experts,

Hope u all are doing good !

I am running a batch class however I see that after processing some batches the batch class execution ends with the error "Batchable instance is too big:". I tried executing the batch class by passing the smaller batch size (like 10,50, etc..) and also not implementing database,stateful, still facing the same issue. 

Looking for any help. Thanks in advance !!

Thanks,

Prashant

Hi Experts,

 

I am implementing SSO, where both the identity Provider and Service Provider are my different- different developer org. I have done all the setup and following this:

http://wiki.developerforce.com/page/Implementing_Single_Sign-On_Across_Multiple_Organizations

 

I am adding  service provider in Identuty provider Org by  using connected app, But I am not able to see the Service Provider listed under Identity Provider.

 

Please help me.

 

Regards,

Prashant

Hi Experts,

Hope u all are doing good !

I am running a batch class however I see that after processing some batches the batch class execution ends with the error "Batchable instance is too big:". I tried executing the batch class by passing the smaller batch size (like 10,50, etc..) and also not implementing database,stateful, still facing the same issue. 

Looking for any help. Thanks in advance !!

Thanks,

Prashant

Hi Experts,

 

I am implementing SSO, where both the identity Provider and Service Provider are my different- different developer org. I have done all the setup and following this:

http://wiki.developerforce.com/page/Implementing_Single_Sign-On_Across_Multiple_Organizations

 

I am adding  service provider in Identuty provider Org by  using connected app, But I am not able to see the Service Provider listed under Identity Provider.

 

Please help me.

 

Regards,

Prashant

hi guys

here is a small scenario with trigger.

In account object theres a "contact count"  custom field, so question is whenver i updated any contact related to that accont ..the contact count custom field must show the count after saving contact information... whats the logic here...

hello guys

pls help me with this trigger scenario...

theres an updated field and theres a trigger with same action i.e updating field on same object and same field .so my question is theres an existence of dead lock here ..how to over come this issue..

Does isexecuting method resovles this issue ...

 

Hi...

My requirement is i have two objects class and student which are in MDR.

 

object 1 - class - Fields- class name.

object 2 -  student -Fields- student name, class(MDR), status(attending,dropping)

 

My requirement is  a student can attend multiple classes and at the same time only one record has to be

created with that student name where..mulitple classes can be included in tat record.

 

Plz suggest me how to work on it.

 

Thanks in advance.

 

 

 

  • October 25, 2013
  • Like
  • 0

Hi All

 

I want to share the contact using trigger, when i tried the below code i am getting an error "Variable does not exist: ContactAccessLevel at line 29 column 9"

 

trigger ContactMakePublicTrigger on Contact (after insert) {

ID groupId = [select id from Group where Type = 'Organization'].id;
if (Trigger.isInsert) {
List<ContactShare> sharesToCreate = new List<ContactShare>();
for (Contact contact : Trigger.new) {
ContactShare cs = new ContactShare();
cs.ContactAccessLevel = 'Edit';
cs.ContactId = contact.Id;
cs.UserOrGroupId = groupId;
sharesToCreate.add(cs);
}
if (!sharesToCreate.isEmpty())

insert sharesToCreate;

}

 

}

 

Please help me 

 

Thanks in advance.

Hello,

Given an object ID is there a way to get its fields info without using SOQL? See example below:

 

I have an aid = accountID given below

 

instead of writing

select id, parentId, name, Type from Account where Id =: aid

 

can I write something like below

 

string sname;

string stype;

 

sname = aid.name;

stype = aid.type;

 

basically it is similar to below statements and it works when I write a trigger like this one below.

Case CaseUpdated:trigger.new

GroupNo = CaseUpdated.Group__c;

 

Please advise

Paul

 

  • October 17, 2013
  • Like
  • 0

Hello Experts,

 

Below is the pretty much good code i am using in orde to update the first activity date field. As per the new salesforce limit I am getting the Apex cpu time limit during mass upload. Some time it works fine and get the error at 1000 upload where in 900 sucess and limit exceed for rest. Sometime it occurs at 100 task uploads only.

 

Please let me know how to overcome this and test the consumption of limits in this code ?? Code was well behaved with preveous releses.

 

===========================================================

trigger SetFirstactivityDate on Task(after update,after insert) {
   
  
  
    Set<Id> RecordIds=new Set<Id>();
    for (Task evntObj: Trigger.new){
       
        RecordIds.add(evntObj.WhoId);
   
    }
    List<Contact> conList=new List<Contact>();
    for(Contact con:[Select id,(SELECT ActivityDate FROM ActivityHistories Where ActivityDate < = Today  Order
    By ActivityDate ASC Limit 1) from Contact where id in:RecordIds])
    {
         if(con.ActivityHistories.size()>0)
         {
         con.First_ACTIVITY_Date__c=con.ActivityHistories[0].ActivityDate;
         conList.add(con);
         con.Apex_context__c=True; \\ in this line bypassing all the validation rule
         }
         else
         {
         con.First_ACTIVITY_Date__c=null;
         conList.add(con);
         con.Apex_context__c=True; \\ in this line bypassing all the validation rule
         }
        
    }
   
    if(conList.size()>0)
    {
    update conList;
    }
    }

===========================================================

 

Appreciate your suggestions ...........

 

Thanks.......

.........................................

hi,

 

I want to update a child object field when if opportunity line item 's quantity gets updated and that object which gonna be informed that the opportunity is got updated .... is the child to opportunity . so for that I'm writting a trigger and getting confused in fetching the old value of that field..... to match .in the if condition....

 

public void statusUpdate(List<opportunity> newOpps, List<opportunity> oldOpps){
        List<String> oppIds = new List<String>();
        List<opportunityLineItem> opportunityLineItemsNew = new List<opportunityLineItem>();
        List<production__c> productionTickets = new List<production__c>();
        for(opportunity oppNw : newOpps){
            oppids.add(oppNw.id);
        }
        
        opportunityLineItemsNew = [Select id, opportunityId, quantity, StartDate__c, EndDate__c, CostType__c From opportunityLineItem where opportunityID in : oppids];
        productionTickets = [select id, name, Opportunity__c, OpportunityStatus__c from production__c where Opportunity__c in : oppids];
        
        for(Production__c pt : productionTickets){
            for(opportunityLineItem oli : opportunityLIneItemsNew){
                if(oli.opportunityId == pt.opportunity__c){
                    if(oli.quantity != ?????? ){
                   
                    }
                }
            }
        }
    }

 

so plz tell me if you have any of the solutions.... thanks in advance........................... :)

  • October 15, 2013
  • Like
  • 0

Hi

 

Apex Sharing Class:

 

public with sharing class TestCls {

    public TestCls(){

         myweb.dologic();

   }

}

 

=====

// Webservice class

 

Global class className{

    dologic();

}

 

 

 

In this case What is the apex code execution mode. is it in user / system?

 

 

Because all webservices will execute in system mode. But sharing class will execute in user mode.

 

When we call a webservice method from sharing class.. what is the final execution mode?

Hi,

 

Can anyone provide an example of creating a picklist of fields within an object.

 

I have an object call forms that has a field - Mapping_Object__c - within this I am storing the name of a custom object

 

i need to then for a child record display the field associated with the mapping object within a selectlist as a single select option.

 

i have found some examples but none that are doing anything like what I need.

 

I'm guessing in my class i need to query the parent object to get the mapping_object__c - i then need to use that value to get the fieldnames related to the object.

 

any ideas or examples of how to do this would be appreciated.

 

cheers

dan

I am trying to develop a new apex class in a production environment and it won,t let me. How to use the developer console and migrate into the production. I am lost but the code I have works since I have tested elsewhere. Can somebody walk me through this?

  • October 10, 2013
  • Like
  • 0

I'm trying to write a Batchable that uses an Iterable.  I'm getting one error.  The example in the documentation isn't much help as it declares the Iterable without a type and I can't even get that to compile.

 

The issue in in the assignment of myIter in the start() method.  I get a runtime exception on that line. 

 

global class KenTestBatch implements Database.batchable<Transaction__c> { 
   /*
   	KenTestBatch batcher = new KenTestBatch();
    	Id procId = Database.executeBatch(batcher,1);
    	System.debug('ProcId ' + procId);
   */
   global Iterable<Transaction__c> start(Database.BatchableContext info){
   		Iterable<Transaction__c>myIter=(Iterable<Transaction__c>)new KenTestCustomIterable(); 
       return  myIter;
   }     

   global void execute(Database.BatchableContext info, List<Transaction__c> scope){

       for (Transaction__c tran : scope) { 

		// Do processing here.

       } 
   }     

  global void finish(Database.BatchableContext info){     
  } 
}

global class KenTestCustomIterable implements Iterator<Transaction__c>{ 

   List<Transaction__c> tranList {get; set;} 
   Integer i {get; set;} 

   public KenTestCustomIterable() { 
       tranList =        [SELECT Id, Back_Office_Order__c
       						FROM Transaction__c 
       						limit 100]; 
       i = 0; 
   }   

   global boolean hasNext(){ 
       if(i >= tranList.size()) {
           return false; 
       } else {
           return true; 
       }
   }    

   global Transaction__c next(){ 
       i++; 
       return tranList[i-1]; 
   } 
}

 

I've one custom object on this custom object I've one approval process.

 

in final approval action I've one field update : IsCommentscopy__c==true.

 

I've one before update trigger on same object where I've below code:

 

 
Name
Version
Namespace
Type
Salesforce.com API29.0 Salesforce.com API
Apttus Contract Management6.126Apttus Installed Package
Apttus Echosign Integration1.45Apttus_Echosign Installed Package
DiscoverOrg1.75DiscoverOrg Installed Package
EchoSign12.6echosign_dev1 Installed Package
Eloqua1.3ELOQUA Installed Package
GridBuddy3.24GBLite Installed Package
Indicee Analytics3.8indicee_apps Installed Package
Informatica Data Loader4.0INFA Installed Package
LOOP9.49Loop Installed Package
NetProspex Executive Directory2.5Netprx Installed Package
Nitro for Salesforce1.87nitro Installed Package
Object Console1.9obj_con Installed Package
OrgChartPlus1.23OrgChartPlus Installed Package
Salesforce clients connected apps1.5sf_com_apps Installed Package
Walker PowerInsights1.16Walker_Info Installed Package
Override Log Filters
CategoryLevel
DatabaseNONEERRORWARNINFODEBUGFINEFINERFINEST
WorkflowNONEERRORWARNINFODEBUGFINEFINERFINEST
ValidationNONEERRORWARNINFODEBUGFINEFINERFINEST
CalloutsNONEERRORWARNINFODEBUGFINEFINERFINEST
Apex CodeNONEERRORWARNINFODEBUGFINEFINERFINEST
Apex ProfilingNONEERRORWARNINFODEBUGFINEFINERFINEST
SystemNONEERRORWARNINFODEBUGFINEFINERFINEST
 
trigger SP_copyComments_Trigger on SP_Milestone__c (before update) {
System.debug('SP_copycomments_Trigger called ##');  
String commentsStr='';
  set<id> setmiles=new set<id>();
  for(SP_Milestone__c m : Trigger.New){
    if(m.IsCommentscopy__c){
       setmiles.add(m.id);
    }  
  }
   for (ProcessInstance pi : [SELECT TargetObjectId,
                              ( 
                                 SELECT Id, Comments
                                 FROM Steps                                                               
                              )
                               FROM ProcessInstance
                               WHERE TargetObjectId In :setmiles
                             ])
    {   
     if(pi.steps.size() >0){
       trigger.new[0].BDM_Approver_comments__c=pi.steps[0].Comments ;   
       }   
    }  
}
 
The comments value coming as null. Can any one help.
 
 
Thanks in advanced.
 
Ramadhar Mishra
 

Hi,

 

I'm doing a HTTP Callout from a trigger on a specific object. The trigger basically runs when a record is updated and checks online for related records.

 

I thought I had worked it out but I'm getting an error of:

 

System.ListException: Before Insert or Upsert list must not have two identically equal elements

here is my code basically it should go off to an external site - then grab the xml response - then go through an create a new record for each child element based on my if statements and also fill in the a lookup field with the record id the the trigger was initiated from.

 

i think it's because of how i'm grabbing the recordid and formid at the beginning but am not sure.

 

public class MonitoringQuestionsUpdater {
  @Future(callout=true)
  public static void updateMQ() {
    List<Monitoring_Form__c> mfcs = [SELECT Id, Form_Id__c FROM Monitoring_Form__c]; 
    for(Monitoring_Form__c a:mfcs){
    string formid = a.form_id__c;
    string recordid = a.id;
    Http http = new Http();
    HttpRequest req = new HttpRequest();
    req.setEndpoint('https://magpi.com/api/questions?username=myusername&accesstoken=mytoken&surveyid='+formid);
    req.setMethod('POST'); 
    HTTPResponse res = http.send(req);
    System.debug(res.getBody());
    List<Monitoring_Questions__c> newquestions = new List<Monitoring_Questions__c>();
    set<string> existingmQuestSetId = new set<string>();
 //iterate thru the existing mforms and add allthe form_id__c in a set. And then use this set to later check for duplicates
 for(monitoring_questions__c mquest: [SELECT Id, questionid__c FROM Monitoring_Questions__c]){
    existingmQuestSetId.add(mquest.questionid__c);
 }
    string s = res.getBody();
    Dom.Document docx = new Dom.Document();
        docx.load(s);
        dom.XmlNode xroot = docx.getrootelement();
        dom.XmlNode [] xrec = xroot.getchildelements(); //Get all Record Elements
        for(Dom.XMLNode child : xrec)
            {
        for(dom.XmlNode magpi : child.getchildren() ) {
           Monitoring_Questions__c mq = new Monitoring_Questions__c();
           if (magpi.getname() == 'Id') {
           System.debug(magpi.getname() == 'Id');
                   mq.QuestionID__c = magpi.gettext();
             }
           if (magpi.getname() == 'Prompt') {
           System.debug(magpi.getname() == 'Prompt');
                   mq.Question_Prompt__c = magpi.gettext();
             }
           if (magpi.getname() == 'Name'){
           System.debug(magpi.getname() == 'Name');
                  mq.Question_Name__c = magpi.gettext();  
         }
         mq.monitoring_form__c = recordid;
        if(!existingmQuestSetId.contains(mq.questionid__c)){
            Newquestions.add(mq);
                }
            }
        }
        insert newquestions;
      }
    }
}

 

any help is appreciated.

 

dan

 

Hi everyone,

 

I have a requirement for a custom Visualforce page to be downloaded and saved as a PDF when a user clicks a button on the page.

 

I'm aware of the renderAs apex:page attribute and how you can control rendering the page as a PDF by adding a parameter to the url - however, when we try this option, the PDF generated via this route is not very attractive and doesn't display the formatting on the page (in fact, it actually displays fragments of the HTML code).

 

We would also like to avoid one of the "link to PDF" options - where you send a link to a 3rd party website and the PDF is generated and returned.

 

Has anyone implemented similar requirements? Does anyone know of any options that could deliver what we're needing?

 

Thanks in advance for the help.

 

Robby

Bonojur,

 

I am getting some content from an external webservice and trying to display as a pdf file.

 

As a response I am getting a String and I have decoded the string using EncodingUtil.base64Decode(response) and assigned it to a blob variable.

 

Now I am trying to print that blob variable in vf page using renderAs pdf and instead of rendering as pdf it is displaying in bytes as core.filemanager.byteblobvalue@23F6123c

 

I have tried using Blob.toPdf() and Blob.valueOf() to get a pdf output.

And also I dont want to save it as an attachment in salesforce..because it may create excess attachments.

Saving as an attachment is working fine and displaying as pdf.

 

Any suggestions would be appreciated!!!!

 

Thanks,

Rajj

 

 

 

 

 

 

 

  • April 08, 2013
  • Like
  • 0