• MILK
  • NEWBIE
  • 0 Points
  • Member since 2012

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

trigger AccountEntitlementUsedTrigger on Account_Entitlement_Used__c (after delete, after insert, after update) {
  if(Trigger.isDelete){
    List<id> LAcctID = new List<id>();
    for(Account_Entitlement_Used__c AE : Trigger.old){
      LAcctID.add(AE.Customer_Name__c);
    }
    List<Account> LAcctUpd = new List<Account>();
    for(Account Acct : [Select id, Current_Balance_CRA__c, Current_Balance_Miele__c, Current_Balance_Partner__c,Total_Partner_Event_Balance__c, Total_Miele_Event_Balance__c,Total_CRA_Balance__c
      from Account where id IN :LAcctID]){
     Acct.Current_Balance_Partner__c = BenefitCalculation.countEntitlementNumber(Acct.id,'Partner Events', date.today())[3];
     Acct.Current_Balance_Miele__c = BenefitCalculation.countEntitlementNumber(Acct.id,'Miele Events', date.today())[3];
      Acct.Current_Balance_CRA__c = BenefitCalculation.countEntitlementNumber(Acct.id,'CRA Services', date.today())[3];
         
       
    //List<String> LType = new String[]{'CRA Services','Miele Events','Partner Events'};
     //  List<integer> HType = new integer[]{0,0,0};
     //  for(Integer i = 0; i < 3; i++){
     //  HType[i]=BenefitCalculation.countEntitlementNumber(Acct.id,LType[i], date.today())[4];
       
       
  //Acct.Total_CRA_Balance__c=HType[0];  
 //Acct.Total_Partner_Event_Balance__c =HType[1];
// Acct.Total_Miele_Event_Balance__c = HType[2];

    //   }
      

  
 

      LAcctUpd.add(Acct);
    }
    if(LAcctUpd != null && LAcctUpd.size()>0)
      update LAcctUpd;
      
      
    //////////////////////////  
      
    List<Account_Entitlement__c> LAcctUpdd = new List<Account_Entitlement__c>();
    for(Account_Entitlement__c Acctt : [Select id from Account_Entitlement__c where id IN :LAcctID]){
      Acctt.Related_Entitlement_Used__c='';
      LAcctUpdd.add(Acctt);
    }
    if(LAcctUpdd != null && LAcctUpdd.size()>0)
      update LAcctUpdd;
  
  }
  else if(Trigger.isUpdate){
    
 List<id> LAcctID = new List<id>();
  for(Account_Entitlement_Used__c AE : Trigger.new){
    LAcctID.add(AE.Customer_Name__c);
  }
 List<Account> LAcctUpd = new List<Account>();
 for(Account Acct : [Select id, Current_Balance_CRA__c, Current_Balance_Miele__c, Current_Balance_Partner__c ,Total_Partner_Event_Balance__c, Total_Miele_Event_Balance__c,Total_CRA_Balance__c
     from Account where id IN :LAcctID]){
   Acct.Current_Balance_Partner__c = BenefitCalculation.countEntitlementNumber(Acct.id,'Partner Events', date.today())[3];
     Acct.Current_Balance_Miele__c = BenefitCalculation.countEntitlementNumber(Acct.id,'Miele Events', date.today())[3];
     Acct.Current_Balance_CRA__c = BenefitCalculation.countEntitlementNumber(Acct.id,'CRA Services', date.today())[3];
           
       
   // List<String> LType = new String[]{'CRA Services','Miele Events','Partner Events'};
     //  List<integer> HType = new integer[]{0,0,0};
     //  for(Integer i = 0; i < 3; i++){
    //   HType[i]=BenefitCalculation.countEntitlementNumber(Acct.id,LType[i], date.today())[4];
       
       
 // Acct.Total_CRA_Balance__c=HType[0];  
 //Acct.Total_Partner_Event_Balance__c =HType[1];
 //Acct.Total_Miele_Event_Balance__c = HType[2];

       //}

      LAcctUpd.add(Acct);
 }
  if(LAcctUpd != null && LAcctUpd.size()>0)
    update LAcctUpd;
    
 }
    else if(Trigger.isInsert){
      string abc;
    Set<String> Sname= new Set<String>();
    List<id> LAcctID = new List<id>();
    for(Account_Entitlement_Used__c AE : Trigger.new){
      LAcctID.add(AE.Customer_Name__c);
      Sname.add(AE.Entitlement_Type__c);
   abc=AE.id;
    }
    

    
    
    List<Account> LAcctUpd = new List<Account>();
    for(Account Acct : [Select id, Current_Balance_CRA__c, Current_Balance_Miele__c, Current_Balance_Partner__c ,Total_CRA_Balance__c,Total_Miele_Event_Balance__c,Total_Partner_Event_Balance__c
      from Account where id IN :LAcctID]){
     Acct.Current_Balance_Partner__c = BenefitCalculation.countEntitlementNumber(Acct.id,'Partner Events', date.today())[3];
      Acct.Current_Balance_Miele__c = BenefitCalculation.countEntitlementNumber(Acct.id,'Miele Events', date.today())[3];
   Acct.Current_Balance_CRA__c = BenefitCalculation.countEntitlementNumber(Acct.id,'CRA Services', date.today())[3];
     
      
       
    //List<String> LType = new String[]{'CRA Services','Miele Events','Partner Events'};
    //   List<integer> HType = new integer[]{0,0,0};
     //  for(Integer i = 0; i < 3; i++){
     //  HType[i]=BenefitCalculation.countEntitlementNumber(Acct.id,LType[i], date.today())[4];
       
       
 // Acct.Total_CRA_Balance__c=HType[0];  
// Acct.Total_Partner_Event_Balance__c =HType[1];
// Acct.Total_Miele_Event_Balance__c = HType[2];

     //  }
      LAcctUpd.add(Acct);
    }
    if(LAcctUpd != null && LAcctUpd.size()>0)
      update LAcctUpd;
      
       
    List<Account_Entitlement__c> LAcctUpdd = new List<Account_Entitlement__c>();
    for(Account_Entitlement__c Acctt : [Select Customer_Name__c from Account_Entitlement__c where Customer_Name__c IN :LAcctID and Expired__c=false and Related_Entitlement_Used__c=null and Entitlement_Type__c IN :Sname  order by Id asc limit 1]){

      
      
        Acctt.Related_Entitlement_Used__c=abc;
        LAcctUpdd.add(Acctt);
   
    }
    if(LAcctUpdd != null && LAcctUpdd.size()>0)
      update LAcctUpdd;
   

      

  }



}

  • July 25, 2013
  • Like
  • 0

I have two object : Account_Entitlement_Used__c and Account_Entitlement__c repectively.

master object is Account.

 

field:Acctt.Related_Entitlement_Used__c (object Account_Entitlement__c)

 

If insert a record OF OBJECT Related_Entitlement_Used__c in Account (i.e, Peter), then  the trigger need to find the eariler Account Entitlement record (object Account_Entitlement__c) in Account Peter,then put the id of record(Related_Entitlement_Used__c )into  field of Related_Entitlement_Used__c (object Account_Entitlement__c) in Account Peter.If delete the record of  object  Account_Entitlement_Used__c in Account Peter ,then the Related_Entitlement_Used__c of object (object Account_Entitlement__c) =null

 

 

below is my trigger: the deletion part  seems is done but i dun know how to wrtie afterinsert.............

 

 

 

AccountEntitlementUsedTrigger on Account_Entitlement_Used__c (afterdelete, afterinsert) {

 

if(Trigger.isDelete){

List<id> LAcctID =

newList<id>();

 

for(Account_Entitlement_Used__cAE : Trigger.old){

LAcctID.add(AE.Customer_Name__c);

}

 

List<Account_Entitlement__c> LAcctUpdd = new List<Account_Entitlement__c>();

 

for(Account_Entitlement__c Acctt : [Selectid

 

fromAccount_Entitlement__cwhere id IN:LAcctID]){

Acctt.Related_Entitlement_Used__c=

'';

LAcctUpdd.add(Acctt);

}

if(LAcctUpdd != null&& LAcctUpdd.size()>0)

 

updateLAcctUpdd;

 

}

else

if(Trigger.inSert){

.....

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

}

  • July 10, 2013
  • Like
  • 0

I am new to Apex & Trigger

I have created 2 custom object o1 and o2 

now i want to update  field  (field is called idfield )of o2 to id of o1 if max(id) of o2 after insert  one record in o1

please help me to get code for this !!Thanks!!!!!!!!

  • July 09, 2013
  • Like
  • 0

How to unchange the last modified date after update?

  • January 18, 2013
  • Like
  • 0

BELOW IS MY CODE ON THE BUTTON:

 

{!REQUIRESCRIPT("/soap/ajax/9.0/connection.js")}
var smid = '{!Sales_Memo__c.Id}';
var result = sforce.connection.query("select Id, No_of_Prints__c From Sales_Memo__c where Id = '{!Sales_Memo__c.Id}' limit 1");
var records = result.getArray("records");
if (records.length > 0) {
var record = records[0];
var i = record.No_of_Prints__c;
record.No_of_Prints__c = ++i;
var result = sforce.connection.update([record]);
if(result[0].getBoolean("success")) {
window.open("https://ap1.salesforce.com/apex/SMPDF_re?id="+smid);
document.location.reload();
}
else {
window.alert ("failed to update Sales Memo " + result[0]);
}
}
else {
window.alert ("No record found for Sales Memo Id : {!Sales_Memo__c.Id}" );
}

 

  • January 04, 2013
  • Like
  • 0

How do I display the values of picklist data type from salesforce to comboBox in Visual C# through API?

 

  • December 04, 2012
  • Like
  • 0

           I want to create a record into salesforce.However, the record is created with correct data of  Sales_Memo__c field  and Product_Name__c field.But no quantity in the record of .Quantity__c field.In Salesforce, the data type of Quantity__c is 'number(18,2)'.Below is the c# coding for importing into salesforce by API.What wrong of it?

 

 

 

            SalesMemoItem.Sales_Memo__c = "a0n90000000HwEo";
                     SalesMemoItem.Product_Name__c = "Milk container";

 

         Sales_Memo_Item__c SalesMemoItem = new Sales_Memo_Item__c();

                     string str = "1";



                    SalesMemoItem.Quantity__c = Convert.ToDouble(str);


               SaveResult[] results = binding.create(new sObject[] { SalesMemoItem });

  • December 03, 2012
  • Like
  • 0

I am new to Apex & Trigger

I have created 2 custom object o1 and o2 

now i want to update  field  (field is called idfield )of o2 to id of o1 if max(id) of o2 after insert  one record in o1

please help me to get code for this !!Thanks!!!!!!!!

  • July 09, 2013
  • Like
  • 0

BELOW IS MY CODE ON THE BUTTON:

 

{!REQUIRESCRIPT("/soap/ajax/9.0/connection.js")}
var smid = '{!Sales_Memo__c.Id}';
var result = sforce.connection.query("select Id, No_of_Prints__c From Sales_Memo__c where Id = '{!Sales_Memo__c.Id}' limit 1");
var records = result.getArray("records");
if (records.length > 0) {
var record = records[0];
var i = record.No_of_Prints__c;
record.No_of_Prints__c = ++i;
var result = sforce.connection.update([record]);
if(result[0].getBoolean("success")) {
window.open("https://ap1.salesforce.com/apex/SMPDF_re?id="+smid);
document.location.reload();
}
else {
window.alert ("failed to update Sales Memo " + result[0]);
}
}
else {
window.alert ("No record found for Sales Memo Id : {!Sales_Memo__c.Id}" );
}

 

  • January 04, 2013
  • Like
  • 0