function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
suresh143suresh143 

hi .The creator(Owner of the opportunity) will get copied to Initial Owner field.

.The creator(Owner of the opportunity) will get copied to Initial Owner field. for trigger pls give that code

hitesh90hitesh90

is Initial Owner field is a custom field of opportunity? if yes, what is the API name of it? and

when you want to copy owner of opportunity to Initial Owner field?

at the time of insert or update or both?

suresh143suresh143
I mean asking about trigger code pls iam new about sales force
hitesh90hitesh90

Hi Suresh,

 

Apex Trigger:

trigger trigExample on Opportunity(before insert, before update){ 
    for(Opportunity Opp:trigger.new){
	Opp.Initial_Owner_field__c = Opp.OwnerId;
    }
}

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/

suresh143suresh143
Hi Hitesh,
Its fine working get id record and one more thing need test class for this one pls .................. iam new converted siebel to sales force iam not understand pls give that code pls..........................
trigger ValidateAmountValueAndTotalamount on Opportunity ( before insert, before update ) {

for ( Opportunity opp : Trigger.new )

{

if(opp.name!=null)

{

user usr=[select id,name from user where id =: opp.ownerid];

opp.Owner_field__c=usr.name;

String CSDRid= [Select Id from RecordType where RecordType.Name='Sales Opportunity-CSD'].Id;

if(opp.Stagename == 'New Opportunity' && opp.Probability == 10 && opp.RecordTypeId==CSDRid)

{

if(opp.Amount == null)

{

opp.Amount.addError('****enter something yar****');

}

if ( opp.Total_Amount__c == null )

{

opp.Total_Amount__c.addError( 'Please enter a value Total Amount.' );

}

}


hitesh90hitesh90

Hi Suresh,

 

Below is the test class for your trigger.

 

Apex Trigger:

@istest(seealldata=true)
public class TestValidateAmountValAndTotalamount{
	public static testmethod void TestValidateAmountValAndTotalamount(){
		Opportunity op = new Opportunity();
		op.Name='test';
		op.StageName='New Opportunity';
		op.Probability = 10;
		op.CloseDate=system.today();
		op.Amount = 10;
		insert op;
	}
}

 

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/

suresh143suresh143
Hi Hitesh so you are great dear but where i have to write that above menctioned code pls give that reply
suresh143suresh143
Hi hitesh iam giving my full code for trigger pls give that test code :
trigger ValidateAmountValueAndTotalamount on Opportunity ( before insert, before update )
{
for ( Opportunity opp : Trigger.new )
{
if(opp.name!=null)
{
user usr=[select id,name from user where id =: opp.ownerid];

opp.Owner_field__c=usr.name;

String CSDRid= [Select Id from RecordType where RecordType.Name='Sales Opportunity-CSD'].Id;

if(opp.Stagename == 'New Opportunity' && opp.Probability == 10 && opp.RecordTypeId==CSDRid)
{
if(opp.Amount == null)
{
opp.Amount.addError('****enter something yar****');
}
if ( opp.Total_Amount__c == null )
{
opp.Total_Amount__c.addError( 'Please enter a value Total Amount.' );
}

}

else if ( opp.StageName == 'Qualification' && opp.Probability == 10 && opp.RecordTypeId==CSDRid)
{

if ( opp.Amount == null )
{
opp.Amount.addError( 'Please********** ' );
}
if ( opp.Total_Amount__c == null )
{
opp.Total_Amount__c.addError( 'Please enter a value Total Amount****.' );
}
}

else if ( opp.StageName == 'Value Proposition' && opp.Probability == 50 && opp.RecordTypeId==CSDRid )
{

if ( opp.Amount == null )
{
opp.Amount.addError( 'only stars**********.' );
}
if ( opp.Total_Amount__c == null )
{
opp.Total_Amount__c.addError( 'here also ***********' );
}
}
else if ( opp.StageName == 'Prospecting' && opp.Probability == 10 && opp.RecordTypeId==CSDRid )
{
if(opp.Two_Year_Revenue__c == 0)
{
opp.Two_Year_Revenue__c.addError( 'Please enter a Two_Year_Revenue__c.' );
}
if(opp.customer_Quotation_Date__c == null)
{
opp.customer_Quotation_Date__c.addError( 'Please enter a customer_Quotation_Date__c.' );
}
if ( opp.Amount == null )
{
opp.Amount.addError( '@@@@@@@@@@@@@Please enter a Amount.' );
}
if ( opp.Total_Amount__c == null )
{
opp.Total_Amount__c.addError( '@@@@@@@@@@@@Please enter a value Total Amount.' );
}
}

}
}
}
hitesh90hitesh90

you have to create new apex class which i have given to you.

and insert more opportunity test record in that class as per your different conditions.

suresh143suresh143
pls give that code iam new pls ....................