• developernewbie
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 9
    Replies
Hello,

I am new to developing code in Apex, so mind my errors. To give you a background of what the current scenario looks like

There is a Master Object  say  Object Master.

Object A and Object B each have a Master -Detail relationship with with Object Master

Object A:
Fields-
-Date
-Amount A

Object B:
Fields-
-Date
-Amount B


What I am trying to achieve in my code is that ;

if date of object A matches date of object B then i would like the value of Amount A equal to Amount B. I am trying to write this in a Class and having trouble getting to this.

The reason there are two objects - Object B is actualzied with a Data Load at end of every month with actual numbers. This then I would like to flow in to Object A so as to show reveue in that object.

Thanks in advance for helping!

Hi everyone,

 

I am new to the whole force.com platform and with the help of these discussion boards was able to write quite a bit of the code below.

 

here is what i am trying to achieve: I am trying to capture the unit price associated with each product on an opportunity level and display it in a new object (called- RevenueObject)

These product names are named like this:

eg. test/email/testproduct/ with Unit price say 400

 

I have to read these product names to search for key words like "/email" and then capture the revenue associated with it and update a counter field.

 

RevenueObject Fields-

 

FieldA - Counter number field ; FieldB - Currency; FieldC - Counter number field ; FieldD - Currency

 

The code below is able to read these product names and capture revenue and update counter. But here is the issue, it updates the revenue and counter fields (FieldA, FieldB, FieldC, FieldD) every time I save the opportunity- in turn double counting. I just want to capture one instance of it.

 

Currently RevenueObject UI shows (I saved the opportunity twice) -

FieldA - 2 (should be 1)

FieldB - $800 (should be $400)

 

Here is my code-

 

 

 

trigger RevenueProject2 on Opportunity (after insert, after update) {

String myString1 = '/email';
String myString2 = '/rb';

RevenueObject__c rO = [Select FieldA__c, FieldB__c, FieldC__c, FieldD__c from RevenueObject__c where Id='a0tW0000000JwFu'] ;
                              
List <RevenueObject__c> rOList = new List<RevenueObject__c>();

double i=0.0;
decimal j= 0.00;



 // This is to create a list of all product names 
 List<OpportunityLineItem>   Product = 
        [Select CustomProdName__c, UnitPrice
         from OpportunityLineItem 
         where Opportunity.StageName != 'Closed Lost' 
         ]; // excluded FOR update
        
       
// The for loop is to go through each product name and to categorize product types     
    
for(OpportunityLineItem prdct: Product) {
        
        
        if(prdct.CustomProdName__c.contains(myString1)) 
        {   
        if(rO.FieldA__c !=null || rO.FieldB__c !=null)
        	{ 
        	i = rO.FieldA__c; 
        	i++;                     //Updates Counter
        	rO.FieldA__c = i;       // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldB__c += j;
        	}
        	else{
        	rO.FieldA__c = 0;	// To avoid null exception
        	rO.FieldB__c = 0;
        	i = rO.FieldA__c; 
        	i++;                   //Updates Counter
        	rO.FieldA__c = i;     // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldB__c += j;
        	}
        }
        else
        if(prdct.CustomProdName__c.contains(myString2)) 
        {
            if(rO.FieldC__c !=null || rO.FieldD__c !=null)
            {
                i = rO.FieldC__c;  
        	i++;                    //Updates Counter
        	rO.FieldC__c = i;      // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldD__c += j;
            }
            else{
            rO.FieldC__c = 0;
            rO.FieldD__c = 0;
           i = rO.FieldC__c;  
        	i++;                    //Updates Counter
        	rO.FieldC__c = i;      // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldD__c += j;
            }
        }
    
    }// for loop
    
    // for updating field
     
     	update rO;
     
     
} // for trigger

 

In my revenue object I do have a Lookip relationship field to the opportunity. I understand that i should check for for opportunity id in the code..but I am having a hard time tryiing to figure this out.

 

I apoloize for the long post. but any help will be a bonus for me.

 

thanks in advance for al the help.

 

I am new to salesforce development and having an issue with this error. The code compiles fine and has no errors however, when trying to save a product i get this error:

 

" RevenueProject2: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object:

Trigger.RevenueProject2: line 58, column 1 "

 

Aim of project is to search for keywords ( all myString varaibles) in the product name and then copy the sales price to a a field in the RevenueObject. Along with that, I also have a field set up for all products that gives a running counter on the number of entries for each product.

 

The error is on this line: i = rO.FieldA__c;

 

Here is my code:

 

trigger RevenueProject2 on Opportunity (after insert, after update) {

String myString1 = '/test1';
String myString2 = '/test2';
String myString3 = 'test3';
RevenueObject__c rO;
double i;
decimal j= 0.00;

 // This is to create a list of all product names 
 List<OpportunityLineItem>   Product = 
        [Select CustomProductName__c, UnitPrice
         from OpportunityLineItem 
         where Opportunity.StageName != 'Closed Lost' 
         ]; 
        
    // The for loop is to go through each  product name and to categorize product types     
    for(OpportunityLineItem prdct: Product) {

		if(prdct.CustomProductName__c.contains(myString1)) 
        {
        	i = rO.FieldA__c; 
        	i++;                       //Updates Counter
        	rO.FieldA__c = i;           // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldB__c += j;
        	
        }
        else
        if(prdct.CustomProductName__c.contains(myString2))
        {
                i = rO.FieldC__c;  
        	i++;                        //Updates Counter
        	rO.FieldC__c = i;          // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldD__c += j;
        	
        }
        else
        if(prdct.CustomProductName__c.contains(myString3)) 
        {
        	i = rO.FieldE__c;
        	i++;                       //Updates Counter
        	rO.FieldE__c = i;         // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldF__c += j;
        	
        }
	else
        if(prdct.CustomProdName__c.contains(myString4)) 
        {
        	i = rO.FieldG__c;
        	i++;                        //Updates Counter
        	rO.FieldG__c = i;          // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldH__c += j;
        	
        }

    }
}

 

 

Hi,

I am new to Salesforce developement and am having an roadblock trying to solve this.

I am trying to write a code that would search/find read for a certain keywords in a  line item and then classify them to a master category.

For example if there are multiple line items like below: 

Line item on opportunity A= abc/open/def/ghi;
Line item on Opportunity B = def/xyz/open/lmn
Line item on opportunity C = lmn/closed/ijk/def
Line item on Opportunity D = pqr/stu/closed/cde

I want to search for "open" and "closed" in these line items and bucket these line items to a master category:
Open and Closed

I understand search() could be a function to use but not sure how to use.

Thanks in advance!

Hello,

I am new to developing code in Apex, so mind my errors. To give you a background of what the current scenario looks like

There is a Master Object  say  Object Master.

Object A and Object B each have a Master -Detail relationship with with Object Master

Object A:
Fields-
-Date
-Amount A

Object B:
Fields-
-Date
-Amount B


What I am trying to achieve in my code is that ;

if date of object A matches date of object B then i would like the value of Amount A equal to Amount B. I am trying to write this in a Class and having trouble getting to this.

The reason there are two objects - Object B is actualzied with a Data Load at end of every month with actual numbers. This then I would like to flow in to Object A so as to show reveue in that object.

Thanks in advance for helping!
Hello,

I am new to developing code in Apex, so mind my errors. To give you a background of what the current scenario looks like

There is a Master Object  say  Object Master.

Object A and Object B each have a Master -Detail relationship with with Object Master

Object A:
Fields-
-Date
-Amount A

Object B:
Fields-
-Date
-Amount B


What I am trying to achieve in my code is that ;

if date of object A matches date of object B then i would like the value of Amount A equal to Amount B. I am trying to write this in a Class and having trouble getting to this.

The reason there are two objects - Object B is actualzied with a Data Load at end of every month with actual numbers. This then I would like to flow in to Object A so as to show reveue in that object.

Thanks in advance for helping!

Hi everyone,

 

I am new to the whole force.com platform and with the help of these discussion boards was able to write quite a bit of the code below.

 

here is what i am trying to achieve: I am trying to capture the unit price associated with each product on an opportunity level and display it in a new object (called- RevenueObject)

These product names are named like this:

eg. test/email/testproduct/ with Unit price say 400

 

I have to read these product names to search for key words like "/email" and then capture the revenue associated with it and update a counter field.

 

RevenueObject Fields-

 

FieldA - Counter number field ; FieldB - Currency; FieldC - Counter number field ; FieldD - Currency

 

The code below is able to read these product names and capture revenue and update counter. But here is the issue, it updates the revenue and counter fields (FieldA, FieldB, FieldC, FieldD) every time I save the opportunity- in turn double counting. I just want to capture one instance of it.

 

Currently RevenueObject UI shows (I saved the opportunity twice) -

FieldA - 2 (should be 1)

FieldB - $800 (should be $400)

 

Here is my code-

 

 

 

trigger RevenueProject2 on Opportunity (after insert, after update) {

String myString1 = '/email';
String myString2 = '/rb';

RevenueObject__c rO = [Select FieldA__c, FieldB__c, FieldC__c, FieldD__c from RevenueObject__c where Id='a0tW0000000JwFu'] ;
                              
List <RevenueObject__c> rOList = new List<RevenueObject__c>();

double i=0.0;
decimal j= 0.00;



 // This is to create a list of all product names 
 List<OpportunityLineItem>   Product = 
        [Select CustomProdName__c, UnitPrice
         from OpportunityLineItem 
         where Opportunity.StageName != 'Closed Lost' 
         ]; // excluded FOR update
        
       
// The for loop is to go through each product name and to categorize product types     
    
for(OpportunityLineItem prdct: Product) {
        
        
        if(prdct.CustomProdName__c.contains(myString1)) 
        {   
        if(rO.FieldA__c !=null || rO.FieldB__c !=null)
        	{ 
        	i = rO.FieldA__c; 
        	i++;                     //Updates Counter
        	rO.FieldA__c = i;       // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldB__c += j;
        	}
        	else{
        	rO.FieldA__c = 0;	// To avoid null exception
        	rO.FieldB__c = 0;
        	i = rO.FieldA__c; 
        	i++;                   //Updates Counter
        	rO.FieldA__c = i;     // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldB__c += j;
        	}
        }
        else
        if(prdct.CustomProdName__c.contains(myString2)) 
        {
            if(rO.FieldC__c !=null || rO.FieldD__c !=null)
            {
                i = rO.FieldC__c;  
        	i++;                    //Updates Counter
        	rO.FieldC__c = i;      // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldD__c += j;
            }
            else{
            rO.FieldC__c = 0;
            rO.FieldD__c = 0;
           i = rO.FieldC__c;  
        	i++;                    //Updates Counter
        	rO.FieldC__c = i;      // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldD__c += j;
            }
        }
    
    }// for loop
    
    // for updating field
     
     	update rO;
     
     
} // for trigger

 

In my revenue object I do have a Lookip relationship field to the opportunity. I understand that i should check for for opportunity id in the code..but I am having a hard time tryiing to figure this out.

 

I apoloize for the long post. but any help will be a bonus for me.

 

thanks in advance for al the help.

 

I am new to salesforce development and having an issue with this error. The code compiles fine and has no errors however, when trying to save a product i get this error:

 

" RevenueProject2: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object:

Trigger.RevenueProject2: line 58, column 1 "

 

Aim of project is to search for keywords ( all myString varaibles) in the product name and then copy the sales price to a a field in the RevenueObject. Along with that, I also have a field set up for all products that gives a running counter on the number of entries for each product.

 

The error is on this line: i = rO.FieldA__c;

 

Here is my code:

 

trigger RevenueProject2 on Opportunity (after insert, after update) {

String myString1 = '/test1';
String myString2 = '/test2';
String myString3 = 'test3';
RevenueObject__c rO;
double i;
decimal j= 0.00;

 // This is to create a list of all product names 
 List<OpportunityLineItem>   Product = 
        [Select CustomProductName__c, UnitPrice
         from OpportunityLineItem 
         where Opportunity.StageName != 'Closed Lost' 
         ]; 
        
    // The for loop is to go through each  product name and to categorize product types     
    for(OpportunityLineItem prdct: Product) {

		if(prdct.CustomProductName__c.contains(myString1)) 
        {
        	i = rO.FieldA__c; 
        	i++;                       //Updates Counter
        	rO.FieldA__c = i;           // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldB__c += j;
        	
        }
        else
        if(prdct.CustomProductName__c.contains(myString2))
        {
                i = rO.FieldC__c;  
        	i++;                        //Updates Counter
        	rO.FieldC__c = i;          // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldD__c += j;
        	
        }
        else
        if(prdct.CustomProductName__c.contains(myString3)) 
        {
        	i = rO.FieldE__c;
        	i++;                       //Updates Counter
        	rO.FieldE__c = i;         // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldF__c += j;
        	
        }
	else
        if(prdct.CustomProdName__c.contains(myString4)) 
        {
        	i = rO.FieldG__c;
        	i++;                        //Updates Counter
        	rO.FieldG__c = i;          // Assigns counter to field  
        	j = prdct.UnitPrice;
        	rO.FieldH__c += j;
        	
        }

    }
}

 

 

Hi,

I am new to Salesforce developement and am having an roadblock trying to solve this.

I am trying to write a code that would search/find read for a certain keywords in a  line item and then classify them to a master category.

For example if there are multiple line items like below: 

Line item on opportunity A= abc/open/def/ghi;
Line item on Opportunity B = def/xyz/open/lmn
Line item on opportunity C = lmn/closed/ijk/def
Line item on Opportunity D = pqr/stu/closed/cde

I want to search for "open" and "closed" in these line items and bucket these line items to a master category:
Open and Closed

I understand search() could be a function to use but not sure how to use.

Thanks in advance!