Here is my trigger:
trigger Trigger_Update on Account_Setup__c (After insert){
Schema.DescribeFieldResult fieldResult = Account_Setup__c.status__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for (Account_Setup__c B : Trigger.new) {
Account ac = new Account();
if(B.status__c == 'Approved'){
ac.Name = B.Name;
ac.industry = B.industry__c;
ac.region__c = B.region__c;
ac.Fax = B.Fax__c;
ac.phone = B.Phone__c;
ac.website = B.website__c;
ac.Account_Email__c = B.email__c;
insert ac;
}
Else if (B.status__c == 'Rejected'){
}
}
}
Here is my Class:
@isTest
public class Account_creation_Class{
// Status of 'Approved'
static testMethod void approved() {
Account_Setup__c B = new Account_Setup__c();
B.status__c = 'Approved';
B.Name = 'Name' ;
B.industry__c = 'Industry';
B.region__c = 'USA';
B.Fax__c = '111-111-1111';
B.Phone__c ='222-222-2222';
B.website__c = 'www.salesforce.com' ;
B.email__c = '[email protected]';
insert B;
}
}
My code coverage shows 100%, but the IF statement is not working. I have a custom field "Status", in my custom object "Account_Set_up". When sales creates account_setup, it goes through an approval process. if approved, it creates an account in the account object; if rejected, nothing happen
the problem I am facing, is that the account gets created either way, whether it was approved, pending or rejected. I guess something is wrong with the code
Also, in the trigger section in the if rejected section, I didn't put a code, because I don't want anything to happen. is that the proper way to tell the code "don't do anything"
Can someone help please? thanks a lot
system.debug
statements to see where the code is going. Also you shouldn't do any DML inside of a loop like that. You should build a list of Accounts to insert then insert them after the loop.