• abdulq
  • NEWBIE
  • 0 Points
  • Member since 2012

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

Hi, I'm writing a trigger on ECS__eCommSource_Order_Line__c and if the user increases 'ECS__Quantity'  filed value then the trigger is suppose to add that number of Asset Records in asset object. The trigger is working fine in sandbox but when Iits deployed in Live org its actually creating twice the number of records to Quantity difference value. For example if the old quantity value is 2 and the updated value is 3 then it should create one asset record i.e difference between the old and new value but it my case its creating two records - I can't seem to find how. Below is my trigger code.

 
trigger AssetCreation on ECS__eCommSource_Order_Line__c (before update) 
 
list<asset> records = new list<asset>();
 
//Checking if the user has increased the quantity and adding asset record.
for(integer i = 0; i < Trigger.new.size(); i++)
{
ECS__eCommSource_Order_Line__c new_li = trigger.new[i];
ECS__eCommSource_Order_Line__c old_li = trigger.old[i];

if (new_li.ECS__Quantity__c > old_li.ECS__Quantity__c)
{
integer diff = (new_li.ECS__Quantity__c - old_li.ECS__Quantity__c).intValue();

for (integer j = 0; j < diff; j++)
{
records.add(new asset(AccountID = new_li.ECS__Account__c, Contact__c = new_li.ECS__Customer__c, B2C_Product__c = new_li.ECS__Product__c, Order__c = new_li.ECS__Order__c, Order_Line__c = new_li.id, Name = new_li.ECS__Title__c));
}

insert records;
}
}
}

 

Hi All, I'm quite new to apex, I have created a trigger on two objects CONTACT & OPPORTUNITIES.

 

When I convert a LEAD to ACCOUNT, it also creates a Contact and an Opportunity, so in this process I want a Custom Field(Consultant__C) on both of these objects to be updated with a field that is there on LEAD and later comes in ACCOUNT.

 

I have also written a test class, but when I try to deploy it comes with the error given below - not sure where I'm going wrong.

 

"ConsultantUpdateTest.validateConsultantonContact System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ConsultantUpdateOnContact: data changed by trigger for field Consultant: id value of incorrect type: a0VD0000002KYPfMAO: []"

 

Trigger Code for Contact 

----------------------------------

 

trigger ConsultantUpdateOnContact on Contact (before insert) {
Account a = [select consultant__c from Account where id = :Trigger.new[0].AccountId];
Trigger.new[0].Consultant__c = a.Consultant__c;
}

 

 

Trigger Code for Opportunity

-------------------------------------

trigger ConsultantUpdate on Opportunity (before insert) {

Account o = [select Consultant__c from Account where Id = :trigger.new[0].AccountId];
trigger.new[0].Consultant__c = o.Consultant__c;

}

 

My Test Class

---------------------

@IsTest
public with sharing class ConsultantUpdateTest {
static testMethod void validateConsultantonContact() {

Consultant__c c = new Consultant__c(name = 'Mac Kay', first_name__c = 'Mac');
insert c;
system.assertNotEquals(null, c.id);
Account a = new Account(name='Test Account', consultant__c = c.id);
insert a;
system.assertNotEquals(null, a.id);
Contact con = new Contact(lastname = 'Smith', Accountid = a.id);
insert con;
system.assertNotEquals(null, con.id);
Opportunity o = new Opportunity(name = 'Harry' , Accountid = a.id , CloseDate = Date.Today() , StageName = 'Open' , LeadSource = 'Website', Lead_Source_Detail__c = '-- na --');
insert o;
system.assertNotEquals(null, o.id);
}

I have this query

 

List <Booking__C> bk = [Select (Select Contact__c From Pupils__r) From Booking__c b where b.id = :bookingId];

 

This query should return me the related Contact ID's from Pupils sObject which is a Child Object for Booking and I'm saving the result in a List of type Booking__c, but how do I access the result of related records in another query, if I want to run another query with the results of this one

 

For Eg:

 

List <contact> con = [select firstname, lastname, id from contact where id = ??? (I have tried bk.Contact__C, also tried bk.Pupils__r.id - nothing works, it comes up with an error)

 

I'm new to salesforce can't get my head around accessing nested query results.

 

I'll be glad if any one can tell me where I'm going wrong.

 

Thanks

Hi, I'm writing a trigger on ECS__eCommSource_Order_Line__c and if the user increases 'ECS__Quantity'  filed value then the trigger is suppose to add that number of Asset Records in asset object. The trigger is working fine in sandbox but when Iits deployed in Live org its actually creating twice the number of records to Quantity difference value. For example if the old quantity value is 2 and the updated value is 3 then it should create one asset record i.e difference between the old and new value but it my case its creating two records - I can't seem to find how. Below is my trigger code.

 
trigger AssetCreation on ECS__eCommSource_Order_Line__c (before update) 
 
list<asset> records = new list<asset>();
 
//Checking if the user has increased the quantity and adding asset record.
for(integer i = 0; i < Trigger.new.size(); i++)
{
ECS__eCommSource_Order_Line__c new_li = trigger.new[i];
ECS__eCommSource_Order_Line__c old_li = trigger.old[i];

if (new_li.ECS__Quantity__c > old_li.ECS__Quantity__c)
{
integer diff = (new_li.ECS__Quantity__c - old_li.ECS__Quantity__c).intValue();

for (integer j = 0; j < diff; j++)
{
records.add(new asset(AccountID = new_li.ECS__Account__c, Contact__c = new_li.ECS__Customer__c, B2C_Product__c = new_li.ECS__Product__c, Order__c = new_li.ECS__Order__c, Order_Line__c = new_li.id, Name = new_li.ECS__Title__c));
}

insert records;
}
}
}

 

Hello we are a non profit 501c3 using salesforce
 
We use salesforce also to track text books and recipients.
We generate a profile for each textbook and a profile for each recipient.
We check-out text books to recipients.
 
Barcode Zone generates barcodes for each record (textbooks and recipients).
I would like the ability to merge and print all the labels (Barcodes) so we place the labels on the books.
 
This will add the functionality to scan books in or out of a recipient profile.
 
Currently Barcode Zone was able to add a print label button that print one label.
<apex:page standardController="Book_Bank_Inventory__c" renderAs="pdf">
  <BarcodeZone:ACBarcodeZone Value="{!Book_Bank_Inventory__c.Name}"
  BrcdType="{!Book_Bank_Inventory__c.Barcode_Type__c}"
  rendered="true"
  />  
</apex:page> 
 
Alternatively on the visual page code we could manually add multiple values.
  <apex:page standardController="Book_Bank_Inventory__c" renderAs="pdf">
  <BarcodeZone:ACBarcodeZone Value="{!'99199-082012-P2-12'}"
  BrcdType="{!'code128'}"
  rendered="true" /> 
  <BarcodeZone:ACBarcodeZone Value="{!'99199-082012-P2-12'}"
  BrcdType="{!'code128'}"
  rendered="true" /> 
  <BarcodeZone:ACBarcodeZone Value="{!'99199-082012-P2-12'}"
  BrcdType="{!'code128'}"
We will have 2800 textbooks and the above solutions will not work.
 
Will you be able to help?
 
THANK YOU