• kingsix
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 15
    Replies

I have wrote some triggers in sandbox, but I don't know how to write test class for trigger?

 

This is one of my trigger, very simple,

 

 

trigger Accountchecking on Account (before insert) {
   if (Trigger.new[0].Name != NULL && Trigger.new[0].group__C != NULL && Trigger.new[0]. BillingCountry  != NULL)  {
       Account[] acc = [ select id from account WHERE name = :Trigger.new[0].Name and group__C=: trigger.new[0].group__C and  BillingCountry =:Trigger.new[0].BillingCountry];
       if (acc.size() > 0) {
           Trigger.new[0].Name.addError('Account Name ,Group and Country cannot be repeated!');
       }
   }
}

 

So, I should write one test class in apex, and then the trigger can be seen in org?

 

Great Thanks

 

 

Hello,

 

I wrote a trigger for Opportunity. I want to do 'When closed the Opportunity, close its Quotes automatically', but it didn't work. Please help to check the code, thanks!!

 

 

trigger QuoteClose on Opportunity(after insert, after update) {
Quote[] cList = new Quote[]{};
for(Opportunity opp : trigger.new)
{if (opp.StageName == 'Closed Won')
cList.add(new Quote(OpportunityId=opp.Id, Status = 'Close'));
}
if (cList != null && !cList.isEmpty())
Database.update(cList);
}

 

Hello,

 

I want to do the special  auto number for the quote.

 

Our opportunity's number is S0001, S0002, S0003................... something like this.

 

If the opportunity number is S0001, its quote auto number should be S0001-1, S0001-2, S0001-3

 

If the opportunity number is S0002, its quote auto number should be S0002-1, S0002-2, S0003-3

 

How can I do the quote auto number like this? Should I write some trigger?

 

Thanks for the help.

Hello,

 

I have a question about make quote with different currencies.

 

I have enabled the multi currencies in our org. (main currency is USD, second currency is EUR)

 

For example, I add product01 into the standard price book with USD price.

 

And then, I create an Account, Opporunity and Quote with EUR currency.  After that, I try to add the quote line item, but it's blank, I cannot find the product01 in it.

 

Should I create another product01 with EUR price?

 

So I should add double products in the future?

 

Is it right?

 

Thanks for the help.

 

 

Our salesforce is enterprise edition and my account's profile is system admin. I go to system write trigger & class everyday.

 

When I login system today, I cannot find 'create' & 'edit' button in the trigger page (also class page)!

 

It's so strange! What can I do to solve the problem??

There is a custom picklist field (payment__c) in Account, same as in Quote

 

Ok, if one people create an Account (also select one payment in it), and then create one opportunity, and then click 'add new Quote', the payment__c will be got automatically before save the quote (because it's same as Account's payment__C).

 

Is it possible? Anyone can tell me how to do it? Or will one trigger?

 

Thanks.

Hello,

 

I wrote the trigger to mapping the custom field 'Payment_Terms__c' (it's a picklist) between Accounts and Quote, but it show the error info when I save the trigger,

 

trigger test3 on Account (after insert, after update) {
    Map<String, String> SetupFormMap = new Map<String, String>();
    for (Account acc : System.Trigger.new){
        if (acc.Payment_Terms__c != null){
                SetupFormMap.put(acc.ID, acc.Payment_Terms__c);
        }


list<Quote> recordsforupdates = new List <Quote>();

For (Quote aacc :[Select OpportunityId, Payment_Terms__c from Quote where Payment_Terms__c IN : SetupFormMap.keySet()] )
 
{

if (SetupFormMap.containsKey(aacc.Payment_Terms__c)) {
           String actName = SetupFormMap.get(Payment_Terms__c);
            recordsforupdates.add (new recordsforupdates (Id = aacc.Id, Payment_Terms__c = actName));
               }
        }
}
update recordsforupdates;
        }

 

Anyone can help the me? Great Thanks.

Hello, I wrote a trigger for prevent duplicate account name and group__C, it works well when I create a account in account page. But it shows a error info when I convert lead to account.

 

trigger test2 on Account (before insert, before update) {
   if (Trigger.new[0].Name != NULL)  {
       Account[] acc = [ select id from account WHERE name = :Trigger.new[0].Name and group__C=: trigger.new[0].group__C];
       if (acc.size() > 0) {
           Trigger.new[0].Name.addError('Name with Group already exists');
       }
   }
}

 

Anyone can help me? Thanks!

I got a error message with my Trigger. I just want to do, if Quote's status is ''Accepted', so Opportunity's stage change to 'Closed Won' automaticlly.

 

trigger test on Quote(after insert, after update) {
List<Opportunity> stageToUpdate = new List<Opportunity>();

for(Quote quo : trigger.new)
{if (quo.status == 'Accepted')
stageToUpdate.add(new Opportunity(Id=quo.Id, StageName = 'Closed Won'));
}
if (stageToUpdate != null && !stageToUpdate.isEmpty())
Database.update(stageToUpdate);
}

 

Error message,

execution of AfterUpdate caused by: System.TypeException: Invalid id value for this SObject type: 0Q09000000009qYCAQ: Trigger.test: line 6, column 38

Hello, I wrote one class and one trigger for process. If someone change the Quote status to 'accepted', the opportunities stage change to 'Closed Won' automaticly. But my codes has some problem when it running. Can anyone help me?

 

Class,

 

public with sharing class Stagechange {
  
      public static void Stagech(List<Quote> myQuote){
      
      for(Quote st1 :myQuote){
        if(st1.Status ==''accepted'){
          
                  
          Opportunity a01 = new Opportunity ();
          a01.AccountId = st1.Id;
          a01.Stagename = 'Closed Won';

         update a01;  

          
        }
        
      }
      
    }
    
}

 

 

Trigger,

 

trigger test on Quote (after update) {
  
    if(Trigger.isUpdate){
      
       List<Quote> st = trigger.new;
       Stagechange.Stagech(st);        

        
    }
}

 

 

Hello,

 

I wrote a trigger for Opportunity. I want to do 'When closed the Opportunity, close its Quotes automatically', but it didn't work. Please help to check the code, thanks!!

 

 

trigger QuoteClose on Opportunity(after insert, after update) {
Quote[] cList = new Quote[]{};
for(Opportunity opp : trigger.new)
{if (opp.StageName == 'Closed Won')
cList.add(new Quote(OpportunityId=opp.Id, Status = 'Close'));
}
if (cList != null && !cList.isEmpty())
Database.update(cList);
}

 

Hello,

 

I want to do the special  auto number for the quote.

 

Our opportunity's number is S0001, S0002, S0003................... something like this.

 

If the opportunity number is S0001, its quote auto number should be S0001-1, S0001-2, S0001-3

 

If the opportunity number is S0002, its quote auto number should be S0002-1, S0002-2, S0003-3

 

How can I do the quote auto number like this? Should I write some trigger?

 

Thanks for the help.

Hello,

 

I have a question about make quote with different currencies.

 

I have enabled the multi currencies in our org. (main currency is USD, second currency is EUR)

 

For example, I add product01 into the standard price book with USD price.

 

And then, I create an Account, Opporunity and Quote with EUR currency.  After that, I try to add the quote line item, but it's blank, I cannot find the product01 in it.

 

Should I create another product01 with EUR price?

 

So I should add double products in the future?

 

Is it right?

 

Thanks for the help.

 

 

Our salesforce is enterprise edition and my account's profile is system admin. I go to system write trigger & class everyday.

 

When I login system today, I cannot find 'create' & 'edit' button in the trigger page (also class page)!

 

It's so strange! What can I do to solve the problem??

There is a custom picklist field (payment__c) in Account, same as in Quote

 

Ok, if one people create an Account (also select one payment in it), and then create one opportunity, and then click 'add new Quote', the payment__c will be got automatically before save the quote (because it's same as Account's payment__C).

 

Is it possible? Anyone can tell me how to do it? Or will one trigger?

 

Thanks.

Hello, I wrote a trigger for prevent duplicate account name and group__C, it works well when I create a account in account page. But it shows a error info when I convert lead to account.

 

trigger test2 on Account (before insert, before update) {
   if (Trigger.new[0].Name != NULL)  {
       Account[] acc = [ select id from account WHERE name = :Trigger.new[0].Name and group__C=: trigger.new[0].group__C];
       if (acc.size() > 0) {
           Trigger.new[0].Name.addError('Name with Group already exists');
       }
   }
}

 

Anyone can help me? Thanks!

I got a error message with my Trigger. I just want to do, if Quote's status is ''Accepted', so Opportunity's stage change to 'Closed Won' automaticlly.

 

trigger test on Quote(after insert, after update) {
List<Opportunity> stageToUpdate = new List<Opportunity>();

for(Quote quo : trigger.new)
{if (quo.status == 'Accepted')
stageToUpdate.add(new Opportunity(Id=quo.Id, StageName = 'Closed Won'));
}
if (stageToUpdate != null && !stageToUpdate.isEmpty())
Database.update(stageToUpdate);
}

 

Error message,

execution of AfterUpdate caused by: System.TypeException: Invalid id value for this SObject type: 0Q09000000009qYCAQ: Trigger.test: line 6, column 38