-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
10Questions
-
15Replies
Don't know how to write test class for trigger
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
-
- kingsix
- May 30, 2011
- Like
- 0
- Continue reading or reply
When closed the Opportunity, close its Quotes automatically
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!!
-
- kingsix
- May 04, 2011
- Like
- 0
- Continue reading or reply
Special Auto Number
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.
-
- kingsix
- April 22, 2011
- Like
- 0
- Continue reading or reply
Quote with multi currencies?
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.
-
- kingsix
- April 20, 2011
- Like
- 0
- Continue reading or reply
System admin cannot create/edit trigger & class today! Strange!
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??
-
- kingsix
- April 16, 2011
- Like
- 0
- Continue reading or reply
Get info from different object's field automatically, is it possible?
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.
-
- kingsix
- April 14, 2011
- Like
- 0
- Continue reading or reply
Map custom picklist between Accounts and Quote
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.
-
- kingsix
- April 12, 2011
- Like
- 0
- Continue reading or reply
Trigger for prevent the duplicate account name when lead convert to account
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!
-
- kingsix
- April 11, 2011
- Like
- 0
- Continue reading or reply
Error Trigger with Quote Id
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
-
- kingsix
- April 07, 2011
- Like
- 0
- Continue reading or reply
The Problem with Trigger (Update stagename)
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);
}
}
-
- kingsix
- April 07, 2011
- Like
- 0
- Continue reading or reply
When closed the Opportunity, close its Quotes automatically
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!!
- kingsix
- May 04, 2011
- Like
- 0
- Continue reading or reply
Special Auto Number
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.
- kingsix
- April 22, 2011
- Like
- 0
- Continue reading or reply
Quote with multi currencies?
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.
- kingsix
- April 20, 2011
- Like
- 0
- Continue reading or reply
System admin cannot create/edit trigger & class today! Strange!
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??
- kingsix
- April 16, 2011
- Like
- 0
- Continue reading or reply
Get info from different object's field automatically, is it possible?
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.
- kingsix
- April 14, 2011
- Like
- 0
- Continue reading or reply
Trigger for prevent the duplicate account name when lead convert to account
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!
- kingsix
- April 11, 2011
- Like
- 0
- Continue reading or reply
Error Trigger with Quote Id
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
- kingsix
- April 07, 2011
- Like
- 0
- Continue reading or reply