• Hammad Shah
  • NEWBIE
  • 25 Points
  • Member since 2010

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

Hello All,

 

I am having a hard time writing a test class to deploy the following Trigger.

 

 

 

trigger PA_Update_Percentage_Trigger on Productivity_Allocations__c (before update) {

String errmsg = '';
Boolean isError = false;

Productivity_Allocations__c NewPA = Trigger.new[0];
Productivity_Allocations__c OldPA = Trigger.old[0];

Decimal Percent3 = 0.00;
	if(OldPA.Allocation_Percentage__c== null){
	Percent3 = NewPA.Allocation_Percentage__c;
		}
		else
			{Percent3 = NewPA.Allocation_Percentage__c - OldPA.Allocation_Percentage__c;
			}	
			
Opportunity RelatedOp = [Select Id, Opportunity_Percentage_Allocated__c, OwnerId
					from Opportunity
					where Id =: NewPA.Opportunity_Name__c Limit 1]; 
					Percent3 = Percent3 + RelatedOp.Opportunity_Percentage_Allocated__c;
	if (Percent3 > 100.00){
	errmsg += 'Total Productivity Allocation percent is currently '+Percent3+'% The Total Allocation percentage cannot be greater than 100%';
	isError = true;
	NewPA.addError(errmsg);
							}

}

 

 

 

Please bare with me as I am mainly an admin who is trying to do some development work. I have done a lot of research on the boards along with the force.com cookbook to get the correct syntax, etc. I have many different version of the test classes I have written for this trigger. However I cant seem to get it correct. Any help would be greatly appreciated.

 

Regards,

Hammad Shah

Hello All,

 

I needed a bit of assistance from the Salesforce community. I have created a a Custom Object called Productivity Allocations. The purpose of this object is to allow users to add more then 1 sales person to any opportunity and split the revenue associated with this opportunity based on the amount of work each sales person has contributed in closing the deal. 

 

Please bare with me as I am mainly an admin who is trying to do some development work. I have done a lot of research on the boards along with the force.com cookbook to get the correct syntax, etc for this Trigger. However I believe I am doing something incorrectly as the Trigger is not functioning as it should.

 

Relationship:

Opportunity = Master

Productivity Allocations = Detail

 

Fields:

Allocation_Percentage__c (PA Object. Number field.)

Percentage_Allocated__c (Opportunity Object. Roll Up Sammary field summing all related PA records.)

 

Functionality:

Every time a Productivity Allocation (PA) record is updated I need to verify that the total cumilative percentage of all PA records relating to a specific opportunity do not = more then 100%. If the total percentage = more then 100% then I need to throw the emded error message.

 

Here is what I have so far.

trigger PA_Percentage_Check_on_Insert on Productivity_Allocations__c (before update) {

String errmsg = '';
Boolean isError = false;

Productivity_Allocations__c NewPA = Trigger.new[0];
Productivity_Allocations__c OldPA = Trigger.old[0];

Decimal Percent3 = 0.00;
	if(OldPA.Allocation_Percentage__c== null){
	Percent3 = NewPA.Allocation_Percentage__c;
		}
		else
			{Percent3 = NewPA.Allocation_Percentage__c - OldPA.Allocation_Percentage__c;
			}	
			
Opportunity RelatedOp = [Select Id, Opportunity_Percentage_Allocated__c, OwnerId
					from Opportunity
					where Id =: NewPA.Opportunity_Name__c Limit 1]; 
					Percent3 = Percent3 + RelatedOp.Opportunity_Percentage_Allocated__c;
	if (Percent3 > 100.00){
	errmsg += 'Total Productivity Allocation percent--'+Percent3+ 'cannot be greater then 100%';
	isError = true;
							}
						
	
	
}

 Any assistance would be greatly appreciated.

 

Regards,

Hammad Shah

 

Hello All,

 

I needed a bit of assistance from the Salesforce community. I have created a a Custom Object called Productivity Allocations. The purpose of this object is to allow users to add more then 1 sales person to any opportunity and split the revenue associated with this opportunity based on the amount of work each sales person has contributed in closing the deal. 

 

Please bare with me as I am mainly an admin who is trying to do some development work. I have done a lot of research on the boards along with the force.com cookbook to get the correct syntax, etc for this Trigger. However I believe I am doing something incorrectly as the Trigger is not functioning as it should.

 

Relationship:

Opportunity = Master

Productivity Allocations = Detail

 

Functionality:

Every time a new Opportunity is created I need to create a detail Productivity Allocations record with certain fields filled out.

 

Here is what I have so far.

 

 

Trigger Productivity_Allocation_Insert on Opportunity (after insert) {



    list<Productivity_Allocations__c> AddPA = new list<Productivity_Allocations__c>();

    for( Opportunity o : Trigger.new ){
        Productivity_Allocations__c PA = new Productivity_Allocations__c(
            Opportunity_Name__c = o.Id,
            Sales_Associate__c = O.OwnerId,
            Allocation_Percentage__c = 100.00);
            }
        insert AddPA;


}

 

 

 

Any and all input would be appreciated.

 

Regards,

Hammad Shah

 

 

 

Hello All,

 

I am having a hard time writing a test class to deploy the following Trigger.

 

 

 

trigger PA_Update_Percentage_Trigger on Productivity_Allocations__c (before update) {

String errmsg = '';
Boolean isError = false;

Productivity_Allocations__c NewPA = Trigger.new[0];
Productivity_Allocations__c OldPA = Trigger.old[0];

Decimal Percent3 = 0.00;
	if(OldPA.Allocation_Percentage__c== null){
	Percent3 = NewPA.Allocation_Percentage__c;
		}
		else
			{Percent3 = NewPA.Allocation_Percentage__c - OldPA.Allocation_Percentage__c;
			}	
			
Opportunity RelatedOp = [Select Id, Opportunity_Percentage_Allocated__c, OwnerId
					from Opportunity
					where Id =: NewPA.Opportunity_Name__c Limit 1]; 
					Percent3 = Percent3 + RelatedOp.Opportunity_Percentage_Allocated__c;
	if (Percent3 > 100.00){
	errmsg += 'Total Productivity Allocation percent is currently '+Percent3+'% The Total Allocation percentage cannot be greater than 100%';
	isError = true;
	NewPA.addError(errmsg);
							}

}

 

 

 

Please bare with me as I am mainly an admin who is trying to do some development work. I have done a lot of research on the boards along with the force.com cookbook to get the correct syntax, etc. I have many different version of the test classes I have written for this trigger. However I cant seem to get it correct. Any help would be greatly appreciated.

 

Regards,

Hammad Shah

Hello All,

 

I needed a bit of assistance from the Salesforce community. I have created a a Custom Object called Productivity Allocations. The purpose of this object is to allow users to add more then 1 sales person to any opportunity and split the revenue associated with this opportunity based on the amount of work each sales person has contributed in closing the deal. 

 

Please bare with me as I am mainly an admin who is trying to do some development work. I have done a lot of research on the boards along with the force.com cookbook to get the correct syntax, etc for this Trigger. However I believe I am doing something incorrectly as the Trigger is not functioning as it should.

 

Relationship:

Opportunity = Master

Productivity Allocations = Detail

 

Fields:

Allocation_Percentage__c (PA Object. Number field.)

Percentage_Allocated__c (Opportunity Object. Roll Up Sammary field summing all related PA records.)

 

Functionality:

Every time a Productivity Allocation (PA) record is updated I need to verify that the total cumilative percentage of all PA records relating to a specific opportunity do not = more then 100%. If the total percentage = more then 100% then I need to throw the emded error message.

 

Here is what I have so far.

trigger PA_Percentage_Check_on_Insert on Productivity_Allocations__c (before update) {

String errmsg = '';
Boolean isError = false;

Productivity_Allocations__c NewPA = Trigger.new[0];
Productivity_Allocations__c OldPA = Trigger.old[0];

Decimal Percent3 = 0.00;
	if(OldPA.Allocation_Percentage__c== null){
	Percent3 = NewPA.Allocation_Percentage__c;
		}
		else
			{Percent3 = NewPA.Allocation_Percentage__c - OldPA.Allocation_Percentage__c;
			}	
			
Opportunity RelatedOp = [Select Id, Opportunity_Percentage_Allocated__c, OwnerId
					from Opportunity
					where Id =: NewPA.Opportunity_Name__c Limit 1]; 
					Percent3 = Percent3 + RelatedOp.Opportunity_Percentage_Allocated__c;
	if (Percent3 > 100.00){
	errmsg += 'Total Productivity Allocation percent--'+Percent3+ 'cannot be greater then 100%';
	isError = true;
							}
						
	
	
}

 Any assistance would be greatly appreciated.

 

Regards,

Hammad Shah

 

Hello All,

 

I needed a bit of assistance from the Salesforce community. I have created a a Custom Object called Productivity Allocations. The purpose of this object is to allow users to add more then 1 sales person to any opportunity and split the revenue associated with this opportunity based on the amount of work each sales person has contributed in closing the deal. 

 

Please bare with me as I am mainly an admin who is trying to do some development work. I have done a lot of research on the boards along with the force.com cookbook to get the correct syntax, etc for this Trigger. However I believe I am doing something incorrectly as the Trigger is not functioning as it should.

 

Relationship:

Opportunity = Master

Productivity Allocations = Detail

 

Functionality:

Every time a new Opportunity is created I need to create a detail Productivity Allocations record with certain fields filled out.

 

Here is what I have so far.

 

 

Trigger Productivity_Allocation_Insert on Opportunity (after insert) {



    list<Productivity_Allocations__c> AddPA = new list<Productivity_Allocations__c>();

    for( Opportunity o : Trigger.new ){
        Productivity_Allocations__c PA = new Productivity_Allocations__c(
            Opportunity_Name__c = o.Id,
            Sales_Associate__c = O.OwnerId,
            Allocation_Percentage__c = 100.00);
            }
        insert AddPA;


}

 

 

 

Any and all input would be appreciated.

 

Regards,

Hammad Shah