• Naveen Kvp
  • NEWBIE
  • 20 Points
  • Member since 2014
  • Salesforce Developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 16
    Questions
  • 10
    Replies
Hi Friends

Validation:In Tax Master i have a Three fields Excise duty,Vat And Cst if we fill Excise duty either Vat or Cst only one should enter.

How to write a validation for this please provoide some inputs,Thanks in advance.

i am writing a Validation like this but it won't work:
AND( 
ISBLANK( Excise_Duty__c ), 
OR( 
NOT(ISBLANK(VAT__c)), 
ISBLANK(CST__c) 
), 
OR( 
NOT(ISBLANK(CST__c)), 
ISBLANK(VAT__c) 
) 
)

 
Hi Friends

Validation:In Tax Master i have a Three fields Excise duty,Vat And Cst if we fill Excise duty either Vat or Cst only one should enter.

How to write a validation for this please provoide some inputs,Thanks in advance.

i am writing a Validation like this but it won't work:
 
AND( 
ISBLANK( Excise_Duty__c ), 
OR( 
NOT(ISBLANK(VAT__c)), 
ISBLANK(CST__c) 
), 
OR( 
NOT(ISBLANK(CST__c)), 
ISBLANK(VAT__c) 
) 
)
Here i wrote a proposal vfpage on opportunity i am trying to convert as pdf,here i am getting this error:PDF
generation failed.Check the page markup is valid.
 Can anyone please suggest on the same...
<apex:page standardController="LM_Opportunity__c" renderAs="pdf" sidebar="true" extensions="proposalclass" >
 <apex:form >
<style> 
     tr.spaceUnder > td
     {
     padding-bottom: 2em;
     }
     tr.spaceUnder1 > td
     {
     padding-bottom: 1em;
     }
</style>
    <table align="center" cellspacing="0" cellpadding="0" border="1" width="100%"> 
         <tr>
         <tr width="1%"></tr>
              <table  width="100%" align="right">
                   <tr >
                         <td align="right"><b>Proposal No :  <apex:outputText value="{!L.Proposal_Number__c}"> </apex:outputText></b></td>            
                   </tr>
                   <tr>  
                        <td align="right"><b>Proposal Date : <apex:outputText value="{!Now()}"> </apex:outputText></b></td>            
                   </tr>                                                   
                   </table> 
                              
                   <table >
                           <tr class="spaceUnder1">
                                 <td><b>To,</b></td>
                           </tr>
                           <tr>
                                 <td><b><apex:outputtext value="JAISIM-FOUNTAINHEAD"/></b></td>
                           </tr>
                           <tr>
                                 <td><b>#175/1,PAVILLION ROAD,</b></td>
                           </tr>
                           <tr>
                                 <td><b>JAYANAGAR EAST,1ST BLOCK,</b></td>
                           </tr>
                           <tr class="spaceUnder">
                                 <td ><b>BANGALORE-560011</b></td>
                           </tr>
                           <tr class="spaceUnder1">
                                 <td><b>Kind Attn :</b>&nbsp;{!L.Kind_Attn__r.Name}</td>
                           </tr>
                            <tr class="spaceUnder1">
                                 <td>Dear Madam,</td>
                           </tr>
                            <tr class="spaceUnder1">
                                 <td>Project:</td>
                           </tr>
                           <tr class="spaceUnder1">
                                 <td><b>Sub: Proposal For{!L.Name}</b></td>
                           </tr>
                           <tr>
                                 <td>This has reference to the discussions you had with our Director during his visit to your office.</td>
                           </tr>
                           <tr>
                                 <td>We Provide your organization with a purchasing channel based on ease,trust,and dependability.Our</td>
                           </tr>
                           <tr>
                                 <td>established relationships, our design and planning center in Bangalore and network of reliable global</td>
                           </tr>
                           <tr>
                                 <td>manufacturers,eliminates the intermediaries,taking out the guess work and advancing your supply</td>
                           </tr>
                           <tr>
                                 <td>chain, without sacrificing efficiency or product quality.By utilizing our "Complete Service Chain",</td>
                           </tr>
                         
                           <tr>
                                 <td>Liquid Metal will meet your Furniture needs.We are your global design team,sourcing agent,quality</td>
                           </tr>
                           <tr class="spaceUnder1">
                                 <td>control,and freight-forwarder-all in one.</td>
                           </tr>
                           <tr class="spaceUnder1">
                                 <td>Enclosed is our proposal for your requirement of Alchemy system for maintec Project.</td>
                           </tr>
                           <tr class="spaceUnder">
                                 <td>We look forward to an opportunity to work with you in this project.</td>
                           </tr>
                           <tr class="spaceUnder1">
                                 <td>Thanking you</td>
                           </tr> 
                           <tr class="spaceUnder">
                                 <td><b>For Liquid Metal Furniture Private Limited</b></td>
                           </tr>
                           <tr>
                                 <td><b>{!L.Opportunity_Owner__r.Name}</b></td>
                           </tr> 
                           <tr>
                                 <td><b>Manager-Business Developement</b></td>
                           </tr>    
                  </table>                                                  
                           </tr>
                  </table>
    
    </apex:form>
</apex:page>

 
I have a two fields in Tax master object Excise_Duty__c and Sales_Tax__c  how to write a validation for Only one of the two to be entered.

      i am wrote a formula like this:

OR(
NOT( ISBLANK( Excise_Duty__c ) ),
ISBLANK( Sales_Tax__c )  
)

This is working for only one field for checking condition,how can i check for both fields!
Please provoide me profer solution for this!! Thanks in advance 
I am trying to map total formula field in class but it will through error like this :Error: NewOrderPageClass Compile Error: Field is not writeable: Order_Product__c.Total__c at line 54 column 14
  can you please suggest me how to resolve this issue.

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 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,Total__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.Total__c = p.Total__c;
             op.Remarks__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;
       }
      
}
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;
        
       }
}
Hi Everyone,

   Here i wrote a trigger on task where new task record is inserted or updated ,in account i have custom field called Area__c
   Whenever trigger fires the Area__c filed should outopopulate on task.
   I need your help on without selecting Relatedto(whatid) i am try to save a record it will cause an Attempt to de-reference a null error  how to resove
   this what kind of changes i need to do in trigger.   
   
     Thanks in advance.

trigger Update_Area on Task (before insert, before update)
{    
    set<id> Accids= new set<id>();
    map<id, Account> mapleads = new map<id, Account>();
    Map<Id, List<Task>> whatIds = new Map<Id, List<Task>>{};
    
        for(Task t : trigger.new)
        {
            String objName = t.WhatId.getSObjectType().getDescribe().getName();
            if(t.WhatId!=null )
            {
                if(objName=='Account')
                {
                    Accids.add(t.WhatId);
                }  
            }
        }
    
    list<Account> ldlist = [select id, name,Area__c
                            from Account where id in :Accids];
    
    if(!ldlist.isEmpty())
    {
        for(Account l : ldlist)
        {
            mapleads.put(l.Id, l);
        }
    }        
    for(Task tt: trigger.new)
    {        
        String objName = tt.WhatId.getSObjectType().getDescribe().getName();
        if(tt.WhatId!=null)
        {
            if(objName == 'Account')
            {
                tt.Area__c= mapleads.get(tt.WhatId).Area__c;  
            }
        }  
    }
}
Hi Everyone,

      Here i am trying to write test class for this trigger but i am getting only 42% of code covereage and DML operation bock of Update              consUpdate; is not covered. can you please help me to increse code covereage.
      
      here i am attach trigger and test class
      
 Thanks in advance.

Create_Contact trigger:
    
trigger Create_Contact on Account (After insert,After Update) {
  List<Contact> conlist=new List<Contact>();  
     if(Trigger.isInsert)
       {
       for(Account a: Trigger.New)
         {
         try
         {                            
         List<String> listTsks=a.Primary_Email__c.split('@');
         system.debug('@@@@@@@@@@@@@@@@@@'+listTsks);
         
          
             Contact c=new Contact();  
                c.AccountId=a.id;          
                c.LastName=listTsks[0];                             
                c.Phone= a.Phone;
                c.Email=a.Primary_Email__c;
                c.MobilePhone=a.Mobile__c;
                c.Description=a.Description;
             
                c.Address_Line_1__c=a.Address_Line_1__c;
                c.Address_Line_2__c=a.Address_Line_2__c;
                c.Address_Line_3__c=a.Address_Line_3__c;
                c.City__c=a.City__c;
                c.Country__c=a.Country__c;
                c.PIN_Code__c=a.PIN_Code__c; 
                
               conlist.add(c);                                            
               insert conlist;
               }
               
               catch(exception e)
               {
               }   
         } 
                       
       if(Trigger.isUpdate)
       {
       try
       {
       List<contact> consUpdate=New List<Contact>();
            List<Account> alist=[select id,name,Phone,Mobile__c,Primary_Email__c,Address_Line_2__c,Address_Line_1__c,Address_Line_3__c,Description,Country__c,PIN_Code__c,City__c from Account];
            List<id> ids=new List<id>();
          for(Account a:trigger.new)
           {
              ids.add(a.id);
           }
          List<contact> cons=[select id,name,AccountId,Phone,MobilePhone,Address_Line_2__c,Address_Line_1__c,Address_Line_3__c,Email,Country__c,PIN_Code__c,City__c,LastName from Contact where AccountId=:ids];
          for(Account a1:trigger.new)
          {
              for(Contact c:cons)
              {
                  if(a1.id==c.AccountId)
                  {
                   List<String> listTsks=a1.Primary_Email__c.split('@');
                c.AccountId=a1.id;                    
                c.LastName=listTsks[0];
                c.Phone= a1.Phone;
                c.Email=a1.Primary_Email__c;
                c.MobilePhone=a1.Mobile__c;
                c.Description=a1.Description;
            
                c.Address_Line_1__c=a1.Address_Line_1__c;                
                c.Address_Line_2__c=a1.Address_Line_2__c;
                c.Address_Line_3__c=a1.Address_Line_3__c;
                c.City__c=a1.City__c;
                c.Country__c=a1.Country__c;
                c.PIN_Code__c=a1.PIN_Code__c; 
               
                  consUpdate.add(c);
                  }
                 
              }
          }      
       if(consUpdate.size()>0)
       {
          Update consUpdate; 
       }
       }
       catch(exception e)
       {}
       }  
  }          
         
}

test class:

@isTest
  Public Class TestCreateContactTrigger
  {
    Static TestMethod Void createcontact()
    {
     
      Account a= new Account();
       a.Name='Test Acc';
       a.Phone='123';
       a.Primary_Email__c='test@email.com';
      
       insert a;
       update a;
     
     Contact c=new Contact();
      c.Salutation='Mr';
      c.LastName='a.Name';
      c.Email= a.Primary_Email__c;
      c.AccountId=a.id;
      
      insert c;
   
     
     Account aa = new Account(id=a.id,Name='Acc');
     Update aa;
     
     Contact cc = new Contact(id=c.id,LastName=aa.Name);
     Update cc;
     
      
    }
  }
Task:How to write a trigger for account object in account object i have different record types like dealer,directdealer
distributor,individualcontacts and every record type is having accounts associated with  recordtypes in that accounts i
have a fields like birth date and anniversarydate on accounts. when thier birthdate or anniversarydate is today those
list will showcase on chatter with the fields of  name,partytype,state,location ...
How can i achieve this can u please send some sample code!!
Thanks in advance!!!
Hi here i am trying to improve code coverege for test class for ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please Enter atleast One Quantity to Create Branding Visit and Branding Order')); but i got a exception can you please help me..i post class and test class below..

class:public class Brandingcls
{
   public Branding_Visit__c brvisit{get;set;}
    public Branding_Order__c brorder{get;set;}
    public list<Branding_Item_Master__c> bimaster{get;set;}
    public list<Branding_Line_Item__c> brlineitem{get;set;}
    public Brandingcls()
    {
        bimaster=[select id,Name,Remarks__c,Quantity__c from Branding_Item_Master__c];
          brorder=new Branding_Order__c(Order_Date__c=system.Today());
        brvisit=new Branding_Visit__c(); 
    }
       
    public PageReference save()
    {
   
      list<Branding_Item_Master__c> lstbritem =new  list<Branding_Item_Master__c>();
          for(Branding_Item_Master__c bim :bimaster)
            {
                   if(bim.Quantity__c>0)
                      {
                        lstbritem.add(bim);
                      } 
            }
        if(lstbritem.Size()>0)
          {
        insert brorder;
        brvisit.Account__c = brorder.Account__c;
        brvisit.Visit_Date__c = brorder.Order_Date__c;
        insert brvisit;
        list<Branding_Line_Item__c> lstbli = new list<Branding_Line_Item__c>();     
          for(Branding_Item_Master__c bm:lstbritem)
             {
                  Branding_Line_Item__c brandli= new Branding_Line_Item__c();
                  
                   
                      brandli.Branding_Order__c=brorder.id;
                      brandli.Branding_Type__c=bm.id;
                      brandli.Quantity__c=bm.Quantity__c;
                      brandli.Remarks__c=bm.Remarks__c;
                      lstbli.add( brandli);
                
                  
             }
             if(lstbli.Size()>0)
             {
                   insert lstbli;
              }
          }
          else
          {
              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please Enter atleast One Quantity to Create Branding Visit and Branding Order'));
              return Null;
          }
             pagereference ref=new pagereference( '/' +brvisit.id); 
                ref.setredirect(true);
                   return ref;
 
     
    }
   
   
    public PageReference cancel()
    {
       return null;
    }
}


Testclass:
@istest
public class testBrandingcls{
   static testmethod  void  testsave(){
     Account Acc = new Account(Name='test',Primary_Contact_Person_Name__c='testperson', Products__c='product1',Market__c='test',Classification__c='D',Purchase_Cycle__c='test', Status__c='coldcall',Contact_Number_Mobile__c='9849544286', State__c='assam',Display_of_our_product__c='promonent',Media__c='inshop',Type_of_Dealer__c='sanitary');
  insert acc;
  Branding_Item_Master__c bim=new Branding_Item_Master__c(Quantity__c=12);
 
        insert bim;
     Branding_Order__c br=new Branding_Order__c(Order_Date__c=system.today(),Account__c=acc.id);
        insert br;
     Branding_Visit__c bv=new Branding_Visit__c(Visit_Date__c=system.today(),Account__c=acc.id);
        insert bv;
     Branding_Line_Item__c blm=new Branding_Line_Item__c(Branding_Type__c=bim.id,Branding_Order__c=br.id,Quantity__c=12);
        insert blm;
     Brandingcls obj= new Brandingcls();
          obj.save();
          obj.cancel();
  PageReference p=Page.Brandingvfpage;
    
         List<Apexpages.Message> msgs = ApexPages.getMessages();
boolean b = false;
for(Apexpages.Message msg:msgs){
    if (msg.getDetail().contains('Please Enter atleast One Quantity to Create Branding Visit and Branding Order')) b = true;
}
 
   System.assertEquals(true, ApexPages.hasMessages());
 
   }
   
}


i got 94%coverege for this class but only 2 lines belongs to apexpages is not coverd so guys please concentrate on that thing only....
          
I am try to write a test class for custom controller but i got some errors i am not that much familiar with writing test classes here i am post the controller code and test class can anybody find out the errors...help me to reach 100% code coverage

page:

<apex:page controller="Brandingcls" sidebar="true">
<apex:pageMessages />
<apex:form >
    <table width="100%" align="center">
        <tr>
           <td style="font-size:15px" align="center">
              <b>Branding Visit</b>
           </td>
        </tr>
    </table>
    <table width="100%" align="center">
         <tr>
            <td>
               <apex:pageBlock >
                   <apex:pageBlockSection >
                      <apex:inputField value="{!brorder.Order_Date__c}" required="True"/>
                      <apex:inputField value="{!brorder.Account__c}" required="True"/>
                   </apex:pageBlockSection>
               </apex:pageBlock>
            </td>
         </tr>
    </table>
<apex:pageBlock >
            <apex:pageBlockTable value="{!bimaster}" var="b">
                <apex:column headerValue="Branding Items" value="{!b.name}"/>
                <apex:column headerValue="Quantity">
                      <apex:inputField value="{!b.Quantity__c}"/>
                </apex:column>
                <apex:column headerValue="Remarks">
                    <apex:inputField value="{!b.Remarks__c}"/>
                </apex:column>
            </apex:pageBlockTable>
            <apex:pageBlockButtons location="bottom">
                   <apex:commandButton value="Save" action="{!save}"/>&nbsp;&nbsp;
                   <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

controller:
public class Brandingcls
{
   public Branding_Visit__c brvisit{get;set;}
    public Branding_Order__c brorder{get;set;}
    public list<Branding_Item_Master__c> bimaster{get;set;}
    public list<Branding_Line_Item__c> brlineitem{get;set;}
    public Brandingcls()
    {
        bimaster=[select id,Name,Remarks__c,Quantity__c from Branding_Item_Master__c];
          brorder=new Branding_Order__c(Order_Date__c=system.Today());
        brvisit=new Branding_Visit__c(); 
    }
       
    public PageReference save()
    {
      list<Branding_Item_Master__c> lstbritem =new  list<Branding_Item_Master__c>();
          for(Branding_Item_Master__c bim :bimaster)
            {
                   if(bim.Quantity__c>0)
                      {
                        lstbritem.add(bim);
                      } 
            }
        if(lstbritem.Size()>0)
          {
        insert brorder;
        brvisit.Account__c = brorder.Account__c;
        brvisit.Visit_Date__c = brorder.Order_Date__c;
        insert brvisit;
        list<Branding_Line_Item__c> lstbli = new list<Branding_Line_Item__c>();     
          for(Branding_Item_Master__c bm:lstbritem)
             {
                  Branding_Line_Item__c brandli= new Branding_Line_Item__c();
                  
                   
                      brandli.Branding_Order__c=brorder.id;
                      brandli.Branding_Type__c=bm.id;
                      brandli.Quantity__c=bm.Quantity__c;
                      brandli.Remarks__c=bm.Remarks__c;
                      lstbli.add( brandli);
                
                  
             }
             if(lstbli.Size()>0)
             {
                   insert lstbli;
              }
          }
          else
          {
              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please Enter atleast One Quantity to Create Branding Visit and Branding Order'));
              return Null;
          }
             pagereference ref=new pagereference( '/' +brvisit.id); 
                ref.setredirect(true);
                   return ref;
    }
   
   
    public PageReference cancel()
    {
       return null;
    }
}

testclass:
@istest
public class testBrandingcls{
   static testmethod  void  testsave(){
     Branding_Order__c br=new Branding_Order__c(Order_Date__c=system.today(),Account__c='testnaveen');
       insert br;
     Branding_Visit__c bv=new Branding_Visit__c(Visit_Date__c=system.today(),Account__c='testvisit');
       insert bv;
     Branding_Line_Item__c blm=new Branding_Line_Item__c(Branding_Type__c='Branding_Item_Master__c.id',Branding_Order__c='Branding_Order__c.id',Quantity__c=12);
        insert blm;
    Brandingcls obj= new Brandingcls();
          obj.save();
          obj.cancel();
    PageReference p=Page.Brandingvfpage;
        Test.setCurrentPage(p);      
   }
}

Thanks in advance...


Hi everyone i have a requirement to create criteria based sharingrule. but edition limit 50 (enterprise) is exceeded how can i create sharing rule for account object.For this account OWD is set as private!! give me some valuable suggestions or ideas..!!
how to auto populate account field values in custom object(Branding_Visit__c) and in this object i create Account__c field it is lookup to account when we check account from lookup,and i have a fields like State,District,Location on Branding_Visit__c these fields are auto populate from account? how to auto populate this by using formula field or trigger??
trigger updatepicklistlist on Orderc__c (after insert,after  Update,after delete) {
  Map<id,Account> mapAcc=new Map<id,Account>();
  set<id> accids=new set<id>();
list<Orderc__c> lstorder=new list<Orderc__c>();
      for(Orderc__c ord:trigger.new){
       accids.add(ord.Party_Name__c);
   }
     for(Orderc__c ord:trigger.old){
       accids.add(ord.Party_Name__c);
   }
for(account acc:[select id,Status__c,Discount__c from  account where id =: accids]) 
      {
     mapAcc.put(acc.id,acc);
         
     System.debug('List of Acccounts@@@@@@@@@@@@@@@@@@'+mapAcc);
      }
  if(accids.Size()>0)
  {
      for(Orderc__c o:Trigger.New)
      {
          if(mapAcc.get(o.Party_Name__c) .Discount__c==Null)
          {
             o.addError('Please Enter Discount in Account'); 
          }
          else
          {
             mapAcc.get(o.Party_Name__c) .Status__C='Existing';  
          }
       
        
      }
   
  }
Update mapAcc.values();
}
how to write a account trigger toupdate status picklistfield (cold call.prospecting,existing) on account change picklist field
to existing,whenever order is having atleast one order here order is lookup with account.
Here i wrote a proposal vfpage on opportunity i am trying to convert as pdf,here i am getting this error:PDF
generation failed.Check the page markup is valid.
 Can anyone please suggest on the same...
<apex:page standardController="LM_Opportunity__c" renderAs="pdf" sidebar="true" extensions="proposalclass" >
 <apex:form >
<style> 
     tr.spaceUnder > td
     {
     padding-bottom: 2em;
     }
     tr.spaceUnder1 > td
     {
     padding-bottom: 1em;
     }
</style>
    <table align="center" cellspacing="0" cellpadding="0" border="1" width="100%"> 
         <tr>
         <tr width="1%"></tr>
              <table  width="100%" align="right">
                   <tr >
                         <td align="right"><b>Proposal No :  <apex:outputText value="{!L.Proposal_Number__c}"> </apex:outputText></b></td>            
                   </tr>
                   <tr>  
                        <td align="right"><b>Proposal Date : <apex:outputText value="{!Now()}"> </apex:outputText></b></td>            
                   </tr>                                                   
                   </table> 
                              
                   <table >
                           <tr class="spaceUnder1">
                                 <td><b>To,</b></td>
                           </tr>
                           <tr>
                                 <td><b><apex:outputtext value="JAISIM-FOUNTAINHEAD"/></b></td>
                           </tr>
                           <tr>
                                 <td><b>#175/1,PAVILLION ROAD,</b></td>
                           </tr>
                           <tr>
                                 <td><b>JAYANAGAR EAST,1ST BLOCK,</b></td>
                           </tr>
                           <tr class="spaceUnder">
                                 <td ><b>BANGALORE-560011</b></td>
                           </tr>
                           <tr class="spaceUnder1">
                                 <td><b>Kind Attn :</b>&nbsp;{!L.Kind_Attn__r.Name}</td>
                           </tr>
                            <tr class="spaceUnder1">
                                 <td>Dear Madam,</td>
                           </tr>
                            <tr class="spaceUnder1">
                                 <td>Project:</td>
                           </tr>
                           <tr class="spaceUnder1">
                                 <td><b>Sub: Proposal For{!L.Name}</b></td>
                           </tr>
                           <tr>
                                 <td>This has reference to the discussions you had with our Director during his visit to your office.</td>
                           </tr>
                           <tr>
                                 <td>We Provide your organization with a purchasing channel based on ease,trust,and dependability.Our</td>
                           </tr>
                           <tr>
                                 <td>established relationships, our design and planning center in Bangalore and network of reliable global</td>
                           </tr>
                           <tr>
                                 <td>manufacturers,eliminates the intermediaries,taking out the guess work and advancing your supply</td>
                           </tr>
                           <tr>
                                 <td>chain, without sacrificing efficiency or product quality.By utilizing our "Complete Service Chain",</td>
                           </tr>
                         
                           <tr>
                                 <td>Liquid Metal will meet your Furniture needs.We are your global design team,sourcing agent,quality</td>
                           </tr>
                           <tr class="spaceUnder1">
                                 <td>control,and freight-forwarder-all in one.</td>
                           </tr>
                           <tr class="spaceUnder1">
                                 <td>Enclosed is our proposal for your requirement of Alchemy system for maintec Project.</td>
                           </tr>
                           <tr class="spaceUnder">
                                 <td>We look forward to an opportunity to work with you in this project.</td>
                           </tr>
                           <tr class="spaceUnder1">
                                 <td>Thanking you</td>
                           </tr> 
                           <tr class="spaceUnder">
                                 <td><b>For Liquid Metal Furniture Private Limited</b></td>
                           </tr>
                           <tr>
                                 <td><b>{!L.Opportunity_Owner__r.Name}</b></td>
                           </tr> 
                           <tr>
                                 <td><b>Manager-Business Developement</b></td>
                           </tr>    
                  </table>                                                  
                           </tr>
                  </table>
    
    </apex:form>
</apex:page>

 
I have a two fields in Tax master object Excise_Duty__c and Sales_Tax__c  how to write a validation for Only one of the two to be entered.

      i am wrote a formula like this:

OR(
NOT( ISBLANK( Excise_Duty__c ) ),
ISBLANK( Sales_Tax__c )  
)

This is working for only one field for checking condition,how can i check for both fields!
Please provoide me profer solution for this!! Thanks in advance 
I am trying to map total formula field in class but it will through error like this :Error: NewOrderPageClass Compile Error: Field is not writeable: Order_Product__c.Total__c at line 54 column 14
  can you please suggest me how to resolve this issue.

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 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,Total__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.Total__c = p.Total__c;
             op.Remarks__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;
       }
      
}
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;
        
       }
}
Hi Everyone,

   Here i wrote a trigger on task where new task record is inserted or updated ,in account i have custom field called Area__c
   Whenever trigger fires the Area__c filed should outopopulate on task.
   I need your help on without selecting Relatedto(whatid) i am try to save a record it will cause an Attempt to de-reference a null error  how to resove
   this what kind of changes i need to do in trigger.   
   
     Thanks in advance.

trigger Update_Area on Task (before insert, before update)
{    
    set<id> Accids= new set<id>();
    map<id, Account> mapleads = new map<id, Account>();
    Map<Id, List<Task>> whatIds = new Map<Id, List<Task>>{};
    
        for(Task t : trigger.new)
        {
            String objName = t.WhatId.getSObjectType().getDescribe().getName();
            if(t.WhatId!=null )
            {
                if(objName=='Account')
                {
                    Accids.add(t.WhatId);
                }  
            }
        }
    
    list<Account> ldlist = [select id, name,Area__c
                            from Account where id in :Accids];
    
    if(!ldlist.isEmpty())
    {
        for(Account l : ldlist)
        {
            mapleads.put(l.Id, l);
        }
    }        
    for(Task tt: trigger.new)
    {        
        String objName = tt.WhatId.getSObjectType().getDescribe().getName();
        if(tt.WhatId!=null)
        {
            if(objName == 'Account')
            {
                tt.Area__c= mapleads.get(tt.WhatId).Area__c;  
            }
        }  
    }
}
Hi Everyone,

      Here i am trying to write test class for this trigger but i am getting only 42% of code covereage and DML operation bock of Update              consUpdate; is not covered. can you please help me to increse code covereage.
      
      here i am attach trigger and test class
      
 Thanks in advance.

Create_Contact trigger:
    
trigger Create_Contact on Account (After insert,After Update) {
  List<Contact> conlist=new List<Contact>();  
     if(Trigger.isInsert)
       {
       for(Account a: Trigger.New)
         {
         try
         {                            
         List<String> listTsks=a.Primary_Email__c.split('@');
         system.debug('@@@@@@@@@@@@@@@@@@'+listTsks);
         
          
             Contact c=new Contact();  
                c.AccountId=a.id;          
                c.LastName=listTsks[0];                             
                c.Phone= a.Phone;
                c.Email=a.Primary_Email__c;
                c.MobilePhone=a.Mobile__c;
                c.Description=a.Description;
             
                c.Address_Line_1__c=a.Address_Line_1__c;
                c.Address_Line_2__c=a.Address_Line_2__c;
                c.Address_Line_3__c=a.Address_Line_3__c;
                c.City__c=a.City__c;
                c.Country__c=a.Country__c;
                c.PIN_Code__c=a.PIN_Code__c; 
                
               conlist.add(c);                                            
               insert conlist;
               }
               
               catch(exception e)
               {
               }   
         } 
                       
       if(Trigger.isUpdate)
       {
       try
       {
       List<contact> consUpdate=New List<Contact>();
            List<Account> alist=[select id,name,Phone,Mobile__c,Primary_Email__c,Address_Line_2__c,Address_Line_1__c,Address_Line_3__c,Description,Country__c,PIN_Code__c,City__c from Account];
            List<id> ids=new List<id>();
          for(Account a:trigger.new)
           {
              ids.add(a.id);
           }
          List<contact> cons=[select id,name,AccountId,Phone,MobilePhone,Address_Line_2__c,Address_Line_1__c,Address_Line_3__c,Email,Country__c,PIN_Code__c,City__c,LastName from Contact where AccountId=:ids];
          for(Account a1:trigger.new)
          {
              for(Contact c:cons)
              {
                  if(a1.id==c.AccountId)
                  {
                   List<String> listTsks=a1.Primary_Email__c.split('@');
                c.AccountId=a1.id;                    
                c.LastName=listTsks[0];
                c.Phone= a1.Phone;
                c.Email=a1.Primary_Email__c;
                c.MobilePhone=a1.Mobile__c;
                c.Description=a1.Description;
            
                c.Address_Line_1__c=a1.Address_Line_1__c;                
                c.Address_Line_2__c=a1.Address_Line_2__c;
                c.Address_Line_3__c=a1.Address_Line_3__c;
                c.City__c=a1.City__c;
                c.Country__c=a1.Country__c;
                c.PIN_Code__c=a1.PIN_Code__c; 
               
                  consUpdate.add(c);
                  }
                 
              }
          }      
       if(consUpdate.size()>0)
       {
          Update consUpdate; 
       }
       }
       catch(exception e)
       {}
       }  
  }          
         
}

test class:

@isTest
  Public Class TestCreateContactTrigger
  {
    Static TestMethod Void createcontact()
    {
     
      Account a= new Account();
       a.Name='Test Acc';
       a.Phone='123';
       a.Primary_Email__c='test@email.com';
      
       insert a;
       update a;
     
     Contact c=new Contact();
      c.Salutation='Mr';
      c.LastName='a.Name';
      c.Email= a.Primary_Email__c;
      c.AccountId=a.id;
      
      insert c;
   
     
     Account aa = new Account(id=a.id,Name='Acc');
     Update aa;
     
     Contact cc = new Contact(id=c.id,LastName=aa.Name);
     Update cc;
     
      
    }
  }
I am try to write a test class for custom controller but i got some errors i am not that much familiar with writing test classes here i am post the controller code and test class can anybody find out the errors...help me to reach 100% code coverage

page:

<apex:page controller="Brandingcls" sidebar="true">
<apex:pageMessages />
<apex:form >
    <table width="100%" align="center">
        <tr>
           <td style="font-size:15px" align="center">
              <b>Branding Visit</b>
           </td>
        </tr>
    </table>
    <table width="100%" align="center">
         <tr>
            <td>
               <apex:pageBlock >
                   <apex:pageBlockSection >
                      <apex:inputField value="{!brorder.Order_Date__c}" required="True"/>
                      <apex:inputField value="{!brorder.Account__c}" required="True"/>
                   </apex:pageBlockSection>
               </apex:pageBlock>
            </td>
         </tr>
    </table>
<apex:pageBlock >
            <apex:pageBlockTable value="{!bimaster}" var="b">
                <apex:column headerValue="Branding Items" value="{!b.name}"/>
                <apex:column headerValue="Quantity">
                      <apex:inputField value="{!b.Quantity__c}"/>
                </apex:column>
                <apex:column headerValue="Remarks">
                    <apex:inputField value="{!b.Remarks__c}"/>
                </apex:column>
            </apex:pageBlockTable>
            <apex:pageBlockButtons location="bottom">
                   <apex:commandButton value="Save" action="{!save}"/>&nbsp;&nbsp;
                   <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

controller:
public class Brandingcls
{
   public Branding_Visit__c brvisit{get;set;}
    public Branding_Order__c brorder{get;set;}
    public list<Branding_Item_Master__c> bimaster{get;set;}
    public list<Branding_Line_Item__c> brlineitem{get;set;}
    public Brandingcls()
    {
        bimaster=[select id,Name,Remarks__c,Quantity__c from Branding_Item_Master__c];
          brorder=new Branding_Order__c(Order_Date__c=system.Today());
        brvisit=new Branding_Visit__c(); 
    }
       
    public PageReference save()
    {
      list<Branding_Item_Master__c> lstbritem =new  list<Branding_Item_Master__c>();
          for(Branding_Item_Master__c bim :bimaster)
            {
                   if(bim.Quantity__c>0)
                      {
                        lstbritem.add(bim);
                      } 
            }
        if(lstbritem.Size()>0)
          {
        insert brorder;
        brvisit.Account__c = brorder.Account__c;
        brvisit.Visit_Date__c = brorder.Order_Date__c;
        insert brvisit;
        list<Branding_Line_Item__c> lstbli = new list<Branding_Line_Item__c>();     
          for(Branding_Item_Master__c bm:lstbritem)
             {
                  Branding_Line_Item__c brandli= new Branding_Line_Item__c();
                  
                   
                      brandli.Branding_Order__c=brorder.id;
                      brandli.Branding_Type__c=bm.id;
                      brandli.Quantity__c=bm.Quantity__c;
                      brandli.Remarks__c=bm.Remarks__c;
                      lstbli.add( brandli);
                
                  
             }
             if(lstbli.Size()>0)
             {
                   insert lstbli;
              }
          }
          else
          {
              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please Enter atleast One Quantity to Create Branding Visit and Branding Order'));
              return Null;
          }
             pagereference ref=new pagereference( '/' +brvisit.id); 
                ref.setredirect(true);
                   return ref;
    }
   
   
    public PageReference cancel()
    {
       return null;
    }
}

testclass:
@istest
public class testBrandingcls{
   static testmethod  void  testsave(){
     Branding_Order__c br=new Branding_Order__c(Order_Date__c=system.today(),Account__c='testnaveen');
       insert br;
     Branding_Visit__c bv=new Branding_Visit__c(Visit_Date__c=system.today(),Account__c='testvisit');
       insert bv;
     Branding_Line_Item__c blm=new Branding_Line_Item__c(Branding_Type__c='Branding_Item_Master__c.id',Branding_Order__c='Branding_Order__c.id',Quantity__c=12);
        insert blm;
    Brandingcls obj= new Brandingcls();
          obj.save();
          obj.cancel();
    PageReference p=Page.Brandingvfpage;
        Test.setCurrentPage(p);      
   }
}

Thanks in advance...


Hi everyone i have a requirement to create criteria based sharingrule. but edition limit 50 (enterprise) is exceeded how can i create sharing rule for account object.For this account OWD is set as private!! give me some valuable suggestions or ideas..!!