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
nani@rnani@r 

I WANT TO INSERT MORE FIELDS IN DATA MODEL THROW APEX CLASSES?

@istest
public class rajinsert{

static testmethod void raj(){

rajesh__c a = new rajesh__c();

a.name = 'Mumbai';
a.price__c=9000;
a.subject__c='sfdc';

rajesh__c b=new rajesh__c();

b.name = 'raj';
b.price__c=4000;
b.subject__c='c';

rajesh__c c=new rajesh__c();

c.name = 'raj';
c.price__c=4400;
c.subject__c=C++';

list<rajesh__c> ab=new list<rajesh__C>();
ab=[select name,price__C,subject__c from rajesh__C ];
ab.add(a);
ab.add(b);
ab.add(c);
insert ab;
}


}

AFTER I EXECUTE THIS PROGRAM AGAIN I CAN'T INSERT MORE FIELDS AND THEN I WANT TO DELETE 'a,b' IN THIS PROGRAM . pls help me 

Suresh RaghuramSuresh Raghuram

there is no need to create 3 instances for 3 records one instance is enough to insert 3 records.

 

The following two lines are also no need

list<rajesh__c> ab=new list<rajesh__C>();
ab=[select name,price__C,subject__c from rajesh__C ];

 

jst create

rajesh__c a = new rajesh__c();

a.name = 'Mumbai';
a.price__c=9000;
a.subject__c='sfdc';


a.name = 'raj';
a.price__c=4000;
a.subject__c='c';

a.name = 'raj';
a.price__c=4400;
a.subject__c=C++';

 

Insert a;

all the queries for loops and if conditions will get cover once you provide input.

If this answers your question make it as a solution.

 

If you still have doubts, post them i will help you

 

 

 

nani@rnani@r

no sir it will execute only one field

Suresh RaghuramSuresh Raghuram

post your code so i can understand what you are trying to do