• Mahesh Babu 187
  • NEWBIE
  • 45 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 9
    Replies
Hi Team,

I have a requirement where I have an external website outside Salesforce.The customer fills out a form on this website and also adds attachment in the form. On submit of this form, I want a new case object record to be created in salesforce with customer filled data.The attachment should be visible to the agent who will work on the case and also the agent should get notified when an attachment is added in the form. Any help would be appreciated.

Thanks in Advance,
Mahesh
I have written a Apex class which is getting called in a trigger. Now I have written a test class for the Apex class. But my code coverage is 0%.

APEX CLASS

public class ChangeOwnerClass{

    public static void changeOwner(Quote quote){
        
        Opportunity opp = [Select ID, CreatedById, OwnerId from Opportunity where Id =: quote.OpportunityId];
        System.debug(opp.OwnerId);
        if(opp.OwnerId != null) {}
            User user = [Select Id,ProfileId from User where Id=: opp.OwnerId];
            System.debug(user.Id);
            if(user!= null && user.ProfileId != null) {
                Profile profile = [Select name from Profile where Id =: user.ProfileId ];
                System.debug(profile.name);
                if(profile !=null && profile.name != null && profile.name == 'TriLink Sales & Service') {
                    quote.ownerId = opp.CreatedById;
                }            
            }
        }
    }

TRIGGER

trigger ChangeOwner on Quote (before insert) {
    
        for(Quote q: Trigger.new)
        {
            ChangeOwnerClass.changeOwner(q);
        }        
    }

TEST CLASS

@isTest
public class ChangeOwnerTest {

    @isTest static void changeOwnerTest(){
        Opportunity opp = new Opportunity();
        opp.Name = 'Test';
        opp.LeadSource = 'Test';
        opp.StageName = 'Identification';
        opp.CloseDate = Date.newInstance(2020, 12, 14);
        opp.OwnerId = '0056A00000264YcQAI';
        insert opp;
        if(opp.OwnerId != null) {}
        User user = [Select Id,ProfileId from User where Id=: opp.OwnerId];
        if(user!= null && user.ProfileId != null){
            Profile profile = [Select name from Profile where Id =: user.ProfileId ];
            if(profile !=null && profile.name != null && profile.name == 'TriLink Sales & Service'){
                Quote q = new Quote();
                q.Id = opp.Id;
                q.ownerId = opp.CreatedById;
                insert q;
            }
        }
    }
}

Please help me to modify it to get the code coverage.
I have written an Apex class for changing the Quote owner as the Opportunity owner for a Profile named 'TriLink Sales & Service'. I have called this class in Trigger. But it is not updating anything.

APEX CODE:
public class changeOwnerClass{
public list<Opportunity> lstOpp = [Select id, name, ownerId from Opportunity] ;
public void changeOwner(list<Quote> lstQuote){
Profile p = [select id,Name from Profile where id=:Userinfo.getProfileid()];
System.debug(p);
for (Opportunity opp : lstOpp){
for(Quote objQuote : lstQuote){
if(p.Name == 'TriLink Sales & Service' && p.Name!= 'TriLink GMP'){
objQuote.OwnerId = opp.OwnerId;
System.debug(opp.OwnerId);
System.debug(objQuote.OwnerId);
}} } }
}

TRIGGER:
trigger changeOwner on Quote (before insert) {
changeOwnerClass clsChangeOwner = new changeOwnerClass ();
if(trigger.isInsert && trigger.isBefore){ clsChangeOwner.changeOwner(trigger.new);
} }

I can see that the opportunity owner id is not coming here. But how to get opportunity owner id here.
Please help me to solve this error.
Hi Team,

Please help to write a test class for a after delete trigger.

TRIGGER

trigger MaketheCheckboxUnused on Order_Line_Item_Serials__c (after delete) {
     //Serial_Number__c    
    List<Serial_Number__c> snumlist = New List<Serial_Number__c>();
    List<Id> orderitemlist = New List<Id>();
    For(Order_Line_Item_Serials__c oli : Trigger.Old){
        orderitemlist.add(oli.Serial_Number__c);
    }
    List<Serial_Number__c> Olis = 
        [Select Id, Name,Serial_Number__c,  
         Product__r.Id,Status__c
         From Serial_Number__c Where
         Status__c = TRUE AND
         ID IN : orderitemlist];
    
    For(Order_Line_Item_Serials__c orim : Trigger.Old){
        For(Serial_Number__c olisn : Olis){
            If(Trigger.IsDelete){
                olisn.Status__c = FALSE;
                snumlist.add(olisn);
            }
        }
    }
    update snumlist; 
}

Thanks in Advance,
Mahesh


 
Hi Team,
I have written a wrapper class contaning the search functionality. But I can't understand how to write it's test class.

APEX CODE 

Public class fetchserials{
    
    Public string OrderID {get; set;}
    Public order OrderInstance {get; set;}
    Public List<OrderItem> OrderItemList {get; set;}
    Public Set<id> ProductIdSet {get; set;} //list to add product Ids
    Public list<Serial_Number__c> SerialList {get; set;}
    Public list<Serial_Number__c> SelectedSerialList {get; set;}
    Public Map<OrderItem,list<Serial_Number__c>> OrderVSerial{get; set;} // list to add OrderItem with their Serial Numbers
    Public List<wrapperfetch> fetchseriallist {get; set;}
    // public Integer Counter;
    Public List<Order_Line_Item_Serials__c> insertordersn {get; set;} // list to add the selected orders
    Public map<id,Serial_Number__c> smap = new map<id,Serial_Number__c>();
    public List<Serial_Number__c> serialNumbers;
    public string fullname{get;set;}
    public string finalSearchValue{get;set;}
    
    //ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.error,'Enter the List');
    // ApexPages.addMessage(myMsg);
    
    Public fetchserials(){
        OrderItemList = new List<OrderItem>(); // intialize
        OrderVSerial = new Map<OrderItem,List<Serial_Number__c>>();
        fetchseriallist = new List<wrapperfetch>();
        insertordersn = new List<Order_Line_Item_Serials__c>();
        SelectedSerialList = new list<Serial_Number__c>();
        SerialList = new list<Serial_Number__c>();
        OrderID = ApexPages.currentPage().getParameters().get('Id'); //Getting the id of current order
      OrderInstance = [SELECT Id FROM Order where Id=:OrderID ];
       OrderItemList=[SELECT Id,OrderId,product2Id,PricebookEntry.Product2.Name, Quantity FROM OrderItem where OrderId =:OrderID];
       loadSerials();
    }
    //adding page reference of the current page
  /*  public PageReference step1() {
        loadSerials();
          if(SerialList==null){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 
'Please select the serial number'));

        return Page.fetchserials;
    }*/
    
    public PageReference cancel() {
        PageReference c=new PageReference('/'+OrderID);
        return c;
    }   
    
    Public void loadSerials(){
        ProductIdSet = new set<Id>();
        For(OrderItem items :OrderItemList){
            ProductIdSet.add(items.Product2Id);// order items products add into productidset 
        }
        SerialList = [SELECT Id,Serial_Number__c,Product_Name__c ,Name,Product__c,Status__c,Bin_Number__c,Location__c
                      FROM Serial_Number__c where Status__c=FALSE And Product__c In:ProductIdSet limit 200 ];
        system.debug('Serialx' +SerialList );
        
        /*if(SerialList == NULL)
{
SerialList.addError('There are no values in the Serials List.'); 
}*/
        // add error exception handling
        system.debug('Serialx' +SerialList );
        For(OrderItem item :OrderItemList){
            //counter = 0;
            For(Serial_Number__c sn :SerialList ){
                If( sn.Product__c == item.Product2Id) // && counter < item.Quantity)
                {   SelectedSerialList = new list<Serial_Number__c>();
                 //     mahesh   fetchseriallist.add(new wrapperfetch(sn,item));
                 fetchseriallist.add(new wrapperfetch(sn));
                 SelectedSerialList.add(sn);
                 //counter = counter +1; 
                }
                else{continue;}
            }
            OrderVSerial.put(item,SelectedSerialList);
            /*=====
try{
if(SerialList == NULL ){ ApexPages.addMessages(e); }

catch (DMLException e){
ApexPages.addMessages(myMsg);
// Code for sending Email
}
============*/
        }
    }
    
    public void search(){
        finalSearchValue = '%' + fullname + '%';
       System.debug(finalSearchValue);
        fetchseriallist = new list<wrapperfetch>();
        List<Serial_Number__c> serialList =  [Select Id, Serial_Number__c, Product_Name__c, Status__c, Bin_Number__c, Location__c FROM Serial_Number__c
                                  where Serial_Number__c like :finalSearchValue];
            System.debug(serialList.size());
        for(Serial_Number__c s : serialList){
                                      System.debug(s);
                                      fetchseriallist.add(new wrapperfetch(s));    
                                      System.debug(s);
                                  }
        
    }
    
    Public class wrapperfetch{
        Public Boolean selected {get; set;}
        Public Serial_Number__c sno{get; set;}
        Public string prodname {get; set;}
        Public OrderItem Oitem{get; set;}
        Public string serialno {get; set;}
        Public Boolean status {get; set;}
        Public String locatn{get;set;}
        Public String binNo{get;set;}
        Public Id stid {get; set;}
        Public Id opid {get; set;}
        
        //    Public wrapperfetch(Serial_Number__c sn,OrderItem Oi){
        Public wrapperfetch(Serial_Number__c sn){  
            //this.selected=check;
            //    this.Oitem= Oi;
            //    this.opid =Oi.Id;
            this.prodname =sn.Product_Name__c;
            this.sno=sn;
            this.locatn=sn.Location__c;
            this.binNo=sn.Bin_Number__c;
            this.serialno = sn.Serial_Number__c;
            this.status=sn.status__c;
            this.stid=sn.id;
            
        }
    }
    
    Public PageReference AddSerailNumbertoOrder(){
        
        for (wrapperfetch st: fetchseriallist ){
            
            If (st.selected == true ){
                Order_Line_Item_Serials__c ordersn= new Order_Line_Item_Serials__c();
                //Order_Line_Item_Serials__c make it to true
                //make a new Order_Line_Item_Serials__c list and make it to true.
                // put that into   ordersn.Serial_Number__c=st.stid;  a new list 
                ordersn.Serial_Number__c=st.stid;
                ordersn.Order_Product__c=st.opid;
                insertordersn.add(ordersn);
                
                Serial_Number__c  serials = new Serial_Number__c();
                serials.id = st.stid;
                serials.Status__c = TRUE;
                serials.Location__c=st.locatn;
                serials.Bin_Number__c = st.binNo;
                SelectedSerialList.add(serials);
                smap.put(serials.id,serials );
                
            }
            
        }
        if (insertordersn.size() > 0){    
                insert insertordersn;    
              //  update smap.values();    
            }
        return Page.fetchserials;    
    }       
}

Please help me to write test class for this code.

Thanks,
Mahesh
Hi Team,

I am trying to display all search results in a wrapper class, but there's this error showing up every time I save the controller:

Error: Constructor not defined: [fetchserials.wrapperfetch].<Constructor>(Serial_Number__c)

The error points to this line of code:  serialNumbers.add(new wrapperfetch(a));

APEX CLASS

Public class fetchserials{
    
    Public string OrderID {get; set;}
    Public order OrderInstance {get; set;}
    Public List<OrderItem> OrderItemList {get; set;}
    Public Set<id> ProductIdSet {get; set;} //list to add product Ids
    Public list<Serial_Number__c> SerialList {get; set;}
    Public list<Serial_Number__c> SelectedSerialList {get; set;}
    Public Map<OrderItem,list<Serial_Number__c>> OrderVSerial{get; set;} // list to add OrderItem with their Serial Numbers
    Public List<wrapperfetch> fetchseriallist {get; set;}
    public Integer Counter;
    Public List<Order_Line_Item_Serials__c> insertordersn {get; set;} // list to add the selected orders
    public List<Serial_Number__c> serialNumbers;
    public string fullname{get;set;}
    public string finalSearchValue{get;set;}
   //ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.error,'Enter the List');
// ApexPages.addMessage(myMsg);
       Public fetchserials(){
        OrderItemList = new List<OrderItem>(); // intialize
        OrderVSerial = new Map<OrderItem,List<Serial_Number__c>>();
        fetchseriallist = new List<wrapperfetch>();
        insertordersn = new List<Order_Line_Item_Serials__c>();
        SelectedSerialList = new list<Serial_Number__c>();
        OrderID = ApexPages.currentPage().getParameters().get('Id'); //Getting the id of current order
        OrderInstance = [SELECT Id FROM Order where Id=:OrderID ];
        OrderItemList=[SELECT Id,OrderId,product2Id,PricebookEntry.Product2.Name, Quantity FROM OrderItem where OrderId =:OrderID];
        loadSerials();
    }
    //adding page reference of the current page
    public PageReference step1() {
        loadSerials();
      /*  if(SerialList==null){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 
                                                           'Please select the serial number'));
        } */
        return Page.fetchserials;
    }
    
    public PageReference cancel() {
        PageReference c=new PageReference('/'+OrderID);
        return c;
    }   
    
    Public void loadSerials(){
        ProductIdSet = new set<Id>();
        For(OrderItem items :OrderItemList){
            ProductIdSet.add(items.Product2Id);// order items products add into productidset 
        }
        SerialList = [SELECT Id,Serial_Number__c,Product_Name__c ,Name,Product__c,Status__c
                      FROM Serial_Number__c where Status__c=FALSE And Product__c In:ProductIdSet limit 200 ];
        
        
        /*if(SerialList == NULL)
{
SerialList.addError('There are no values in the Serials List.'); 
}*/
        // add error exception handling
        system.debug('Serialx' +SerialList );
        For(OrderItem item :OrderItemList){
            counter = 0;
            For(Serial_Number__c sn :SerialList ){
                If( sn.Product__c == item.Product2Id && counter < item.Quantity)
                {   SelectedSerialList = new list<Serial_Number__c>();
                    fetchseriallist.add(new wrapperfetch(sn,item));
                    SelectedSerialList.add(sn);
                    counter = counter +1; }
                else{continue;}
            }
            OrderVSerial.put(item,SelectedSerialList);
            /*=====
            try{
                if(SerialList == NULL ){ ApexPages.addMessages(e); }

catch (DMLException e){
    ApexPages.addMessages(myMsg);
    // Code for sending Email
}
            ============*/
        }
    }
    
    public pagereference Search()
    {
        String finalSearchValue = '%' + fullname + '%';
        serialNumbers = [Select Id, Serial_Number__c, Product_Name__c, Status__c FROM Serial_Number__c
                    where Name like :finalSearchValue];
        fetchseriallist = new list<wrapperfetch>();  
        for(Serial_Number__c a: serialNumbers)
        {
            serialNumbers.add(new wrapperfetch(a));
        }
       return null;
   }
    
    Public class wrapperfetch{
        Public Boolean selected {get; set;}
        Public Serial_Number__c sno{get; set;}
        Public string prodname {get; set;}
        Public OrderItem Oitem{get; set;}
        Public string serialno {get; set;}
        Public Boolean status {get; set;}
        Public Id stid {get; set;}
        Public Id opid {get; set;}
        
        Public wrapperfetch(Serial_Number__c sn,OrderItem Oi){
            //this.selected=check;
            this.Oitem= Oi;
            this.opid =Oi.Id;
            this.prodname =sn.Product_Name__c;
            this.sno=sn;
            this.serialno = sn.Serial_Number__c;
            this.status=sn.status__c;
            this.stid=sn.id;
            
            }
    }
    
    Public PageReference AddSerailNumbertoOrder(){
        
        for (wrapperfetch st: fetchseriallist ){
            
            If (st.selected == true ){
                Order_Line_Item_Serials__c ordersn= new Order_Line_Item_Serials__c();
                //Order_Line_Item_Serials__c make it to true
                //make a new Order_Line_Item_Serials__c list and make it to true.
                // put that into   ordersn.Serial_Number__c=st.stid;  a new list 
                ordersn.Serial_Number__c=st.stid;
                ordersn.Order_Product__c=st.opid;
                insertordersn.add(ordersn);
                
                Serial_Number__c  serials = new Serial_Number__c();
                serials.id = st.stid;
                serials.Status__c = TRUE;
                SelectedSerialList.add(serials);
            }
            if(SelectedSerialList == NULL){
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 
                                                           'Please select the serial number'));
            }
        }
        insert  insertordersn;
        update SelectedSerialList;
        PageReference orderpage = new PageReference('/'+OrderID);
        orderpage.setRedirect(true);
        orderpage.getParameters().put('myId', OrderID);
        return orderpage;
       
    }
}
-----------------------------------

VISUALFORCE Page

<apex:page controller="fetchserials" lightningstylesheets="true" readonly="true">
    <script>
  function confirmCancel() {
      var isCancel = confirm("Are you sure you wish to cancel?");
      if (isCancel) return true;
     return false;
  }  
  </script>
<Apex:form >
<apex:pageBlock >
<apex:pageMessages id="showmsg"></apex:pageMessages>
    <apex:pageBlock>
        <apex:inputText value="{!fullname}" html-placeholder="Search" />
        <apex:commandButton value="search" action="{!Search}" />
    </apex:pageBlock>
  <apex:pageBlockTable value="{!fetchseriallist }" var="u"  style="width:100%">
    
  <apex:column headerValue="Select" > 
                        <Apex:inputcheckbox value="{!u.Selected}"  /> 
                    </apex:column>  
                    <apex:column headerValue="Serial Number" > 
                        <Apex:outputText value="{!u.serialno }"   /> 
                    </apex:column> 
                   <apex:column headerValue="Product Name" > 
                        <Apex:outputText value="{!u.prodname }"  /> 
                    </apex:column> 
                    <apex:column headerValue="Status" > 
                       <Apex:outputText value="{!u.status}"   />
                    </apex:column> 
  </apex:pageBlockTable>                  
  <apex:commandButton value="Add to Order" action="{!AddSerailNumbertoOrder}" style="margin-top: -2pt;" rerender="showmsg"/>
  <apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true" id="cancel"/>

</apex:pageBlock>
  </Apex:form>
</apex:page>

Please help me to solve this issue.
Hi Team,

I am new to integration. I need to send PDF files from Salesforce to Netsuite when a checkbox is selected in Salesforce. I just know the approach that I need to convert the pdf to xml format in a restlet. But how to do this. 

Thanks in Advance 
Hi Team,

How to update child record's checkbox field value on parent record deletion using Lightning flow or trigger?
Hi, I got a question. If we upload data from a .csv file through data loader which has 500 rows and due to some error my data is uploaded till 100th row. Now I want to  upload my data from 101st row without again inserting from the starting. How could I do it?
Hi Team,

I am new to integration. I need to send PDF files from Salesforce to Netsuite when a checkbox is selected in Salesforce. I just know the approach that I need to convert the pdf to xml format in a restlet. But how to do this. 

Thanks in Advance 
I have written an Apex class for changing the Quote owner as the Opportunity owner for a Profile named 'TriLink Sales & Service'. I have called this class in Trigger. But it is not updating anything.

APEX CODE:
public class changeOwnerClass{
public list<Opportunity> lstOpp = [Select id, name, ownerId from Opportunity] ;
public void changeOwner(list<Quote> lstQuote){
Profile p = [select id,Name from Profile where id=:Userinfo.getProfileid()];
System.debug(p);
for (Opportunity opp : lstOpp){
for(Quote objQuote : lstQuote){
if(p.Name == 'TriLink Sales & Service' && p.Name!= 'TriLink GMP'){
objQuote.OwnerId = opp.OwnerId;
System.debug(opp.OwnerId);
System.debug(objQuote.OwnerId);
}} } }
}

TRIGGER:
trigger changeOwner on Quote (before insert) {
changeOwnerClass clsChangeOwner = new changeOwnerClass ();
if(trigger.isInsert && trigger.isBefore){ clsChangeOwner.changeOwner(trigger.new);
} }

I can see that the opportunity owner id is not coming here. But how to get opportunity owner id here.
Please help me to solve this error.
Hi Team,

Please help to write a test class for a after delete trigger.

TRIGGER

trigger MaketheCheckboxUnused on Order_Line_Item_Serials__c (after delete) {
     //Serial_Number__c    
    List<Serial_Number__c> snumlist = New List<Serial_Number__c>();
    List<Id> orderitemlist = New List<Id>();
    For(Order_Line_Item_Serials__c oli : Trigger.Old){
        orderitemlist.add(oli.Serial_Number__c);
    }
    List<Serial_Number__c> Olis = 
        [Select Id, Name,Serial_Number__c,  
         Product__r.Id,Status__c
         From Serial_Number__c Where
         Status__c = TRUE AND
         ID IN : orderitemlist];
    
    For(Order_Line_Item_Serials__c orim : Trigger.Old){
        For(Serial_Number__c olisn : Olis){
            If(Trigger.IsDelete){
                olisn.Status__c = FALSE;
                snumlist.add(olisn);
            }
        }
    }
    update snumlist; 
}

Thanks in Advance,
Mahesh


 
Hi Team,
I have written a wrapper class contaning the search functionality. But I can't understand how to write it's test class.

APEX CODE 

Public class fetchserials{
    
    Public string OrderID {get; set;}
    Public order OrderInstance {get; set;}
    Public List<OrderItem> OrderItemList {get; set;}
    Public Set<id> ProductIdSet {get; set;} //list to add product Ids
    Public list<Serial_Number__c> SerialList {get; set;}
    Public list<Serial_Number__c> SelectedSerialList {get; set;}
    Public Map<OrderItem,list<Serial_Number__c>> OrderVSerial{get; set;} // list to add OrderItem with their Serial Numbers
    Public List<wrapperfetch> fetchseriallist {get; set;}
    // public Integer Counter;
    Public List<Order_Line_Item_Serials__c> insertordersn {get; set;} // list to add the selected orders
    Public map<id,Serial_Number__c> smap = new map<id,Serial_Number__c>();
    public List<Serial_Number__c> serialNumbers;
    public string fullname{get;set;}
    public string finalSearchValue{get;set;}
    
    //ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.error,'Enter the List');
    // ApexPages.addMessage(myMsg);
    
    Public fetchserials(){
        OrderItemList = new List<OrderItem>(); // intialize
        OrderVSerial = new Map<OrderItem,List<Serial_Number__c>>();
        fetchseriallist = new List<wrapperfetch>();
        insertordersn = new List<Order_Line_Item_Serials__c>();
        SelectedSerialList = new list<Serial_Number__c>();
        SerialList = new list<Serial_Number__c>();
        OrderID = ApexPages.currentPage().getParameters().get('Id'); //Getting the id of current order
      OrderInstance = [SELECT Id FROM Order where Id=:OrderID ];
       OrderItemList=[SELECT Id,OrderId,product2Id,PricebookEntry.Product2.Name, Quantity FROM OrderItem where OrderId =:OrderID];
       loadSerials();
    }
    //adding page reference of the current page
  /*  public PageReference step1() {
        loadSerials();
          if(SerialList==null){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 
'Please select the serial number'));

        return Page.fetchserials;
    }*/
    
    public PageReference cancel() {
        PageReference c=new PageReference('/'+OrderID);
        return c;
    }   
    
    Public void loadSerials(){
        ProductIdSet = new set<Id>();
        For(OrderItem items :OrderItemList){
            ProductIdSet.add(items.Product2Id);// order items products add into productidset 
        }
        SerialList = [SELECT Id,Serial_Number__c,Product_Name__c ,Name,Product__c,Status__c,Bin_Number__c,Location__c
                      FROM Serial_Number__c where Status__c=FALSE And Product__c In:ProductIdSet limit 200 ];
        system.debug('Serialx' +SerialList );
        
        /*if(SerialList == NULL)
{
SerialList.addError('There are no values in the Serials List.'); 
}*/
        // add error exception handling
        system.debug('Serialx' +SerialList );
        For(OrderItem item :OrderItemList){
            //counter = 0;
            For(Serial_Number__c sn :SerialList ){
                If( sn.Product__c == item.Product2Id) // && counter < item.Quantity)
                {   SelectedSerialList = new list<Serial_Number__c>();
                 //     mahesh   fetchseriallist.add(new wrapperfetch(sn,item));
                 fetchseriallist.add(new wrapperfetch(sn));
                 SelectedSerialList.add(sn);
                 //counter = counter +1; 
                }
                else{continue;}
            }
            OrderVSerial.put(item,SelectedSerialList);
            /*=====
try{
if(SerialList == NULL ){ ApexPages.addMessages(e); }

catch (DMLException e){
ApexPages.addMessages(myMsg);
// Code for sending Email
}
============*/
        }
    }
    
    public void search(){
        finalSearchValue = '%' + fullname + '%';
       System.debug(finalSearchValue);
        fetchseriallist = new list<wrapperfetch>();
        List<Serial_Number__c> serialList =  [Select Id, Serial_Number__c, Product_Name__c, Status__c, Bin_Number__c, Location__c FROM Serial_Number__c
                                  where Serial_Number__c like :finalSearchValue];
            System.debug(serialList.size());
        for(Serial_Number__c s : serialList){
                                      System.debug(s);
                                      fetchseriallist.add(new wrapperfetch(s));    
                                      System.debug(s);
                                  }
        
    }
    
    Public class wrapperfetch{
        Public Boolean selected {get; set;}
        Public Serial_Number__c sno{get; set;}
        Public string prodname {get; set;}
        Public OrderItem Oitem{get; set;}
        Public string serialno {get; set;}
        Public Boolean status {get; set;}
        Public String locatn{get;set;}
        Public String binNo{get;set;}
        Public Id stid {get; set;}
        Public Id opid {get; set;}
        
        //    Public wrapperfetch(Serial_Number__c sn,OrderItem Oi){
        Public wrapperfetch(Serial_Number__c sn){  
            //this.selected=check;
            //    this.Oitem= Oi;
            //    this.opid =Oi.Id;
            this.prodname =sn.Product_Name__c;
            this.sno=sn;
            this.locatn=sn.Location__c;
            this.binNo=sn.Bin_Number__c;
            this.serialno = sn.Serial_Number__c;
            this.status=sn.status__c;
            this.stid=sn.id;
            
        }
    }
    
    Public PageReference AddSerailNumbertoOrder(){
        
        for (wrapperfetch st: fetchseriallist ){
            
            If (st.selected == true ){
                Order_Line_Item_Serials__c ordersn= new Order_Line_Item_Serials__c();
                //Order_Line_Item_Serials__c make it to true
                //make a new Order_Line_Item_Serials__c list and make it to true.
                // put that into   ordersn.Serial_Number__c=st.stid;  a new list 
                ordersn.Serial_Number__c=st.stid;
                ordersn.Order_Product__c=st.opid;
                insertordersn.add(ordersn);
                
                Serial_Number__c  serials = new Serial_Number__c();
                serials.id = st.stid;
                serials.Status__c = TRUE;
                serials.Location__c=st.locatn;
                serials.Bin_Number__c = st.binNo;
                SelectedSerialList.add(serials);
                smap.put(serials.id,serials );
                
            }
            
        }
        if (insertordersn.size() > 0){    
                insert insertordersn;    
              //  update smap.values();    
            }
        return Page.fetchserials;    
    }       
}

Please help me to write test class for this code.

Thanks,
Mahesh
Hi Team,

I am trying to display all search results in a wrapper class, but there's this error showing up every time I save the controller:

Error: Constructor not defined: [fetchserials.wrapperfetch].<Constructor>(Serial_Number__c)

The error points to this line of code:  serialNumbers.add(new wrapperfetch(a));

APEX CLASS

Public class fetchserials{
    
    Public string OrderID {get; set;}
    Public order OrderInstance {get; set;}
    Public List<OrderItem> OrderItemList {get; set;}
    Public Set<id> ProductIdSet {get; set;} //list to add product Ids
    Public list<Serial_Number__c> SerialList {get; set;}
    Public list<Serial_Number__c> SelectedSerialList {get; set;}
    Public Map<OrderItem,list<Serial_Number__c>> OrderVSerial{get; set;} // list to add OrderItem with their Serial Numbers
    Public List<wrapperfetch> fetchseriallist {get; set;}
    public Integer Counter;
    Public List<Order_Line_Item_Serials__c> insertordersn {get; set;} // list to add the selected orders
    public List<Serial_Number__c> serialNumbers;
    public string fullname{get;set;}
    public string finalSearchValue{get;set;}
   //ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.error,'Enter the List');
// ApexPages.addMessage(myMsg);
       Public fetchserials(){
        OrderItemList = new List<OrderItem>(); // intialize
        OrderVSerial = new Map<OrderItem,List<Serial_Number__c>>();
        fetchseriallist = new List<wrapperfetch>();
        insertordersn = new List<Order_Line_Item_Serials__c>();
        SelectedSerialList = new list<Serial_Number__c>();
        OrderID = ApexPages.currentPage().getParameters().get('Id'); //Getting the id of current order
        OrderInstance = [SELECT Id FROM Order where Id=:OrderID ];
        OrderItemList=[SELECT Id,OrderId,product2Id,PricebookEntry.Product2.Name, Quantity FROM OrderItem where OrderId =:OrderID];
        loadSerials();
    }
    //adding page reference of the current page
    public PageReference step1() {
        loadSerials();
      /*  if(SerialList==null){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 
                                                           'Please select the serial number'));
        } */
        return Page.fetchserials;
    }
    
    public PageReference cancel() {
        PageReference c=new PageReference('/'+OrderID);
        return c;
    }   
    
    Public void loadSerials(){
        ProductIdSet = new set<Id>();
        For(OrderItem items :OrderItemList){
            ProductIdSet.add(items.Product2Id);// order items products add into productidset 
        }
        SerialList = [SELECT Id,Serial_Number__c,Product_Name__c ,Name,Product__c,Status__c
                      FROM Serial_Number__c where Status__c=FALSE And Product__c In:ProductIdSet limit 200 ];
        
        
        /*if(SerialList == NULL)
{
SerialList.addError('There are no values in the Serials List.'); 
}*/
        // add error exception handling
        system.debug('Serialx' +SerialList );
        For(OrderItem item :OrderItemList){
            counter = 0;
            For(Serial_Number__c sn :SerialList ){
                If( sn.Product__c == item.Product2Id && counter < item.Quantity)
                {   SelectedSerialList = new list<Serial_Number__c>();
                    fetchseriallist.add(new wrapperfetch(sn,item));
                    SelectedSerialList.add(sn);
                    counter = counter +1; }
                else{continue;}
            }
            OrderVSerial.put(item,SelectedSerialList);
            /*=====
            try{
                if(SerialList == NULL ){ ApexPages.addMessages(e); }

catch (DMLException e){
    ApexPages.addMessages(myMsg);
    // Code for sending Email
}
            ============*/
        }
    }
    
    public pagereference Search()
    {
        String finalSearchValue = '%' + fullname + '%';
        serialNumbers = [Select Id, Serial_Number__c, Product_Name__c, Status__c FROM Serial_Number__c
                    where Name like :finalSearchValue];
        fetchseriallist = new list<wrapperfetch>();  
        for(Serial_Number__c a: serialNumbers)
        {
            serialNumbers.add(new wrapperfetch(a));
        }
       return null;
   }
    
    Public class wrapperfetch{
        Public Boolean selected {get; set;}
        Public Serial_Number__c sno{get; set;}
        Public string prodname {get; set;}
        Public OrderItem Oitem{get; set;}
        Public string serialno {get; set;}
        Public Boolean status {get; set;}
        Public Id stid {get; set;}
        Public Id opid {get; set;}
        
        Public wrapperfetch(Serial_Number__c sn,OrderItem Oi){
            //this.selected=check;
            this.Oitem= Oi;
            this.opid =Oi.Id;
            this.prodname =sn.Product_Name__c;
            this.sno=sn;
            this.serialno = sn.Serial_Number__c;
            this.status=sn.status__c;
            this.stid=sn.id;
            
            }
    }
    
    Public PageReference AddSerailNumbertoOrder(){
        
        for (wrapperfetch st: fetchseriallist ){
            
            If (st.selected == true ){
                Order_Line_Item_Serials__c ordersn= new Order_Line_Item_Serials__c();
                //Order_Line_Item_Serials__c make it to true
                //make a new Order_Line_Item_Serials__c list and make it to true.
                // put that into   ordersn.Serial_Number__c=st.stid;  a new list 
                ordersn.Serial_Number__c=st.stid;
                ordersn.Order_Product__c=st.opid;
                insertordersn.add(ordersn);
                
                Serial_Number__c  serials = new Serial_Number__c();
                serials.id = st.stid;
                serials.Status__c = TRUE;
                SelectedSerialList.add(serials);
            }
            if(SelectedSerialList == NULL){
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 
                                                           'Please select the serial number'));
            }
        }
        insert  insertordersn;
        update SelectedSerialList;
        PageReference orderpage = new PageReference('/'+OrderID);
        orderpage.setRedirect(true);
        orderpage.getParameters().put('myId', OrderID);
        return orderpage;
       
    }
}
-----------------------------------

VISUALFORCE Page

<apex:page controller="fetchserials" lightningstylesheets="true" readonly="true">
    <script>
  function confirmCancel() {
      var isCancel = confirm("Are you sure you wish to cancel?");
      if (isCancel) return true;
     return false;
  }  
  </script>
<Apex:form >
<apex:pageBlock >
<apex:pageMessages id="showmsg"></apex:pageMessages>
    <apex:pageBlock>
        <apex:inputText value="{!fullname}" html-placeholder="Search" />
        <apex:commandButton value="search" action="{!Search}" />
    </apex:pageBlock>
  <apex:pageBlockTable value="{!fetchseriallist }" var="u"  style="width:100%">
    
  <apex:column headerValue="Select" > 
                        <Apex:inputcheckbox value="{!u.Selected}"  /> 
                    </apex:column>  
                    <apex:column headerValue="Serial Number" > 
                        <Apex:outputText value="{!u.serialno }"   /> 
                    </apex:column> 
                   <apex:column headerValue="Product Name" > 
                        <Apex:outputText value="{!u.prodname }"  /> 
                    </apex:column> 
                    <apex:column headerValue="Status" > 
                       <Apex:outputText value="{!u.status}"   />
                    </apex:column> 
  </apex:pageBlockTable>                  
  <apex:commandButton value="Add to Order" action="{!AddSerailNumbertoOrder}" style="margin-top: -2pt;" rerender="showmsg"/>
  <apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true" id="cancel"/>

</apex:pageBlock>
  </Apex:form>
</apex:page>

Please help me to solve this issue.
Hi, I got a question. If we upload data from a .csv file through data loader which has 500 rows and due to some error my data is uploaded till 100th row. Now I want to  upload my data from 101st row without again inserting from the starting. How could I do it?
I have a requirement where I have an external website outside Salesforce.The customer fills out a form on this website with name & other information. On submit of this form, I want a new custom object record to be created in salesforce with customer filled data on the form.Any help plz.