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
Rahul H 4Rahul H 4 

need class for my trigger

trigger Images34_case on Case (before insert, before update) {

list <string> name = new list<string>();
map<string,id> casemap = new map<string,id>();
for(case c : trigger.new){
name.add(c.Customer_Name__c );
}
for(contact con : [select id,name from contact where name in : name]){
casemap.put(con.name,con.id);
}
for(case ca: trigger.new){
if(casemap.containskey(ca.Customer_Name__c)){
ca.contactid = casemap.get(ca.Customer_Name__c);
}
}
}

this is my trigger.. can u pls help to write the classfor the same. thanks 
Best Answer chosen by Rahul H 4
Raj VakatiRaj Vakati
TRy this code
 
@istest

Private class Images34_caseTest{

static testmethod void TestTrigger(){
account a = new account(name ='test');
insert a;

contact c = new contact(lastname= 'test',AccountId= a.Id, Email= 'test@test.com');
insert c;

case cs = new case(subject='test',Image1__c='https',Customer_Name__c='test' , Brand__c = 'MDC' , status= 'New', origin= 'email', accountid=a.id, contactid =c.id, 
Categorize_Faults__c =' Electrics', VIN__c ='123', Purchase_Date__c = System.today());



insert cs;
}


}

 

All Answers

Rahul H 4Rahul H 4
@istest

Private class Images34_caseTest{

static testmethod void TestTrigger(){
account a = new account(name ='test');
insert a;

contact c = new contact(lastname= 'test',AccountId= '0017F00000A7NhEQAV', Email= 'test@test.com');
insert c;

case cs = new case(subject='test',Image1__c='https',Brand__c = 'MDC' , status= 'New', origin= 'email', accountid=a.id, contactid =c.id, Categorize_Faults__c =' Electrics', VIN__c ='123', Purchase_Date__c = '12/12/2018');



insert cs;
}


}

i created this class however its throwing error 

Error: Compile Error: Illegal assignment from String to Date at line 12 column 11
Raj VakatiRaj Vakati
TRy this code
 
@istest

Private class Images34_caseTest{

static testmethod void TestTrigger(){
account a = new account(name ='test');
insert a;

contact c = new contact(lastname= 'test',AccountId= a.Id, Email= 'test@test.com');
insert c;

case cs = new case(subject='test',Image1__c='https',Customer_Name__c='test' , Brand__c = 'MDC' , status= 'New', origin= 'email', accountid=a.id, contactid =c.id, 
Categorize_Faults__c =' Electrics', VIN__c ='123', Purchase_Date__c = System.today());



insert cs;
}


}

 
This was selected as the best answer
Rahul H 4Rahul H 4
thanks it works