• Adam Cadam
  • NEWBIE
  • 45 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 9
    Replies
0
In my BeforeInsert trigger for OpprtunityLineItemTrigger, I check if the product requires VAT (sales tax in the US) and add it to the UnitPrice if it does.
This works most of the time, but sometimes fails.
Here's the code that does this:
boolean vatableEntry = entry.Vatable_Entry__c;
Decimal entryFee = (entry.Registration_Fee_Calculation__c <> NULL ? entry.Registration_Fee_Calculation__c : 0);
// If VAT Applicable, add it to the Entry Registration fee
oli.Vatable_Entry__c = vatableEntry ;
if (vatableEntry){
    Decimal vat = (entryFee * (entry.Event__r.VAT_Percentage__c/100)).setScale(2);
    oli.Cost_Comment__c = '(pre-I) OLI - VATable: ' + entryFee + vat;
    oli.UnitPrice = entryFee + vat;
    system.debug('#### fixEntryOppUnitPrice (pre-I) OLI - VATable: ' + entryFee + vat);
}
else {
    oli.Cost_Comment__c = '(pre-I) OLI - Not VATable: ' + entryFee;
    oli.UnitPrice = entryFee;
    system.debug('#### fixEntryOppUnitPrice (pre-I) OLI - Not VATable: ' + entryFee);
}
And here are two OpportunityLineItems, from the same Opportunity, for the same product:
Correct valuesIncorrect values
In the first image, the price is correct - £87.48 In the 'Cost Comment' field, added in before insert (pre-I) you can see the string from the code: 72.90 entryFee and 14.58 vat

In the second one, processed in just the same way - with the same Cost Comment (both of them say it is Vatable), but the price on the OLI is just £72.90 - the vat has not been added.
This works most of the time (I've not extracted the data to give detailed stats, but probably < than 1 in 100 OLI's).

You can also see that the 'Vatable Entry' flag is set for both OLI's.

So, it's really difficult to reliably reproduce to debug in a sandbox, and the fact it works most of the time means the code is correct. We can also see that the OLI gets updated - the Cost_Comment field is populated in both cases.

Please note - the £0.00 List Price is not part of this. The price for this product, an entry into a competition, doesn't come from a PriceBook but is calculated for each entry - from the Entry__c.Registration_Fee_Calculation__c field - and is the same in both cases.

Any ideas why this might be happening?

 
How do you create a SOQL query using a filed name from a List of custom objects. I tried this but it doesn't work:
 
List<Payment__c> payments = [SELECT Id,Name,Order__c,Settled_Date__c,Success_Date__c FROM Payment__c WHERE Order__c IN :orders.customerOrderCode];

'orders' is a List<CustomApexObject> where CustomApexObject is just what it says, and it has a field called customerOrderCode, which contains a valid 'Order' Id,

The code above fails because customerOrderCode is a field on the CustomApexObject, not on the List<CustomApexObject>

Thanks!
In workbench, I'm trying to execute a very basic query as follows:

SELECT Count(Id) FROM Account WHERE RecordTypeId = '0124O000000NAuoQAG'

This is returning the error in the subject.  Could this be a server caching issue?
0
In my BeforeInsert trigger for OpprtunityLineItemTrigger, I check if the product requires VAT (sales tax in the US) and add it to the UnitPrice if it does.
This works most of the time, but sometimes fails.
Here's the code that does this:
boolean vatableEntry = entry.Vatable_Entry__c;
Decimal entryFee = (entry.Registration_Fee_Calculation__c <> NULL ? entry.Registration_Fee_Calculation__c : 0);
// If VAT Applicable, add it to the Entry Registration fee
oli.Vatable_Entry__c = vatableEntry ;
if (vatableEntry){
    Decimal vat = (entryFee * (entry.Event__r.VAT_Percentage__c/100)).setScale(2);
    oli.Cost_Comment__c = '(pre-I) OLI - VATable: ' + entryFee + vat;
    oli.UnitPrice = entryFee + vat;
    system.debug('#### fixEntryOppUnitPrice (pre-I) OLI - VATable: ' + entryFee + vat);
}
else {
    oli.Cost_Comment__c = '(pre-I) OLI - Not VATable: ' + entryFee;
    oli.UnitPrice = entryFee;
    system.debug('#### fixEntryOppUnitPrice (pre-I) OLI - Not VATable: ' + entryFee);
}
And here are two OpportunityLineItems, from the same Opportunity, for the same product:
Correct valuesIncorrect values
In the first image, the price is correct - £87.48 In the 'Cost Comment' field, added in before insert (pre-I) you can see the string from the code: 72.90 entryFee and 14.58 vat

In the second one, processed in just the same way - with the same Cost Comment (both of them say it is Vatable), but the price on the OLI is just £72.90 - the vat has not been added.
This works most of the time (I've not extracted the data to give detailed stats, but probably < than 1 in 100 OLI's).

You can also see that the 'Vatable Entry' flag is set for both OLI's.

So, it's really difficult to reliably reproduce to debug in a sandbox, and the fact it works most of the time means the code is correct. We can also see that the OLI gets updated - the Cost_Comment field is populated in both cases.

Please note - the £0.00 List Price is not part of this. The price for this product, an entry into a competition, doesn't come from a PriceBook but is calculated for each entry - from the Entry__c.Registration_Fee_Calculation__c field - and is the same in both cases.

Any ideas why this might be happening?

 
How do you create a SOQL query using a filed name from a List of custom objects. I tried this but it doesn't work:
 
List<Payment__c> payments = [SELECT Id,Name,Order__c,Settled_Date__c,Success_Date__c FROM Payment__c WHERE Order__c IN :orders.customerOrderCode];

'orders' is a List<CustomApexObject> where CustomApexObject is just what it says, and it has a field called customerOrderCode, which contains a valid 'Order' Id,

The code above fails because customerOrderCode is a field on the CustomApexObject, not on the List<CustomApexObject>

Thanks!
Hi,
I'm bulding an Approval process, for that I'm preparing an email (Text) template to include VisualForce page link so that approvars opens that page and submit. I can get the Salesforce Base URL from apex but I have no clue how to get it form email template.
See the following template that I have gotten from APEX.
<a href='https://'+ System.URL.getSalesforceBaseUrl().getHost() +  
             '/apex/GUGocardPhotoApprovalPage?ContactId='+contactID'>Click here </a>

 

Hello. I want to know how can i create a Map<String, CustomObject> where the key will not be the Id of the custom field but the Name field and without using a list and going through each record and puting in the map a pair.

If I use Map<String, CustomObject__c> myMap = new Map<String, CustomObject__c>([Select z.Name, z.Id From CustomObject__c z]); i have a map where the key is my CustomObject.Id and I want it to be CustomObject.Name.

Simply put the following formula into a formula field of type "Text":

 

Id
& MID("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345",(
    IF(FIND(MID(Id,1,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,1,0)
    +IF(FIND(MID(Id,2,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,2,0)
    +IF(FIND(MID(Id,3,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,4,0)
    +IF(FIND(MID(Id,4,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,8,0)
    +IF(FIND(MID(Id,5,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,16,0)
    )+1,1)
& MID("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345",(
    IF(FIND(MID(Id,6,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,1,0)
    +IF(FIND(MID(Id,7,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,2,0)
    +IF(FIND(MID(Id,8,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,4,0)
    +IF(FIND(MID(Id,9,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,8,0)
    +IF(FIND(MID(Id,10,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,16,0)
    )+1,1)
& MID("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345",(
    IF(FIND(MID(Id,11,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,1,0)
    +IF(FIND(MID(Id,12,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,2,0)
    +IF(FIND(MID(Id,13,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,4,0)
    +IF(FIND(MID(Id,14,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,8,0)
    +IF(FIND(MID(Id,15,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,16,0)
    )+1,1)

 

This is an optimized version of the code example "BPS: 18 digit external ID within the UI" you can find on the Online Help, but unlike the example provided there, it is small enough to fit into a formula field. Also, this code doesn't contain the error found in the online help example, where the second character byte equivalent of the first 5-character chunk was "4" instead of "2". I'd be more than happy if someone could come up with an even shorter version of this formula...Still, I hope you can use this.

 

Cheers,

Erik Mittmeyer

When I add the tag for the externalIDFieldName (also tried externalIdFieldName)

 

<?xml version="1.0" encoding="utf-8"?>
<jobInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.force.com/2009/06/asyncapi/dataload">
  <operation>upsert</operation>
  <object>Prospect__c</object>
  <contentType>CSV</contentType>
  <externalIDFieldName>Urn__c</externalIDFieldName>
</jobInfo>

 

and send this to the API, I get back

 

<?xml version="1.0" encoding="UTF-8"?><error
   xmlns="http://www.force.com/2009/06/asyncapi/dataload">
 <exceptionCode>InvalidJob</exceptionCode>
 <exceptionMessage>Unable to parse Job</exceptionMessage>
</error>

 

If I leave the externalIdFieldName tag out

 

<?xml version="1.0" encoding="utf-8"?>
<jobInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.force.com/2009/06/asyncapi/dataload">
  <operation>upsert</operation>
  <object>Prospect__c</object>
  <contentType>CSV</contentType>
</jobInfo>

 

I get

 

<?xml version="1.0" encoding="UTF-8"?><error
   xmlns="http://www.force.com/2009/06/asyncapi/dataload">
 <exceptionCode>InvalidJob</exceptionCode>
 <exceptionMessage>External ID was blank for Prospect__c. An External ID must be specified for upsert.</exceptionMessage>
</error>

 

Any ideas

 

Also, is there a resource that I can use to get the full XML specification for these batch requests and responses?

 

Thanks

Simon