• lizmijohn
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 27
    Replies
Hi,

I have written the apex code for roll up summary using look up fields. My requirement is as follows.
Opportunity line item 1: Name - Product A  
                                     Quantity - 1
                                     Price - 100 AED
 Opportunity line item 2: Name - Product B  
                                     Quantity - 6
                                     Price - 250 AED

At Opportunity level: I created the following fields

Product A = Product A from line item 1
A Qty = Quantity from  line item 1
A Price = Price from  line item 1
  
Product B = Product B from line item 2
B Qty = Quantity from  line item 2
B Price = Price from  line item 2     

I wrote the trigger on Opportunity product as follows:
**********************************************************************************************************************
trigger Opplnitemtrigger on OpportunityLineItem(after delete, after insert, after undelete, after update) {
    Decimal sumOpplnitemqty = 0;
    Decimal sumOpplnitemprice = 0.00;
    String Opplnitemname =NULL;
    OpportunityLineItem[] cons;
    
     Set<ID> OppIds = new Set<ID>();
     if (trigger.isInsert || trigger.isUpdate || trigger.isUndelete) {
      for (OpportunityLineItem con : trigger.new) {
            OppIds.add(con.OpportunityId);
      }
    }
     if (Trigger.isDelete)
      cons = trigger.old;
    
    Map<ID,OpportunityLineItem>lineValue=new Map<ID, OpportunityLineItem>([select Id,OpportunityId,Quantity,UnitPrice,Product2.name,Tick_green__c,Tick_Defence__c,Tick_Tech__c,Tick_Smart__c from OpportunityLineItem where OpportunityId in:OppIds ]);
     
    Map<ID, Opportunity> OppToUpdate = new Map<ID, Opportunity>([select Id,Green_qty__c,Green_price__c,Green__c,Defence_qty__c,Defence_price__c,Defence__c,Technology__c,Tech_qty__c,Tech_price__c,
    
    Smart_Phone__c,Smart_Phone_price__c,Smart_Phone_qty__c from Opportunity where Id in :OppIds ]);
                                                                 
    for (Opportunity coun : OppToUpdate.values()) {
        Set<ID> conIds = new Set<ID>();
        for (OpportunityLineItem con : lineValue.values()) {
            
            sumOpplnitemqty = con.Quantity ;
            sumOpplnitemprice = con.UnitPrice;
            Opplnitemname  = con.Product2.name ;
            
          if((con.Product2.name == 'Green Basket') && (con.Tick_green__c == 1)){

            coun.Green_qty__c = sumOpplnitemqty;
            coun.Green_price__c= sumOpplnitemprice ;
            coun.Green__c = Opplnitemname;
            
            
            } else if((con.Product2.name == 'Defence Basket') && (con.Tick_Defence__c == TRUE)){
            
            coun.Defence_qty__c = sumOpplnitemqty;
            coun.Defence_price__c= sumOpplnitemprice ;
            coun.Defence__c = Opplnitemname ;
           
            
            }else if((con.Product2.name == 'Technology Basket') && (con.Tick_Tech__c == TRUE)){
            
            coun.Tech_qty__c = sumOpplnitemqty;
            coun.Tech_price__c= sumOpplnitemprice ;
            coun.Technology__c = Opplnitemname ;
            
            }else if((con.Product2.name == 'Smart Phone Basket') && (con.Tick_Smart__c == TRUE)){
            
            coun.Smart_Phone_qty__c = sumOpplnitemqty;
            coun.Smart_Phone_price__c= sumOpplnitemprice ;
            coun.Smart_Phone__c= Opplnitemname ;
            
            }else {
            sumOpplnitemqty = 0 ;
            sumOpplnitemprice = 0 ;
            Opplnitemname  = null  ;
            
            }
         }  
      }
    update OppToUpdate.values();      
*********************************************************************************************************

On update and insert of line item trigger, the fields in Opportunity are changed correctly. But when I delete one of the line item say Product B, even then the field in Opportunity (Product B, B Qty and B Price)   retains the value it took on insert or update. I would like to empty these fields on respective product's line item deletion.

Please help me for writing the code that action on line item deletion.

Thanks,
Liz
Hi,

I have 2 look up fields to  'source' & 'destination' objects and a pick list on Opportunity page. There is a custom object 'Orders' that is again have lookup fields to 'source' & 'destination' objects. 

Opp1 has Source - Dubai and Destination- Sharjah
Order 1 has Source - Dubai and Destination- Sharjah
Order 2 has Source - India and Destination- UAE

There is a button on Opportunity layout by name 'Lookup'. On click of button the 'Orders' related list must be filled with only the matching result. In this case the record will be 'Order 1' because Opp1 has the same source & destination as Order 1.

Please help.

Thanks,
Liz

Hi,

 

I have designed a VF page and placed a list button (Generate invoice) on Opportunity list view. On selecting required Opportunities from list & clicking on "Generate Invoice" button should display a VF page with Opportunity & Opportunity line item details.

 

Note: Placing the button on Detail page layout works fine. But I need this to be generated for more than 1 opportunity at a time using List button.

 

My VF code is as follows:

 

<apex:page standardController="Opportunity" showHeader="false" renderAs="pdf" standardstylesheets="false">
<head>
<style type="text/css">
body {font-family: "Arial" "Sans-Serif"; font-size:11px; }
@page {
@top-center {
content: element(header);
}
@bottom-center{
content: element(footer);
}
}

div.header {
padding: 5px;
position: static(header);
}
div.footer {

padding: 2px;
position: running(footer);
}


.pagenumber:before {
content: counter(page);
}
.pagecount:before {
content: counter(pages);
}
</style>
</head>

<div class="header">
<apex:image id="theImage" value="{!$Resource.AGT_Logo}" width="300" height="75"/>
</div>

<apex:form >
<h2 style="text-align:left;color:black;font-size:20px"> Salary Invoice Sales </h2>


<BR></BR>
<BR></BR>

<apex:pageBlock >

<apex:pageBlockTable value="{!Opportunity.OpportunityLineItems}" var="Oppdt" border="1" cellspacing="10" cellpadding="9" columnClasses="red,green,blue">
<apex:column headervalue="Contract"><apex:outputfield value="{!Oppdt.Contract_Ref_No__c}"/></apex:column>
<apex:column headervalue="Basket Type"><apex:outputfield value="{!Oppdt.PriceBookEntry.name}"/></apex:column>
<apex:column headervalue="Quantity"><apex:outputfield value="{!Oppdt.Quantity}"/></apex:column>
<apex:column headervalue="Cost Per Basket"><apex:outputfield value="{!Oppdt.UnitPrice}"/></apex:column>
<apex:column headervalue="Total"><apex:outputfield value="{!Oppdt.TotalPrice}"/></apex:column>

</apex:pageBlockTable>
</apex:pageBlock>
<BR></BR>
<BR></BR>
<BR></BR>

</apex:form>
</apex:page>

 

Please help.

 

Thanks,

Liz

Hi,

 

I have 3 objects:

Analysis (Parent of Project)

             Project (Parent of Project Analysis)

                        Project Analysis

On change of any field in Analysis, I need to mass update the Projects records for which I use a custom button. The code as follows:

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

var records = {!GETRECORDIDS($ObjectType.Project1__c)}; 
var newRecords = []; 

if (records[0] == null) 

alert("Please select at least one row") 

else 

for (var n=0; n<=records.length; n++) { 
var t = new sforce.SObject("Project1__c"); 
t.id = records[n]; 
newRecords.push(t); 

result = sforce.connection.update(newRecords); 

window.location.reload(); 
}

 

The code updates the changes in Project records. But on this update of Project records a trigger needs to  work on Project Analysis records as follows. But in my case Project analysis records will be changed to 0 records. Meaning the update trigger code as follows is not working due to some reason:

 

trigger EqupdProjectAnalysis on Project1__c(after update)
 {
    List<Project_Analysis__c> ProjectAnalysis = new List <Project_Analysis__c> {};
    for (Project1__c p : trigger.new)
    {
       if(p.Start_Date_check__c == 1)
        {
          Project1__c[] updrec = [select id,start_Date_check__c from Project1__c pj where id = :p.id]; 
          for(Project1__c p1:updrec)
          {
         
          p1.start_Date_check__c=0;
          update p1;
          }
          Project_Analysis__c[] objsToDelete = [select id from Project_Analysis__c ol1 where ol1.Project1__c = :p.id];  
          delete objsToDelete; 
        }
        if(p.Start_Date_check__c == 1)
        {
          if ((p.Project_Type__c!='Master')&&(p.EPC_Awarding_Date__c !=null))
             {
                Integer i = 0;
                date Date1= p.EPC_Awarding_Date__c ;
                date myDate1=Date1;
                Decimal x=0;
                Decimal y=0;
                for (i=0;i< p.No_of_Months__c; i++) 
                {
                   
                    if((myDate1>=p.EPC_Awarding_Date__c) && (myDate1 < p.EndDate__c))
                   {
                       if(myDate1<=p.Q1__c)
                       {
                           x=p.Eq_Q1_month__c;
                         }
                       else if(myDate1<=p.Q2__c)
                       {
                           x=p.Eq_Q2_month__c;
                        }
                        else if(myDate1<p.Q3__c)
                       {
                           x=p.Eq_Q3_month__c;
                        }
                       else if(myDate1>=p.Q3__c)
                       {
                           x=p.Eq_Q4_month__c;
                        } 
                       }
                     else
                     {
                         x=0;
                     }
                   
                   if((myDate1>=p.EPC_Awarding_Date__c) && (myDate1 < p.EndDate__c))
                  {
                       if(myDate1<=p.Q1_FM__c)
                       {
                           y=p.FM_Q1_month__c;
                          
                       }
                       else if(myDate1<=p.Q2_FM__c)
                       {
                           y=p.FM_Q2_month__c;
                        }
                        else if(myDate1<p.Q3_FM__c)
                       {
                           y=p.FM_Q3_month__c;
                        }
                       else if(myDate1>=p.Q3_FM__c)
                       {
                           y=p.FM_Q4_month__c;
                        } 
                      }
                     else
                     {
                         y=0;
                     }
                   
                  ProjectAnalysis.add(new Project_Analysis__c(Project1__c= p.Id,Amount_per_month__c=x,FM__c=y,Date__c = myDate1));       
                  MyDate1=MyDate1.addMonths(1); 
                 }               
                }
           }
         }
         try
         {
               insert ProjectAnalysis;
          }
          catch (Exception Ex)
          {    
               system.debug(Ex);
          }
     }

 

Note: If I individually edit and save the project record, project analysis records are populated correctly.

 

Any help is greatly appreciated.

 

Thanks,

Liz

Hi,

 

I want to invoke an apex trigger on click on 'Update' button in a list view.

The update button code on 'Onclick java script' is as follows:

 

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

var records = {!GETRECORDIDS($ObjectType.Project1__c)}; 
var newRecords = []; 

if (records[0] == null) 

alert("Please select at least one row") 

else 

for (var n=0; n<records.length; n++) { 
var t = new sforce.SObject("Project1__c"); 
t.id = records[n]; 
newRecords.push(t); 


result = sforce.connection.update(newRecords); 

window.location.reload(); 
}

 

And Apex trigger that needs to be invoked is as follows on button click:

 

trigger EqupdProjectAnalysis on Project1__c(after update)
 {
    List<Project_Analysis__c> ProjectAnalysis = new List <Project_Analysis__c> {};
    for (Project1__c p : trigger.new)
    {
       if(p.Start_Date_check__c == 1)
        {
          Project1__c[] updrec = [select id,start_date_check__c from Project1__c pj where id = :p.id]; 
          for(Project1__c p1:updrec)
          {
          p1.start_date_check__c=0;
          update p1;
          }
          Project_Analysis__c[] objsToDelete = [select id from Project_Analysis__c ol1 where ol1.Project1__c = :p.id];  
          delete objsToDelete; 
        }
        if(p.Start_Date_check__c == 1)
        {
          if ((p.Project_Type__c!='Master')&&(p.EPC_Awarding_Date__c !=null))
             {
                Integer i = 0;
                date Date1= p.EPC_Awarding_Date__c ;
                date myDate1=Date1;
                Decimal x=0;
                Decimal y=0;
                for (i=0;i< p.No_of_Months__c; i++) 
                {
                   
                   if((myDate1>=p.EPC_Awarding_Date__c) && (myDate1 < p.Q3__c))
                   {
                       if(myDate1<p.Q1__c)
                       {
                           x=p.Eq_Q1_month__c;
                       }
                       else
                       {
                           x=p.Eq_Q2_3_4_month__c;
                       }
                     }  
                     else
                     {
                         x=0;
                     }
                    if((myDate1>=p.EPC_Awarding_Date__c) && (myDate1 < p.Q3_FM__c))
                   {
                       if(myDate1<p.Q1_FM__c)
                       {
                           y=p.Eq_Q1_month_FM__c;
                       }
                       else if(myDate1<p.Q2_FM__c)
                       {
                           y=0;
                       }
                       else if(myDate1>=p.Q2_FM__c)
                       {
                           y=p.Eq_Q2_3_4_month_FM__c;
                       }
                     }  
                     else
                     {
                         y=0;
                     }
                  ProjectAnalysis.add(new Project_Analysis__c(Project1__c= p.Id,Amount_per_month__c=x,FM__c=y,Date__c = myDate1));       
                  MyDate1=MyDate1.addMonths(1); 
                 }               
                }
            }
         }
         try
         {
               insert ProjectAnalysis;
          }
          catch (Exception Ex)
          {    
               system.debug(Ex);
          }
     }

 

I assume there should be a line added in update custom button code as follows:

var result = sforce.apex.execute("class1", "method1",{iTitle : noteTitle});

 

But I do not have a global class defined. If I need to add let me know how to.

 

I am a big zero in coding. Please help.

 

Thanks.

 

Hi,

 

I have 'Project' as parent record and 'Project Analysis' as child records.

I have written a test class as follows:

 

@isTest
private class projecttrigger {
static testMethod void ProjectAnalysistrigger() {

Project1__c prj = new Project1__c();
prj.Name='P-006';
prj.Project_Name__c='Test-Rigs';
prj.Country__c='a0GL0000001G4mu';
prj.End_Market_Segment__c='Rigs';
prj.EPC_Awarding_Date__c=Date.newInstance(2014,6,1);
prj.EndDate__c=Date.newInstance(2017,6,1);
prj.Analysis_dell__c='a0CL0000000cIeN';
prj.ProjectValue__c=2000000;
prj.Eq_Q1_month_percent_Eq1__c = 0.8;
prj.Eq_Q1_month_percent_FM1__c = 0.6;
prj.Eq_Q2_3_4_month_percent_Eq1__c = 0.2;
prj.Eq_Q2_3_4_month_percent_FM1__c = 0.4;

Integer i = 0;
date Date1= prj.EPC_Awarding_Date__c;
date myDate1=Date1;
Decimal x=0;
Decimal y=0;

prj = [SELECT id,Name,Country__c,Project_Name__c,End_Market_Segment__c, Start_Date__c, EPC_Awarding_Date__c, Analysis_dell__c, ProjectValue__c, No_of_months__c,Eq_Q1_month__c,Eq_Q1_month_FM__c,Eq_Q2_3_4_month__c,Eq_Q2_3_4_month_FM__c,Eq_Q1_month_percent_Eq1__c,Eq_Q1_month_percent_FM1__c,Eq_Q2_3_4_month_percent_Eq1__c,Eq_Q2_3_4_month_percent_FM1__c FROM Project1__c WHERE id = :prj.id];
Project_Analysis__c[] analysisToCreate = new Project_Analysis__c[]{};


for (i=0;i< prj.No_of_Months__c; i++)
{

if((myDate1>=prj.EPC_Awarding_Date__c ) && (myDate1 < prj.Q3__c))
{
if(myDate1<prj.Q1__c)
{
x=prj.Eq_Q1_month__c;
}
else
{
x=prj.Eq_Q2_3_4_month__c;
}
}
else
{
x=0;
}

if((myDate1>=prj.EPC_Awarding_Date__c) && (myDate1 < prj.Q3_FM__c))
{
if(myDate1<prj.Q1_FM__c)
{
y=prj.Eq_Q1_month_FM__c;
}
else if(myDate1<prj.Q2_FM__c)
{
y=0;
}
else if(myDate1>=prj.Q2_FM__c)
{
y=prj.Eq_Q2_3_4_month_FM__c;
}
}
else
{
y=0;
}
Project_Analysis__c pa=new Project_Analysis__c(Project1__c= prj.Id,Amount_per_month__c=x,FM__c=y,Date__c = myDate1);
MyDate1=MyDate1.addMonths(1);
analysisToCreate.add(pa);
}

Test.startTest();
insert analysisToCreate;
Test.stopTest();

}
}

 

On running the test, I am getting the following error: 

Error Message System.QueryException: List has no rows for assignment to SObject

 

Please help

 

Thanks,

Liz

Hi,

 

I have a Parent object by name 'Project' and child related list by name 'Project Analysis'.

I have set the trigger on 'Project Analysis' so that I get the rollup summary on Project field 'Total Eq' & 'Total FM'.

The code is as follows and it works fine.

 

trigger EqSumTrigger on Project_Analysis__c(after delete, after insert, after undelete, after update) {
Decimal sumTotalEq = 0;
Decimal sumTotalFM = 0;
Decimal countFM = 0;
Decimal countEq = 0;
//sid = scl[0].Project_Analysis__c;
Project_Analysis__c[] cons;
if (Trigger.isDelete)
cons = Trigger.old;
else
cons = Trigger.new;

// get list of accounts
Set<ID> ProjectIds = new Set<ID>();
for (Project_Analysis__c con : cons) {
ProjectIds.add(con.Project1__c);
}

Map<ID, Project_Analysis__c> EqValue = new Map<ID, Project_Analysis__c>([select Id,Amount_per_month__c,FM__c from Project_Analysis__c where Project1__c in :ProjectIds]);

Map<ID, Project1__c> projectToUpdate = new Map<ID, Project1__c>([select Id,Total_Eq__c,Total_FM__c from Project1__c where Id in :ProjectIds]);



for (Project1__c coun : projectToUpdate.values()) {
Set<ID> conIds = new Set<ID>();
for (Project_Analysis__c con : EqValue.values()) {
sumTotalEq += con.Amount_per_month__c ;
sumTotalFM += con.FM__c;

}

coun.Total_Eq__c = sumTotalEq;
coun.Total_FM__c = sumTotalFM;

}

update projectToUpdate.values();

}

 

Now, I have 2  fields in Project by name 'EqCount' & 'FMCount'. This field should take the count of only those child records of which 'Amount_per_month__c' and 'FM__c ' are not equal to 0.

 

Please help.

Hi,

 

How to get the count of nymber of values selected in a multipicklist?

 

Eg: My multipicklist value has selected values as red/orange/green. Therefore the count field should get 3.

 

I am using PE edition. How can a formula or workflow be created for this?

 

Please help!

 

Thanks,

Liz

Hi, My requirement is as follows: I have a 'Stock' field in Product page with default value as 1. Once a product is allocated to an opportunity line item, I need a formula or workflow that updates the 'Stock' field in product page to 0. Basically to block the user to select the same product, as it will be blocked for an Account for a certain period. Also user can check the product's 'Stock' field before associating that to a new opportunity line item Is the above possible as I am using Professional Edition. But Workflow & Approval is enabled. Please help. Thanks, Liz

I have a unit test as follows:

 On running test i am getting the following error: "System.NullPointerException: Attempt to de-reference a null object"

 

Not able to figure out where exactly the problem is. Please help!

 



public class projecttrigger { 
    static testMethod void ProjectAnalysistrigger() {
    Project1__c prj = new Project1__c();
    prj.name='P-10000';
    prj.Project_Name__c='test project';
    prj.Country__c='a0GL00000009Ydl';
    prj.End_Market_Segment__c='Storage';
    prj.Start_Date__c=Date.newInstance(2011,6,1);
    prj.EndDate__c=Date.newInstance(2012,6,1);
    prj.Analysis_dell__c='a0CL00000004ijw';
    prj.ProjectValue__c=50000;
    
    insert prj;
     Project_Analysis__c[] analysisToCreate = new Project_Analysis__c[]{};
        
        Integer i=0;
        date Date1= prj.Start_Date__c;
        date myDate1=Date1;
    
        if (i <= (prj.No_of_months__c + 1)) {
        for (myDate1 = myDate1; myDate1 < prj.EndDate__c.addDays(25); myDate1= myDate1.addDays(31)) {
        analysisToCreate.add(new Project_Analysis__c(Project1__c= prj.Name,Amount_per_month__c= prj.Project_Value_per_month__c ,Date__c = myDate1,Start_Date__c=prj.Start_Date__c));
        }
        i=i+1;
        }
               


        Test.startTest();

        insert analysisToCreate;

        Test.stopTest();   

    }  

}

 

 

Hi,

 

Please help me with my requirement as follows:

 

Parent object: project

Child object :Project analysis

 

Trigger on :Project analysis

 

Scenario 1: Parent object (start date=1/6/2011 and end date=1/1/2012)

 

On Insert Project analysis will have records with date values as

PA 1 : Date-1/6/2011,PA 2:  Date-2/7/2011, PA 3: Date-2/8/2011,...PA 19: 10/12/2012.

 

On Update if I change Parent object's (start date=1/5/2011 and end date=1/1/2012) then the value are as follows:

PA 1 : Date-1/5/2011,PA 2:  Date-1/6/2011,...PA 18: 9/10/2012, PA-19: 10/12/2012

 

As per my understanding on change of parent object's start and end date, the child records are not incrementing or decrementing accordingly to take the correct date values.

 

My code is as below:

 

if(trigger.isupdate){
List<Project_Analysis__c> listPA= new List <Project_Analysis__c> ();

List<Project_Analysis__c> tbuPA = New List<Project_Analysis__c>();

listPA = [Select Project1__c,Amount_Per_Month__c,Date__c,Start_Date__c FROM Project_Analysis__c WHERE Project1__c IN :trigger.new];

for (Project1__c np : trigger.new) {Integer j = 0;

date NewDate=np.Start_Date__c;

date upDate1=NewDate;date Test;

for (Project1__c oProject : trigger.old){       

for(Project_Analysis__c lPA : listPA){         

if (lPA.Project1__c == np.id && ((np.Project_Value_per_month__c != lPA.Amount_per_month__c)&&(np.Start_Date__c!=lPA.Start_Date__c))){           

lPA.Amount_per_month__c = np.Project_Value_per_month__c;            if(np.No_of_months__c!=oProject.No_of_months__c){           

if(j <= (np.No_of_months__c)){               

if(upDate1< np.EndDate__c.addDays(25)){                 

  lPA.Date__c = upDate1;                                       

upDate1= upDate1.addDays(31);                                     

}                              

}             

j=j+1;                         

tbuPA.add(lPA);           

}       

}   

}   

}

if(tbuPA.size() > 0) 

update tbuPA;

}

 

 

Thanks in advance

Hi,

 

I have a custom object by name : Project

Child object name: ProjectAnalysis

 

Based on Project start date, End Date, Project Value, Project value per month in Project object , Project Analysis records will get generated. Please find the Trigger code:

 

trigger ProjectAnalysis on Project__c(after insert,after update) {if(trigger.isafter){   

if(trigger.isinsert)   

{    List<Project_Analysis__c> ProjectAnalysis = new List <Project_Analysis__c> {};    for (Project__c p : trigger.new) {    Integer i = 0;   

date Date1= p.StartDate__c;   

date myDate1=Date1;   

if (i <= (p.No_of_months__c + 1) ) {   

for (myDate1 = myDate1; myDate1 < p.EndDate__c.addDays(20); myDate1= myDate1.addDays(30)) {    ProjectAnalysis.add(new Project_Analysis__c(Project__c= p.Id, Amount_per_month__c= p.Project_Value_per_month__c, Date__c = myDate1));    }   

i=i+1;   

}   

}   

}

 

 

I need help to update the ProjectAnalysis records if there is a change in Project value per month/Start Date/End Date field in Project object on update.

 

Please help me on this.

 

Thanks in advance

Hi,

I have written the apex code for roll up summary using look up fields. My requirement is as follows.
Opportunity line item 1: Name - Product A  
                                     Quantity - 1
                                     Price - 100 AED
 Opportunity line item 2: Name - Product B  
                                     Quantity - 6
                                     Price - 250 AED

At Opportunity level: I created the following fields

Product A = Product A from line item 1
A Qty = Quantity from  line item 1
A Price = Price from  line item 1
  
Product B = Product B from line item 2
B Qty = Quantity from  line item 2
B Price = Price from  line item 2     

I wrote the trigger on Opportunity product as follows:
**********************************************************************************************************************
trigger Opplnitemtrigger on OpportunityLineItem(after delete, after insert, after undelete, after update) {
    Decimal sumOpplnitemqty = 0;
    Decimal sumOpplnitemprice = 0.00;
    String Opplnitemname =NULL;
    OpportunityLineItem[] cons;
    
     Set<ID> OppIds = new Set<ID>();
     if (trigger.isInsert || trigger.isUpdate || trigger.isUndelete) {
      for (OpportunityLineItem con : trigger.new) {
            OppIds.add(con.OpportunityId);
      }
    }
     if (Trigger.isDelete)
      cons = trigger.old;
    
    Map<ID,OpportunityLineItem>lineValue=new Map<ID, OpportunityLineItem>([select Id,OpportunityId,Quantity,UnitPrice,Product2.name,Tick_green__c,Tick_Defence__c,Tick_Tech__c,Tick_Smart__c from OpportunityLineItem where OpportunityId in:OppIds ]);
     
    Map<ID, Opportunity> OppToUpdate = new Map<ID, Opportunity>([select Id,Green_qty__c,Green_price__c,Green__c,Defence_qty__c,Defence_price__c,Defence__c,Technology__c,Tech_qty__c,Tech_price__c,
    
    Smart_Phone__c,Smart_Phone_price__c,Smart_Phone_qty__c from Opportunity where Id in :OppIds ]);
                                                                 
    for (Opportunity coun : OppToUpdate.values()) {
        Set<ID> conIds = new Set<ID>();
        for (OpportunityLineItem con : lineValue.values()) {
            
            sumOpplnitemqty = con.Quantity ;
            sumOpplnitemprice = con.UnitPrice;
            Opplnitemname  = con.Product2.name ;
            
          if((con.Product2.name == 'Green Basket') && (con.Tick_green__c == 1)){

            coun.Green_qty__c = sumOpplnitemqty;
            coun.Green_price__c= sumOpplnitemprice ;
            coun.Green__c = Opplnitemname;
            
            
            } else if((con.Product2.name == 'Defence Basket') && (con.Tick_Defence__c == TRUE)){
            
            coun.Defence_qty__c = sumOpplnitemqty;
            coun.Defence_price__c= sumOpplnitemprice ;
            coun.Defence__c = Opplnitemname ;
           
            
            }else if((con.Product2.name == 'Technology Basket') && (con.Tick_Tech__c == TRUE)){
            
            coun.Tech_qty__c = sumOpplnitemqty;
            coun.Tech_price__c= sumOpplnitemprice ;
            coun.Technology__c = Opplnitemname ;
            
            }else if((con.Product2.name == 'Smart Phone Basket') && (con.Tick_Smart__c == TRUE)){
            
            coun.Smart_Phone_qty__c = sumOpplnitemqty;
            coun.Smart_Phone_price__c= sumOpplnitemprice ;
            coun.Smart_Phone__c= Opplnitemname ;
            
            }else {
            sumOpplnitemqty = 0 ;
            sumOpplnitemprice = 0 ;
            Opplnitemname  = null  ;
            
            }
         }  
      }
    update OppToUpdate.values();      
*********************************************************************************************************

On update and insert of line item trigger, the fields in Opportunity are changed correctly. But when I delete one of the line item say Product B, even then the field in Opportunity (Product B, B Qty and B Price)   retains the value it took on insert or update. I would like to empty these fields on respective product's line item deletion.

Please help me for writing the code that action on line item deletion.

Thanks,
Liz
Hi,

I have 2 look up fields to  'source' & 'destination' objects and a pick list on Opportunity page. There is a custom object 'Orders' that is again have lookup fields to 'source' & 'destination' objects. 

Opp1 has Source - Dubai and Destination- Sharjah
Order 1 has Source - Dubai and Destination- Sharjah
Order 2 has Source - India and Destination- UAE

There is a button on Opportunity layout by name 'Lookup'. On click of button the 'Orders' related list must be filled with only the matching result. In this case the record will be 'Order 1' because Opp1 has the same source & destination as Order 1.

Please help.

Thanks,
Liz

Hi,

 

I have 3 objects:

Analysis (Parent of Project)

             Project (Parent of Project Analysis)

                        Project Analysis

On change of any field in Analysis, I need to mass update the Projects records for which I use a custom button. The code as follows:

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

var records = {!GETRECORDIDS($ObjectType.Project1__c)}; 
var newRecords = []; 

if (records[0] == null) 

alert("Please select at least one row") 

else 

for (var n=0; n<=records.length; n++) { 
var t = new sforce.SObject("Project1__c"); 
t.id = records[n]; 
newRecords.push(t); 

result = sforce.connection.update(newRecords); 

window.location.reload(); 
}

 

The code updates the changes in Project records. But on this update of Project records a trigger needs to  work on Project Analysis records as follows. But in my case Project analysis records will be changed to 0 records. Meaning the update trigger code as follows is not working due to some reason:

 

trigger EqupdProjectAnalysis on Project1__c(after update)
 {
    List<Project_Analysis__c> ProjectAnalysis = new List <Project_Analysis__c> {};
    for (Project1__c p : trigger.new)
    {
       if(p.Start_Date_check__c == 1)
        {
          Project1__c[] updrec = [select id,start_Date_check__c from Project1__c pj where id = :p.id]; 
          for(Project1__c p1:updrec)
          {
         
          p1.start_Date_check__c=0;
          update p1;
          }
          Project_Analysis__c[] objsToDelete = [select id from Project_Analysis__c ol1 where ol1.Project1__c = :p.id];  
          delete objsToDelete; 
        }
        if(p.Start_Date_check__c == 1)
        {
          if ((p.Project_Type__c!='Master')&&(p.EPC_Awarding_Date__c !=null))
             {
                Integer i = 0;
                date Date1= p.EPC_Awarding_Date__c ;
                date myDate1=Date1;
                Decimal x=0;
                Decimal y=0;
                for (i=0;i< p.No_of_Months__c; i++) 
                {
                   
                    if((myDate1>=p.EPC_Awarding_Date__c) && (myDate1 < p.EndDate__c))
                   {
                       if(myDate1<=p.Q1__c)
                       {
                           x=p.Eq_Q1_month__c;
                         }
                       else if(myDate1<=p.Q2__c)
                       {
                           x=p.Eq_Q2_month__c;
                        }
                        else if(myDate1<p.Q3__c)
                       {
                           x=p.Eq_Q3_month__c;
                        }
                       else if(myDate1>=p.Q3__c)
                       {
                           x=p.Eq_Q4_month__c;
                        } 
                       }
                     else
                     {
                         x=0;
                     }
                   
                   if((myDate1>=p.EPC_Awarding_Date__c) && (myDate1 < p.EndDate__c))
                  {
                       if(myDate1<=p.Q1_FM__c)
                       {
                           y=p.FM_Q1_month__c;
                          
                       }
                       else if(myDate1<=p.Q2_FM__c)
                       {
                           y=p.FM_Q2_month__c;
                        }
                        else if(myDate1<p.Q3_FM__c)
                       {
                           y=p.FM_Q3_month__c;
                        }
                       else if(myDate1>=p.Q3_FM__c)
                       {
                           y=p.FM_Q4_month__c;
                        } 
                      }
                     else
                     {
                         y=0;
                     }
                   
                  ProjectAnalysis.add(new Project_Analysis__c(Project1__c= p.Id,Amount_per_month__c=x,FM__c=y,Date__c = myDate1));       
                  MyDate1=MyDate1.addMonths(1); 
                 }               
                }
           }
         }
         try
         {
               insert ProjectAnalysis;
          }
          catch (Exception Ex)
          {    
               system.debug(Ex);
          }
     }

 

Note: If I individually edit and save the project record, project analysis records are populated correctly.

 

Any help is greatly appreciated.

 

Thanks,

Liz

Hi,

 

I want to invoke an apex trigger on click on 'Update' button in a list view.

The update button code on 'Onclick java script' is as follows:

 

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

var records = {!GETRECORDIDS($ObjectType.Project1__c)}; 
var newRecords = []; 

if (records[0] == null) 

alert("Please select at least one row") 

else 

for (var n=0; n<records.length; n++) { 
var t = new sforce.SObject("Project1__c"); 
t.id = records[n]; 
newRecords.push(t); 


result = sforce.connection.update(newRecords); 

window.location.reload(); 
}

 

And Apex trigger that needs to be invoked is as follows on button click:

 

trigger EqupdProjectAnalysis on Project1__c(after update)
 {
    List<Project_Analysis__c> ProjectAnalysis = new List <Project_Analysis__c> {};
    for (Project1__c p : trigger.new)
    {
       if(p.Start_Date_check__c == 1)
        {
          Project1__c[] updrec = [select id,start_date_check__c from Project1__c pj where id = :p.id]; 
          for(Project1__c p1:updrec)
          {
          p1.start_date_check__c=0;
          update p1;
          }
          Project_Analysis__c[] objsToDelete = [select id from Project_Analysis__c ol1 where ol1.Project1__c = :p.id];  
          delete objsToDelete; 
        }
        if(p.Start_Date_check__c == 1)
        {
          if ((p.Project_Type__c!='Master')&&(p.EPC_Awarding_Date__c !=null))
             {
                Integer i = 0;
                date Date1= p.EPC_Awarding_Date__c ;
                date myDate1=Date1;
                Decimal x=0;
                Decimal y=0;
                for (i=0;i< p.No_of_Months__c; i++) 
                {
                   
                   if((myDate1>=p.EPC_Awarding_Date__c) && (myDate1 < p.Q3__c))
                   {
                       if(myDate1<p.Q1__c)
                       {
                           x=p.Eq_Q1_month__c;
                       }
                       else
                       {
                           x=p.Eq_Q2_3_4_month__c;
                       }
                     }  
                     else
                     {
                         x=0;
                     }
                    if((myDate1>=p.EPC_Awarding_Date__c) && (myDate1 < p.Q3_FM__c))
                   {
                       if(myDate1<p.Q1_FM__c)
                       {
                           y=p.Eq_Q1_month_FM__c;
                       }
                       else if(myDate1<p.Q2_FM__c)
                       {
                           y=0;
                       }
                       else if(myDate1>=p.Q2_FM__c)
                       {
                           y=p.Eq_Q2_3_4_month_FM__c;
                       }
                     }  
                     else
                     {
                         y=0;
                     }
                  ProjectAnalysis.add(new Project_Analysis__c(Project1__c= p.Id,Amount_per_month__c=x,FM__c=y,Date__c = myDate1));       
                  MyDate1=MyDate1.addMonths(1); 
                 }               
                }
            }
         }
         try
         {
               insert ProjectAnalysis;
          }
          catch (Exception Ex)
          {    
               system.debug(Ex);
          }
     }

 

I assume there should be a line added in update custom button code as follows:

var result = sforce.apex.execute("class1", "method1",{iTitle : noteTitle});

 

But I do not have a global class defined. If I need to add let me know how to.

 

I am a big zero in coding. Please help.

 

Thanks.

 

Hi,

 

I have 'Project' as parent record and 'Project Analysis' as child records.

I have written a test class as follows:

 

@isTest
private class projecttrigger {
static testMethod void ProjectAnalysistrigger() {

Project1__c prj = new Project1__c();
prj.Name='P-006';
prj.Project_Name__c='Test-Rigs';
prj.Country__c='a0GL0000001G4mu';
prj.End_Market_Segment__c='Rigs';
prj.EPC_Awarding_Date__c=Date.newInstance(2014,6,1);
prj.EndDate__c=Date.newInstance(2017,6,1);
prj.Analysis_dell__c='a0CL0000000cIeN';
prj.ProjectValue__c=2000000;
prj.Eq_Q1_month_percent_Eq1__c = 0.8;
prj.Eq_Q1_month_percent_FM1__c = 0.6;
prj.Eq_Q2_3_4_month_percent_Eq1__c = 0.2;
prj.Eq_Q2_3_4_month_percent_FM1__c = 0.4;

Integer i = 0;
date Date1= prj.EPC_Awarding_Date__c;
date myDate1=Date1;
Decimal x=0;
Decimal y=0;

prj = [SELECT id,Name,Country__c,Project_Name__c,End_Market_Segment__c, Start_Date__c, EPC_Awarding_Date__c, Analysis_dell__c, ProjectValue__c, No_of_months__c,Eq_Q1_month__c,Eq_Q1_month_FM__c,Eq_Q2_3_4_month__c,Eq_Q2_3_4_month_FM__c,Eq_Q1_month_percent_Eq1__c,Eq_Q1_month_percent_FM1__c,Eq_Q2_3_4_month_percent_Eq1__c,Eq_Q2_3_4_month_percent_FM1__c FROM Project1__c WHERE id = :prj.id];
Project_Analysis__c[] analysisToCreate = new Project_Analysis__c[]{};


for (i=0;i< prj.No_of_Months__c; i++)
{

if((myDate1>=prj.EPC_Awarding_Date__c ) && (myDate1 < prj.Q3__c))
{
if(myDate1<prj.Q1__c)
{
x=prj.Eq_Q1_month__c;
}
else
{
x=prj.Eq_Q2_3_4_month__c;
}
}
else
{
x=0;
}

if((myDate1>=prj.EPC_Awarding_Date__c) && (myDate1 < prj.Q3_FM__c))
{
if(myDate1<prj.Q1_FM__c)
{
y=prj.Eq_Q1_month_FM__c;
}
else if(myDate1<prj.Q2_FM__c)
{
y=0;
}
else if(myDate1>=prj.Q2_FM__c)
{
y=prj.Eq_Q2_3_4_month_FM__c;
}
}
else
{
y=0;
}
Project_Analysis__c pa=new Project_Analysis__c(Project1__c= prj.Id,Amount_per_month__c=x,FM__c=y,Date__c = myDate1);
MyDate1=MyDate1.addMonths(1);
analysisToCreate.add(pa);
}

Test.startTest();
insert analysisToCreate;
Test.stopTest();

}
}

 

On running the test, I am getting the following error: 

Error Message System.QueryException: List has no rows for assignment to SObject

 

Please help

 

Thanks,

Liz

Hi,

 

I have a Parent object by name 'Project' and child related list by name 'Project Analysis'.

I have set the trigger on 'Project Analysis' so that I get the rollup summary on Project field 'Total Eq' & 'Total FM'.

The code is as follows and it works fine.

 

trigger EqSumTrigger on Project_Analysis__c(after delete, after insert, after undelete, after update) {
Decimal sumTotalEq = 0;
Decimal sumTotalFM = 0;
Decimal countFM = 0;
Decimal countEq = 0;
//sid = scl[0].Project_Analysis__c;
Project_Analysis__c[] cons;
if (Trigger.isDelete)
cons = Trigger.old;
else
cons = Trigger.new;

// get list of accounts
Set<ID> ProjectIds = new Set<ID>();
for (Project_Analysis__c con : cons) {
ProjectIds.add(con.Project1__c);
}

Map<ID, Project_Analysis__c> EqValue = new Map<ID, Project_Analysis__c>([select Id,Amount_per_month__c,FM__c from Project_Analysis__c where Project1__c in :ProjectIds]);

Map<ID, Project1__c> projectToUpdate = new Map<ID, Project1__c>([select Id,Total_Eq__c,Total_FM__c from Project1__c where Id in :ProjectIds]);



for (Project1__c coun : projectToUpdate.values()) {
Set<ID> conIds = new Set<ID>();
for (Project_Analysis__c con : EqValue.values()) {
sumTotalEq += con.Amount_per_month__c ;
sumTotalFM += con.FM__c;

}

coun.Total_Eq__c = sumTotalEq;
coun.Total_FM__c = sumTotalFM;

}

update projectToUpdate.values();

}

 

Now, I have 2  fields in Project by name 'EqCount' & 'FMCount'. This field should take the count of only those child records of which 'Amount_per_month__c' and 'FM__c ' are not equal to 0.

 

Please help.

Hi,

 

How to get the count of nymber of values selected in a multipicklist?

 

Eg: My multipicklist value has selected values as red/orange/green. Therefore the count field should get 3.

 

I am using PE edition. How can a formula or workflow be created for this?

 

Please help!

 

Thanks,

Liz

Hi,

 

I created a trigger who will the get the URL of my product's picture.

So far it's working as you can see

but i decided to create a pdf, my pictures will not appear

I don't understand what's happening =/

Sincerely,

 

I have a unit test as follows:

 On running test i am getting the following error: "System.NullPointerException: Attempt to de-reference a null object"

 

Not able to figure out where exactly the problem is. Please help!

 



public class projecttrigger { 
    static testMethod void ProjectAnalysistrigger() {
    Project1__c prj = new Project1__c();
    prj.name='P-10000';
    prj.Project_Name__c='test project';
    prj.Country__c='a0GL00000009Ydl';
    prj.End_Market_Segment__c='Storage';
    prj.Start_Date__c=Date.newInstance(2011,6,1);
    prj.EndDate__c=Date.newInstance(2012,6,1);
    prj.Analysis_dell__c='a0CL00000004ijw';
    prj.ProjectValue__c=50000;
    
    insert prj;
     Project_Analysis__c[] analysisToCreate = new Project_Analysis__c[]{};
        
        Integer i=0;
        date Date1= prj.Start_Date__c;
        date myDate1=Date1;
    
        if (i <= (prj.No_of_months__c + 1)) {
        for (myDate1 = myDate1; myDate1 < prj.EndDate__c.addDays(25); myDate1= myDate1.addDays(31)) {
        analysisToCreate.add(new Project_Analysis__c(Project1__c= prj.Name,Amount_per_month__c= prj.Project_Value_per_month__c ,Date__c = myDate1,Start_Date__c=prj.Start_Date__c));
        }
        i=i+1;
        }
               


        Test.startTest();

        insert analysisToCreate;

        Test.stopTest();   

    }  

}

 

 

Hi,

 

Please help me with my requirement as follows:

 

Parent object: project

Child object :Project analysis

 

Trigger on :Project analysis

 

Scenario 1: Parent object (start date=1/6/2011 and end date=1/1/2012)

 

On Insert Project analysis will have records with date values as

PA 1 : Date-1/6/2011,PA 2:  Date-2/7/2011, PA 3: Date-2/8/2011,...PA 19: 10/12/2012.

 

On Update if I change Parent object's (start date=1/5/2011 and end date=1/1/2012) then the value are as follows:

PA 1 : Date-1/5/2011,PA 2:  Date-1/6/2011,...PA 18: 9/10/2012, PA-19: 10/12/2012

 

As per my understanding on change of parent object's start and end date, the child records are not incrementing or decrementing accordingly to take the correct date values.

 

My code is as below:

 

if(trigger.isupdate){
List<Project_Analysis__c> listPA= new List <Project_Analysis__c> ();

List<Project_Analysis__c> tbuPA = New List<Project_Analysis__c>();

listPA = [Select Project1__c,Amount_Per_Month__c,Date__c,Start_Date__c FROM Project_Analysis__c WHERE Project1__c IN :trigger.new];

for (Project1__c np : trigger.new) {Integer j = 0;

date NewDate=np.Start_Date__c;

date upDate1=NewDate;date Test;

for (Project1__c oProject : trigger.old){       

for(Project_Analysis__c lPA : listPA){         

if (lPA.Project1__c == np.id && ((np.Project_Value_per_month__c != lPA.Amount_per_month__c)&&(np.Start_Date__c!=lPA.Start_Date__c))){           

lPA.Amount_per_month__c = np.Project_Value_per_month__c;            if(np.No_of_months__c!=oProject.No_of_months__c){           

if(j <= (np.No_of_months__c)){               

if(upDate1< np.EndDate__c.addDays(25)){                 

  lPA.Date__c = upDate1;                                       

upDate1= upDate1.addDays(31);                                     

}                              

}             

j=j+1;                         

tbuPA.add(lPA);           

}       

}   

}   

}

if(tbuPA.size() > 0) 

update tbuPA;

}

 

 

Thanks in advance