• jpwagner
  • NEWBIE
  • 200 Points
  • Member since 2007

  • Chatter
    Feed
  • 8
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 66
    Replies

A little challenge,

 

I have say 100 strings in a list that are in this format: 3 to 5 numbers, a space, a name.  

Example 1: "1234 Product Name One"

Example 2: "12345 Product Name Two"

 

How do I most efficiently remove the 1234 and the space so I just have Product Name? 

 

Result 1: "Product Name One"

Result 2: "Product Name Two "

I'm going to create a trigger on case object, this trigger should only invoke when the case're record type is "XXX", "XXX" is one of the record type of case, can someone help me figure out the code to identify the report type is "XXX". the following script doesn't work.

if(Trigger.new[i].RecordType == 'Partner Case'){

How do I write a trigger for the opportunity product object that updates the "sales price" field every time the "discount field" or the "Qty" field is changed?

 

Please help.

 

  • April 14, 2009
  • Like
  • 0

Hello everyone!!

 

I'm just trying to develop in APEX code something I used to do very often with JAVA. I want to convert float to String

( 200 -> two hundred) 

 

 Thank you so much!!

 

 

J A V I

i am a beginner i managed to create the below trigger to update the campaign member status before lead update. .  

 

can any one help me writing a test class for it.

 

thanks in advance for your help.

 

trigger UpdateMemberStatus on Lead ( before insert ,before update) {

Lead[] leads = Trigger.new;

for (Lead l:leads){

List<CampaignMember> status = new List<CampaignMember>();

// select the status for the most recent campaign for that lead

status = [SELECT status FROM CampaignMember  WHERE leadId = :l.id order by id desc limit 1];

// make sure the lead is assigned to the campaign.

if (!status.isEmpty())

{

status[0].status = l.outcome__c;

update status;

}

}

  • April 14, 2009
  • Like
  • 0

I am new at sql and soql and need some help. I am trying to find out if a user record is marked out of office and if so add a backup user to their cases. I am having trouble with my query.

 

My Trigger

 

 

trigger myCaseTrigger on Case (before insert, before update) { Case[] cs = Trigger.new; caseChange.makeChange(cs); }

 

 

This is working for me as a test to change the case

 

 

public class caseChange { public static void makeChange(Case[] cs){ for (Case u : cs ) { if (u.Backup_User__c == null ) { u.Backup_User__c = u.OwnerId;} } } }

 

 

 

The next two are my attempt, but are not working

 

 

 

public class caseChange { public static void makeChange(Case[] cs){ for (Case u : cs ) { if (u.Owner__r.Out_Of_Office__c == 'true' ) { u.Backup_User__c = u.Owner__r.Backup_User__c;} } } }

 

 

 

 

 

public class caseChange { public static void makeChange(Case[] cs){ for (User u : cs ) { if (u.Out_Of_Office__c == 'true' ) { u.Cases__r.Backup_User__c = u.OwnerId;} } } }

 

 

 

Thank you for any advice or help.

 

 

 

 

I am recieving this error when inserting a record with an Apex webservice that is invoked from a button on a page layout. I haven't been able to dig too deep into this issue but because this error is so generic I am not really sure where to start looking.

 

Has anyone encountered this error message before and if so what did you find to be the issue?

 

Thanks.

Message Edited by TehNrd on 03-16-2009 01:31 PM
  • March 16, 2009
  • Like
  • 0

Does anyone have any ideas for how to check what browser and version is being used while rendering a visualforce page?

 

Thanks! 

Hi all,

 

I think I must be misunderstanding something about some of the governor limits.

 

Here's a quick example of something I'd like to understand better:

 

I have a trigger that does a bunch of calculations on insert and update of a custom object and inserts some new records based on those calculations.  When I split up my ~52,000 record initial dataset, and load (via the APEX Data Loader)~13,000 records 4 times, I have no governor limit breaches.  When I load all 52,000 at once, it breaks the Script statement governor limit. 

 

I thought the APEX data loader batches it's loads into 200, so how is this possible?

Message Edited by jpwagner on 04-13-2009 11:37 PM

Hi,

 

I'm looking to create a button that obtains an html blob from a URL (in the real implementation I'd actually be parsing that html to find some piece of information, but that's not important.)

 

So far I believe this is a pretty straight forward class to get that info:

global class htmlblob {

webservice static String getblob(String someurl) {

PageReference pageRef = new PageReference(someurl);
String htmlblob = pageRef.getContent().toString();
return htmlblob;

}

}

 

and I'm calling that class from the button like this:

 

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js" )}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js" )}
var someurl = '/{!Opportunity.Id}';
var records = {!GETRECORDIDS($ObjectType.Opportunity)};
var result = sforce.apex.execute("htmlblob","getblob",{a:someurl});
var myObj = new sforce.SObject("Opportunity" );
myObj.id = records[0];
myObj.htmlblob__c = result.substring(0,50);
sforce.connection.update([myObj]);
window.parent.location="/"+'{!Opportunity.Id}';

 

Just a reminder that I don't actually care about saving the blob to a field so if that's a problem for some reason, I can parse it first, I just want to validate that I am receiving the correct data back.

 

Any help on this is appreciated!

 

Thanks

Message Edited by jpwagner on 04-08-2009 12:19 PM
Message Edited by jpwagner on 04-08-2009 12:20 PM
Message Edited by jpwagner on 04-08-2009 12:20 PM
Message Edited by jpwagner on 04-08-2009 12:47 PM
Message Edited by jpwagner on 04-08-2009 01:05 PM

a few questions on this:

 

1.

 

first of all, at one point, apex code only allowed simple (string) responses from webservice callouts.  is this still the case?  if so, when is salesforce planning on supporting complex responses in this scenario?

 

_____________________________________________________________________________

2.

 

more specifically, I'd like to access meta-data from apex code to modify existing picklist values.  does anyone have thoughts on if this is doable?

 

(i believe this means that if salesforce supports the enterprise and metadata wsdl's converting to apex code (enterprise because of authentication) AND the specific calls made have simple responses, this should work.)

 

Thanks!

New to Visualforce and S-Controls, but an avid Salesforce apex developer.
 
It would help me understand so much if I could see the Visualforce/Javascript used to create the AddProduct Standard List-Button on the OpportunityLineItem.  Is something similar available anywhere?  I could not find such an example in an admittedly quick search of the developer guides.
 
Thanks!
I'm not entirely clear on the limits that scale with trigger batch size. 
 
So I would like to pose a question and ask the community if there are any nifty work arounds or other ways to achieve a certain type of task.  (Although I secretly hope I misunderstood the limits...)
 
Let's suppose I have a field on the OpportunityLineItem that indicates the Product Family from Product2 and I've set up 2 triggers to write to that field (one on OpportunityLineItem before insert, and one on Product2 before update.)  So far so good.
 
Now if I have a single ProductId that I reference in 101 different OpportunityLineItems, then if I change that Product's Family, my trigger on Product2 will fail.  Is this correct?
 
Similarly if this Product was on 1,001 different OpportunityLineItems, I could not even see that list of OpportunityLineItems that reference it (from my select statement.)
 
If this is a correct understanding, what can be done to get around this (another method or a way to batch the results in 100s or 1000s)?  Products are often added to many more than 100 OpportunityLineItems, so if this is a correct understanding, I'm not sure I understand the purpose of this limitation.
 
Thanks!
 
I would've thought this would work...
 
trigger ContactLookupOnInsertTrigger on Contact (before insert) {
for (Contact c : Trigger.new){c.Account.SomeField = someValue;}}
 
But it doesn't.  Any thoughts/suggestions?
Thanks.
Has anyone successfully written callouts to SAP/XI?

I have tried all sorts of combinations, but running into issues:

All my research points that I am doing this correct.  We have tried both self-signed certs and basic username/password authentication.

Setting my stub values:
Stub.inputHttpHeaders_x.put('Authorization','BASIC dnJldmF....W1wcGFzczAx');
--OR--
Blob headerValue = Blob.valueOf(username + ':' + password);//username/password set above String authorizationHeader = 'BASIC '+ EncodingUtil.base64Encode(headerValue);
stub.inputHttpHeaders_x.put('Authorization', authorizationHeader);

We have also tried (separately):
stub.clientCert_x = 'MIIG...';//Where this is the bas64 encoding of the pkc12 version of the cert
stub.clientCertPasswd_x = 'xxxxx';

Nothing seems to get past the security layer.  Has anyone successfully written the outbound message?

 

 

 

 

A little challenge,

 

I have say 100 strings in a list that are in this format: 3 to 5 numbers, a space, a name.  

Example 1: "1234 Product Name One"

Example 2: "12345 Product Name Two"

 

How do I most efficiently remove the 1234 and the space so I just have Product Name? 

 

Result 1: "Product Name One"

Result 2: "Product Name Two "

In sandbox that got upgraded to winter 10.

 

I am trying to return a Database.QueryLocation from the start method.

 

The release notes and the documentation for winter 10 clearly says that I can return either iterable or QueryLocator. But, in my code if  I say something like 

 

global Database.QueryLocator start(Database.BatchableContext ctx)

{

return Database.getQueryLocator('Some query here'); 

 

It does not compile.

  

  • September 22, 2009
  • Like
  • 0

Ihave a custom field on Account that is a user lookup called "SA Manager."  I also have an "SA Manager User" lookup field on Opportunity that is a user lookup.  Every opportunity related to that account needs to have the SA Manager User field updated when "SA Manager" field is changed on the Account.

 

I created a trigger to update it, but can't seem to get the code to compile.  My IF statement is off and I'm getting the following error:

 

Error: Compile Error: Illegal assignment from Schema.SObjectField to Id at line 13 column 8

 

 

 

trigger UpdateSAMgrOnOppty on Account (after update) { Account acctObj = Trigger.new[0]; IF (acctObj.SA_Manager__r.Id != null && ISCHANGED(acctObj.SA_Manager__r.Id))

User name = [SELECT u.Id, u.Name from User u where u.Id =: acctObj.SA_Manager__r.Id]; for (Opportunity oppty : [Select o.Id, o.SA_Manager_User__r.Id From Opportunity o where o.Account.id = :acctObj.id ]) { oppty.SA_Manager_User__c = name.id ; update oppty; } }

 


Any help is appreciated!

 

  • September 22, 2009
  • Like
  • 0

I have an Object which the Name field starts with "AO-" Now within that is an autonumber. So the field would say for a record after created is AO-01856. How in an Apex Class just get the number from here and not the AO.

I am trying to create a new record for the child object which relates to the parent object.

Thanks

Hi All,

 

I need to run batch apex in every 2 hours using "batch Apex" faciulity given by SFDC. Please help me with the same.

 

 

regards

Sunil Arora

  • September 22, 2009
  • Like
  • 0

Currently all my APEX trigger and classes are either version 14.0 or 15.0. I noticed that 17.0 is available in the version control settings. Do I need to update everything? Also, going forward should I use the latest version, would I have metadata issues?

 

Thanks

  • September 21, 2009
  • Like
  • 0
Is it possible to get report data via apex? So essentially you are requesting the report to run and retrieving the report data in a List of sobjects or something similar? 
  • September 21, 2009
  • Like
  • 0
Hi all, I have a question. Is is posible to create a custom object using a web service call or apex code? Thank you very much for you help.
  • September 21, 2009
  • Like
  • 0

I have a business case where I need to display the corresponding input field when a value has been selected. For example: when Phone and fax fields have been selected as to what needs to be added, the cooresponding Phone and fax fields will be displayed. Currently my code is:

 

<apex:actionRegion > <apex:pageblockSection columns="1" > <apex:pageBlockSectionItem > <apex:outputLabel value="What Information needs to be Corrected?" id="thePageBlock1"/> <apex:outputPanel > <apex:inputfield value="{!Manufacturing_Design_Sheet__c.What_Information_needs_to_be_Corrected__c}"> <apex:actionSupport event="onclick" rerender="thePageBlock1" status="status1"/> </apex:inputField> <apex:actionStatus startText="applying value..." id="status1"/> </apex:outputPanel> </apex:pageBlockSectionItem><apex:pageBlockSectionItem > <apex:outputLabel value="Correct the Information"/> <apex:outputPanel > <apex:inputfield value="{!Manufacturing_Design_Sheet__c.Correct_the_Information__c}"> <apex:actionSupport event="onclick" rerender="thePageBlock" status="status"/> </apex:inputField> <apex:actionStatus startText="applying value..." id="status"/> </apex:outputPanel> </apex:pageBlockSectionItem> </apex:pageblockSection> </apex:actionRegion> <apex:pageBlockSection columns="1" rendered="{!Manufacturing_Design_Sheet__c.Correct_the_Information__c==true}"> <apex:inputfield value="{!Manufacturing_Design_Sheet__c.Technical_Phone__c}" /> </apex:pageBlockSection> <apex:pageBlockSection columns="1" rendered="{!And(Manufacturing_Design_Sheet__c.Correct_the_Information__c==true, Manufacturing_Design_Sheet__c.What_Information_needs_to_be_Corrected__c=='Commercial Phone') }"> <apex:inputfield value="{!Manufacturing_Design_Sheet__c.Commercial_Phone__c}" /> </apex:pageBlockSection>

 

 

Any suggestions? Do I need to run the logic to disply the fields in my trigger?

  • September 21, 2009
  • Like
  • 0

I have a trigger that sends an outbound email when an opportunitylineitem is deleted from a particular opportunity. However my test class is failing saying that "no index id on line 22". any help would be greatly appreciated

 

my trigger:

trigger UnassignedConsultantRemoved on OpportunityLineItem (before delete) {
{
Set<Id> Pricebookentryid = new Set<Id>();

for (OpportunityLineItem OppLineItem : Trigger.old)
{
if (opplineitem.opportunityid =='006R0000003rc72IAA')
{
PricebookentryId.add(opplineitem.pricebookentryid);


Map<Id,String> PricebookEntryMap = new Map<Id, String>();
Map<Id,Datetime> PricebookEntryDate = new Map<Id, Datetime>();


for(Pricebookentry pb:[select id, name, lastmodifieddate from pricebookentry where id IN: pricebookentryID])
{
Pricebookentrymap.put(pb.id,pb.name);
PricebookentryDate.put(pb.id, pb.lastmodifieddate);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'bkim@dlcinc.com'};
mail.setToAddresses(toAddresses);
mail.setSubject('DLC Consultant removed from Bench');
mail.setUseSignature(false);
string msg = ' <br>';
msg = msg + '<b>' + 'Consultant, ' + pb.name + ' has been removed from the bench on ' + '</i>' + pb.lastmodifieddate;
msg = msg ;
mail.setHtmlBody(msg);

// Send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
}
}

 

 

My test class:

 

@isTest 
private class TestOpportunityLineItemDelete {

static testMethod void myUnitTest() {
Account acc = new Account(Name = 'TestAccount', Type = 'Prospect', Industry = 'Banking', Physical_Street__c = 'Test Street',Physical_City__c = 'Los Angeles', Physical_State__c = 'CA', Physical_Zip_Postal_Code__c = '90017', Physical_Country__c = 'USA', Phone = '(888) 999-1234' );
Opportunity opp = new Opportunity(Name= 'Test', accountid = acc.Id, Type = 'CSD Transition', Stagename= 'Won-Engagement in Process', PracticeArea__c = 'Won-Engagement in Process',CloseDate=Date.today(), EngagementStartDate__c = Date.today(), EngagementEndDate__c = Date.today(),Work_Type__c = 'Project',Status__c = 'Full-time', OT_Multiplier__c = 1, DT_Multiplier__c =1 );
OpportunityLineItem olt1 = new OpportunityLineItem(Opportunityid = opp.id,Unitprice= 180.00, Quantity = 1);

try {
insert olt1;
}
catch(DmlException olt)
{
System.debug(olt.getMessage());
}

test.starttest();

ID newid = olt1.id;
delete olt1;
test.stoptest();
}
}

Message Edited by bikla78 on 08-18-2009 11:01 PM

We went Live with SF today, and I'm getting Too many SOQL queries error on a trigger of mine.

 

The trigger is fairly simple in concept in that it takes the ownership of an opportunity and makes certain related objects (or certain objects related to those related objects) and makes the owner of the record the same.

 

In implmentation, I had to do maps and limit the scope of of things with comparisions to keep under the limits and I succeeded until now. 

 

But I'm making no sense of this error message.  At my count there are at most 12 SOQL queries in my code, none in any sort of loop.  So..... how is it adding up to 20?  Is it counting Workflows, Triggers that trigger other triggers, triggers that trigger other triggers that trigger this trigger again?  What are the exception to the rule in which I can't just count the number of potential queries in a given query code to see if I'm going to exceed this SOQL limit?

 

Here's the code:

trigger Opportunity_Ownership_Trigger on Opportunity (after insert, after update) {
    List<String> theIds = new List<String>();
    for(Opportunity opp : Trigger.new) {
          theIds.add(opp.Id);
      }
      boolean updated = false;
     
      List<Order_Detail__c> od_list = [SELECT Id,Opportunity__c,OwnerId,Order__c FROM Order_Detail__c WHERE Opportunity__c IN :theIds];
      for(Order_Detail__c od : od_list) {
        if (Trigger.newMap.get(od.Opportunity__c).OwnerId != od.OwnerId) {
              od.OwnerId = Trigger.newMap.get(od.Opportunity__c).OwnerId;
              updated = true;
        }
      }
      if (updated)
      {
          update od_list;
      }
      Map<Id, Order_Detail__c> od_map = new Map<Id, Order_Detail__c>([SELECT Id,Opportunity__c,OwnerId,Order__c FROM Order_Detail__c WHERE Opportunity__c IN :theIds]);
      Map<Id, Order_Detail__c> od_order_map = new Map<Id, Order_Detail__c>();
      for(Order_Detail__c od : [SELECT Id,Opportunity__c,OwnerId,Order__c FROM Order_Detail__c WHERE Opportunity__c IN :theIds]) {
          if(!od_order_map.containsKey(od.Order__c)) {
              od_order_map.put(od.Order__c,od);
          }         
      }
 
      updated = false;
     
      List<Invoice_Detail__c> id_list = [SELECT Id,Opportunity__c,OwnerId,Invoice__c FROM Invoice_Detail__c WHERE Opportunity__c IN :theIds];
      for(Invoice_Detail__c id : id_list) {
        if (Trigger.newMap.get(id.Opportunity__c).OwnerId != id.OwnerId) {
              id.OwnerId = Trigger.newMap.get(id.Opportunity__c).OwnerId;
              updated = true;
        }
      }
      if (updated)
      {
          update id_list;
      }
      Map<Id, Invoice_Detail__c> id_map = new Map<Id, Invoice_Detail__c>();
      for(Invoice_Detail__c id : [SELECT Id,Opportunity__c,OwnerId,Invoice__c FROM Invoice_Detail__c WHERE Opportunity__c IN :theIds]) {
          if(!id_map.containsKey(id.Invoice__c)) {
              id_map.put(id.Invoice__c,id);
          }
      }
     
      updated = false;
      theIds = new List<String>();
    for(Order_Detail__c od : od_list) {
          theIds.add(od.Id);
      }
      List<Order_Release__c> or_list = [SELECT Id,OwnerId,Order_Detail__c FROM Order_Release__c WHERE Order_Detail__c IN :theIds];
      for(Order_Release__c or_item : or_list) {
        if (od_map.get(or_item.Order_Detail__c).OwnerId != or_item.OwnerId) {
              or_item.OwnerId = od_map.get(or_item.Order_Detail__c).OwnerId;
              updated = true;
          }
      }
      if (updated)
      {
          update or_list;
      }
     
      updated = false;
      theIds = new List<String>();
    for(Order_Detail__c od : od_list) {
          theIds.add(od.Order__c);
      }     
      List<Sales_Orders__c> o_list = [SELECT Id,OwnerId FROM Sales_Orders__c WHERE Id IN :theIds];
      for(Sales_Orders__c o : o_list) {
        if (od_order_map.get(o.Id).OwnerId != o.OwnerId) {
              o.OwnerId = od_order_map.get(o.Id).OwnerId;
              updated = true;
          }
      }
      if (updated)
      {
          update o_list;
      } 
         
      updated = false;
      theIds = new List<String>();
    for(Invoice_Detail__c id : id_list) {
          theIds.add(id.Invoice__c);
      }     
      List<Invoice_Object__c> i_list = [SELECT Id,OwnerId FROM Invoice_Object__c WHERE Id IN :theIds];
      for(Invoice_Object__c i_item : i_list) {
        if (id_map.get(i_item.Id).OwnerId != i_item.OwnerId) {
              i_item.OwnerId = id_map.get(i_item.Id).OwnerId;
              updated = true;
          }
      }
      if (updated)
      {
          update i_list;
      }       
}

 

Additionally these triggers support that trigger by invoking it appropriately, but do not error out:

trigger Opportunity_Ownership_Trigger_Order_Detail on Order_Detail__c (after insert, after update) {
    List<String> theIds = new List<String>();
    if (Trigger.isInsert) {
        for (Order_Detail__c od : trigger.new) {
            if (od.Opportunity__c != null) {
                theIds.add(od.Opportunity__c);   
            }   
        }
    }
    else if (Trigger.isUpdate) {
        for (Order_Detail__c od : trigger.new) {
            if (Trigger.oldMap.get(od.Id).Opportunity__c != od.Opportunity__c) {
                if (od.Opportunity__c != null) {
                    theIds.add(od.Opportunity__c);     
                }
            }
        }
    }
    List<Opportunity> opp_list = [SELECT Id FROM Opportunity WHERE Id IN :theIds];
    update opp_list;
}

trigger Opportunity_Ownership_Trigger_Invoice_Detail on Invoice_Detail__c (after insert, after update) {
    List<String> theIds = new List<String>();
    if (Trigger.isInsert) {
        for (Invoice_Detail__c od : trigger.new) {
            if (od.Opportunity__c != null) {
                theIds.add(od.Opportunity__c);   
            }   
        }
    }
    else if (Trigger.isUpdate) {
        for (Invoice_Detail__c od : trigger.new) {
            if (Trigger.oldMap.get(od.Id).Opportunity__c != od.Opportunity__c) {
                if (od.Opportunity__c != null) {
                    theIds.add(od.Opportunity__c);     
                }
            }
        }
    }
    List<Opportunity> opp_list = [SELECT Id FROM Opportunity WHERE Id IN :theIds];
    update opp_list;
}

I'm writing a trigger that will cause some data updates to happen when an Opportunity has certain products added or changed.

 

I think the trigger should run on Opportunity (after insert, after update), but I can't seem to access data like Opportunity.OpportunityLineItem[x].productName when triggering on the opportunity.

 

If OpportunityLineItems aren't a child of Opportunity, how does one access that data?  I guess I'm not approaching this correctly and don't understand the Opportunity object yet.

 

Thanks,

Kevin

  • April 15, 2009
  • Like
  • 0

Hi all,

 

I think I must be misunderstanding something about some of the governor limits.

 

Here's a quick example of something I'd like to understand better:

 

I have a trigger that does a bunch of calculations on insert and update of a custom object and inserts some new records based on those calculations.  When I split up my ~52,000 record initial dataset, and load (via the APEX Data Loader)~13,000 records 4 times, I have no governor limit breaches.  When I load all 52,000 at once, it breaks the Script statement governor limit. 

 

I thought the APEX data loader batches it's loads into 200, so how is this possible?

Message Edited by jpwagner on 04-13-2009 11:37 PM