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
Naveen KvpNaveen Kvp 

How can we make non filled fileds should be blank?

Hi Everyone,

    here i wrote a class for creating salesorder ,when end user creating a records he should fill anyone of sizes fields like Size_S__c,Size_L__c,
    Size_M__c,Size_XL__c,Size_XXL__c.Suppose he select Trento 00311 product only size Size_XL__c all remaining size fields showing zero. 
    
    here i don't want show zeros in non filled fields,instead of zeros those feilds i should be blank how can i do that?

    Thanks in Advance.    

public with sharing class NewOrderPageClass
{
  public Id orid{get;set;}
  // public List<id> Opids{get;set;} 
  Public Map<id,Account> mapAccounts{get;set;}
  public Order__c OppId{get;set;}
  public List<Order_Product__c> oplist{get;set;}
  public List<Product_Master__c> Pmid{get;set;}
  Public Boolean Display{get;set;}
  public NewOrderPageClass(ApexPages.StandardController controller)
      {
      try
          {
       
       String orid=ApexPages.CurrentPage().getParameters().get('id');
       mapAccounts=new Map<id,Account>([Select id,Name,RollupOrders__c from Account]); 
       oplist=new List<Order_Product__c>();
       OppId=[select id,name,Account__c,Total_Quantity_Sets__c,Total_Order_Amount__c from Order__c where id=:orid];
            Pmid=[select id,name,Active__c,Size_S__c,Size_L__c,Size_M__c,Size_XL__c,Size_XXL__c,Price__c,Product_Color__c,Remarks__c   from Product_Master__c WHERE 
                    Product_Type__c='Sales' AND Active__c=True AND Thermax__c=False ORDER BY CreatedDate ASC];
       System.Debug('----->>>>>@@@@Size'+Pmid.size()); 
       System.Debug('----->>>>>@@@@Prose'+Pmid); 
          }
        
      catch(Exception e)
          {
          system.debug(e);
          ApexPages.addMessages(e);
          }
      }
    public PageReference CreateOrderProduct()
        {
        
       try
         {
    
       for( Product_Master__c p:pmid)
         {
        
         if(p.Size_S__c>0||p.Size_L__c>0||p.Size_M__c>0||p.Size_XL__c>0||p.Size_XXL__c>0)
         {
          RecordType rty = [SELECT Name, id FROM RecordType WHERE sObjectType='Order_Product__c' and name='Sales'];
          System.debug('-------------------> Record Type Ids'+rty);
           Order_Product__c op=new Order_Product__c(RecordTypeId=rty.id);             
             op.Product_Master__c=p.id;
             op.Sales_Order__c=OppId.id;
            // op.name=p.Name;      
             op.Size_S__c=p.Size_S__c;
             op.Size_M__c=p.Size_M__c;
             op.Size_L__c=p.Size_L__c;
             op.Size_XL__c=p.Size_XL__c;
             op.Size_XXL__c=p.Size_XXL__c;
             op.Description__c=p.Remarks__c;
             /*op.quantity__c=p.Quantity__c;*/
            
             System.debug('-------------------> Order Products are Ids'+op);
             oplist.add(op);             
                  
        }
        }
        }
        
        catch(Exception e)
            {
            system.debug(e);
            }
        if(oplist.Size()>0)
        {
            insert oplist;
        }
      PageReference reference = new PageReference('/'+Apexpages.CurrentPage().getParameters().get('Id'));
      return reference;
        //PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
       //pageRef.setRedirect(true);
       //return pageRef;
        
       }
}
Vivek_PatelVivek_Patel
Hi Naveen,

If you are setting the values of all the fields to be displayed on the page from the object, then check which field does not have zero and populate on that field form the object rest of the field should not be set from the object

like instead of 
op.Size_XL__c=p.Size_XL__c;

do op.Size_XL__c=null;


Regards,
Vivek Patel.
Naveen KvpNaveen Kvp
Hi vivek, Thaks for your responce. according to your suggestion i made changes on my code like this /* Company: Epeople Bespoke Consulting Pvt Ltd Created By: Ravi Chellamlla Modified By: Sateesh Kumar */ public with sharing class NewOrderPageClass { public Id orid{get;set;} // public List Opids{get;set;} Public Map mapAccounts{get;set;} public Order__c OppId{get;set;} public List oplist{get;set;} public List Pmid{get;set;} Public Boolean Display{get;set;} public NewOrderPageClass(ApexPages.StandardController controller) { try { String orid=ApexPages.CurrentPage().getParameters().get('id'); mapAccounts=new Map([Select id,Name,RollupOrders__c from Account]); oplist=new List(); OppId=[select id,name,Account__c,Total_Quantity_Sets__c,Total_Order_Amount__c from Order__c where id=:orid]; Pmid=[select id,name,Active__c,Size_S__c,Size_L__c,Size_M__c,Size_XL__c,Size_XXL__c,Price__c,Product_Color__c,Remarks__c from Product_Master__c WHERE Product_Type__c='Sales' AND Active__c=True AND Thermax__c=False ORDER BY CreatedDate ASC]; System.Debug('----->>>>>@@@@Size'+Pmid.size()); System.Debug('----->>>>>@@@@Prose'+Pmid); } catch(Exception e) { system.debug(e); ApexPages.addMessages(e); } } public PageReference CreateOrderProduct() { try { for( Product_Master__c p:pmid) { if(p.Size_S__c>=0||p.Size_L__c>=0||p.Size_M__c>=0||p.Size_XL__c>=0||p.Size_XXL__c>=0) { RecordType rty = [SELECT Name, id FROM RecordType WHERE sObjectType='Order_Product__c' and name='Sales']; System.debug('-------------------> Record Type Ids'+rty); Order_Product__c op=new Order_Product__c(RecordTypeId=rty.id); op.Product_Master__c=p.id; op.Sales_Order__c=OppId.id; // op.name=p.Name; op.Size_S__c=null; op.Size_M__c=null; op.Size_L__c=null; op.Size_XL__c=null; op.Size_XXL__c=null; op.Description__c=p.Remarks__c; /*op.quantity__c=p.Quantity__c;*/ System.debug('-------------------> Order Products are Ids'+op); oplist.add(op); } } } catch(Exception e) { system.debug(e); } if(oplist.Size()>0) { insert oplist; } PageReference reference = new PageReference('/'+Apexpages.CurrentPage().getParameters().get('Id')); return reference; //PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl()); //pageRef.setRedirect(true); //return pageRef; } } this would show blank to all the fields incuding entered fields also once the order would confirm they are send this order to distributor there it will shows zeros here i am attaching file regading that.they want blank instesd of zeros
Vivek_PatelVivek_Patel
Hi Naveen,

It looks that you are setting all the fields to null, set null to only those fields which has value 0, means that size was not set by the user, also can you put you code in the code block <> section next time, it's hard to read the code when it's not formatted.

Regards,
Vivek Patel.
Naveen KvpNaveen Kvp
k i will before i gave reply from my gmail so that you recieved unformatted code. anyways thanks for your time Vivek.