• Hrishikesh Kolhe
  • NEWBIE
  • 20 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 1
    Replies
public class invoice {



public Salesorder__c so{get;set;}
public Invoice__c inc{get;set;}
public list<Salesorder_Line_Product__c> solp{get;set;}
public list<Invoice_Line_Product_No__c> inclp{get;set;}
public string rid{get;set;}


public invoice (){
rid=apexpages.currentpage().getparameters().get('id');
so= new Salesorder__c();
inc= new Invoice__c();
solp=new list<Salesorder_Line_Product__c>();
inclp= new list<Invoice_Line_Product_No__c>();

so=[Select id,Account_Management__c,Contact_Management__c,Delivery_Lead_Time__c,Opportunity_Management__c,Payment_Terms__c,Quote__c,Remarks__c,Salesorder_Date__c,Warranty__c,Valid_Till__c from Salesorder__c where id=:rid];
inc.Salesorder__c=so.id;
inc.Account_Management__c=so.Account_Management__c;
inc.Contact_Management__c=so.Contact_Management__c;
inc.Delivery_Lead_Time__c=so.Delivery_Lead_Time__c;
inc.Opportunity_Management__c=so.Opportunity_Management__c;
inc.Payment_Terms__c=so.Payment_Terms__c;

inc.Quote__c=so.Quote__c;

// inc.Remarks__c=so.Remarks__c;

inc.Warranty__c=so.Warranty__c;
inc.Valid_Till__c=so.Valid_Till__c;
//inc.Total_Amount__c =so.Total_Amount__c ;



//inc.Invoice_Date__c=so.Salesorder_Date__c;


solp=new list<Salesorder_Line_Product__c>();
inclp= new list<Invoice_Line_Product_No__c>();


solp=[Select id,Account_Name__c,Actual_Price__c,Unit_price__c,Total_Price__c,Product_Description__c,CGST__c,CGST_Amount__c,IGST__c,IGST_Amount__c,
      SGST__c,SGST_Amount__c,Quantity__c,Opportunity_Name__c,Quote_Name__c,Salesorder_Name__c,Discounted_Price__c,Discount_Type__c,Product__c from Salesorder_Line_Product__c where Salesorder_Name__c=:rid ];

 for (Salesorder_Line_Product__c  solipo:solp)
 {

Salesorder_Line_Product__c sl =new Salesorder_Line_Product__c ();

 sl.Salesorder_Name__c=solipo.Salesorder_Name__c;
sl.Account_Name__c=solipo.Account_Name__c;

sl.Actual_Price__c=solipo.Actual_Price__c;

sl.Unit_Price__c=solipo.Unit_Price__c;
sl.Quantity__c=solipo.Quantity__c;


//sl.Total_Price__c=solipo.Total_Price__c;

sl.Product_Description__c=solipo.Product_Description__c;


sl.CGST__c=solipo.CGST__c;
//sl.CGST_Amount__c=solipo.CGST_Amount__c;

sl.IGST__c=solipo.IGST__c;

//sl.IGST_Amount__c=solipo.IGST_Amount__c;

sl.SGST__c=solipo.SGST__c;

//sl.SGST_Amount__c=solipo.SGST_Amount__c;
sl.Opportunity_Name__c=solipo.Opportunity_Name__c;

sl.Quote_Name__c=solipo.Quote_Name__c;
sl.Product__c=solipo.Product__c;

//sl.Discounted_Price__c=solipo.Discounted_Price__c;

sl.Discount_Type__c=solipo.Discount_Type__c;

// sl.Discount_Value__c = solipo.Discount_Value__c ;



solp.add(sl);


}
update solp;
 }

public pagereference save(){
 insert inc;
 solp=new list<Salesorder_Line_Product__c>();

 for(Salesorder_Line_Product__c solipo : solp){

Salesorder_Line_Product__c sl =new Salesorder_Line_Product__c ();
//solipo .Salesorder_Name__c=inc.id;
solp.add(sl);
}
insert solp;
pagereference pr=new pagereference('/'+rid);
return pr;

}
}

Invoice get generated but getting error after adding products
System.FinalException: Cannot modify a collection while it is being iterated
public class invoice {

public Salesorder__c so{get;set;}
public Invoice__c i{get;set;}
public list<Salesorder_Line_Product__c> soliList{get;set;}
   public list<Invoice_Line_Product_No__c> iliList{get;set;}
public string s{get;set;}

public invoice ()
{
s=apexpages.currentpage().getparameters().get('id');

so= new Salesorder__c();
i=new Invoice__c();

soliList= new list <Salesorder_Line_Product__c>();
  iliList= new list <Invoice_Line_Product_No__c>();

so=[SELECT id,Account_Management__c,Contact_Management__c,Delivery_Lead_Time__c,Opportunity_Management__c,Payment_terms__c,Quote__c,Remarks__c,Salesorder_Date__c,Warranty__c FROM Salesorder__c WHERE id=:s];

soliList=[SELECT id,Account_Name__c,Actual_price__c,Balanced_Quantity__c,CGST__c,CGST_Amount__c,Product__c,Discounted_Price__c,Discount_Type__c,Discount_Value__c,IGST__c,Quote_Name__c,Product_Description__c,Quantity__c,Salesorder_Name__c,SGST__c,SGST_Amount__c,Total_Price__c,Unit_price__c FROM Salesorder_Line_Product__c WHERE Salesorder_Name__c=:s];



i.Salesorder__c=so.id;
i.Account_Management__c=so.Account_Management__c;
i.Contact_Management__c= so.Contact_Management__c;
i.Delivery_Lead_Time__c=so.Delivery_Lead_Time__c;
i.Opportunity_Management__c=so.Opportunity_Management__c;
i.Payment_terms__c=so.Payment_terms__c;
i.Quote__c=so.Quote__c;
  // i.Remarks__c = so.Remarks__c;
i.Valid_Till__c=so.Valid_Till__c;
i.Warranty__c=so.Warranty__c;

for(Salesorder_Line_Product__c sol:soliList)
{


Salesorder_Line_Product__c inv= new Salesorder_Line_Product__c ();
inv.Salesorder_Name__c=sol.Salesorder_Name__c;
inv.Account_Name__c=sol.Account_Name__c;
inv.Actual_Price__c =sol.Actual_Price__c;
 inv.Quantity__c = sol.Balanced_Quantity__c;   
inv.CGST__c =sol.CGST__c;               
inv.Product__c = sol.Product__c; 
inv.Discount_Type__c=sol.Discount_Type__c;
inv.Discount_Value__c=sol.Discount_Value__c;
inv.IGST__c=sol.IGST__c;
inv.Opportunity_Name__c=sol.Opportunity_Name__c;
inv.Product_Description__c=sol.Product_Description__c;
inv.Quote_Name__c = sol.Quote_Name__c;
inv.SGST__c=sol.SGST__c;
inv.Unit_Price__c=sol.Unit_Price__c;

 // iliList.add(inv);
}

}

public pageReference saveit()
{
    insert i;
    
    for(Invoice_Line_Product_No__c inv: iliList)
    {
   //  inv.Invoice__c = i.Id;
    }
    
    insert iliList;
    
    pageReference pr = new pageReference('/'+s);
    return pr;
    
}

public pageReference cancelit()
{
    
    pageReference pr = new pageReference('/'+s);
    return pr;

}
}
Getting errors invoice is not visible showing this error list has no rows for assignment to SObject
public class accconopp {

public  Account_Management__c acc{get;set;}
public Contact_Management__c con{get;set;}
public Opportunity_Management__c opp{get;set;}

 public accconopp()
 {
acc=new Account_Management__c();
con=new Contact_Management__c();
opp=new Opportunity_Management__c();
}
/*
public pagereference Save()
{
insert acc;
con.AccountID=acc.id;
insert con;
opp.AccountID=acc.id;
insert opp;
pagereference pr=new
pagereference('/'+acc.id);
 return pr;
}
*/
public pagereference cancel(){
pagereference can= new pagereference('/'+acc.id);
return can;
}

}
How to face errrors while working on custom Objects and IDs
public class Editoppallfields {

public Quote_item__c quo{get;set;}

public opportunity opp{get;set;}
 
public string sids{get;set;}

public list<Quote_item__c> 
qili{get;set;}       //Quote line item list

public list<Opportunity>
opli{get;set;}     //opp items list


quo=new Quote_item__c();
opp=new Opportunity();

public Editoppallfields()

{

sids=Apexpages.currentpage().getparameters().get('id');

}

opp=[select Amount,OrderNumber__c, TrackingNumber__c from Opportunity WHERE id=:ids];
opli=new list<Product_Name__c>();

quo.Opportunity = oppId;
quo.Amount=opp.Amount;
quo.OrderNumber__c=opp.OrderNumber__c;


qili=new list<Quote_item__c>();

qili=[select Opportunity__c,Product_Code__c,Product_Name__c,Quantity__c FROM Quote_item__c WHERE id=:Ids];



public pagereference save()
{
list<Quote_item__c> qili=new list<Quote_item__c>();
insert quo;

pagereference pr=new

pagerefernce('/'+opp.id);
return pr;

}
public pagereference cancel(){
pagereference can=new pagereference(+sid);
return can;
}


}
 
Update Account Rating  to  'Hot'  on account when opportunity  stage equals to 'Closed Won' ELSE update account rating to 'Cold'

How to deal with above scenario new one---->

/*Update Account Rating  to  'Hot'  on account when opp stage equals to 'Closed Won' ELSE update account rating to 'Cold'*/
trigger Accountoppstage2 on Opportunity ( After insert, After update) {
    list<Account> acclist= new list<Account>();
     Set<Id> accID = new Set<Id>();
     Set<Id> ratID= new Set<Id>();
    
    for(Opportunity Opp: Trigger.new){
        if(Opp.StageName=='Closed Won'){
            AccID.add(Opp.AccountID);       
        }else{
            ratID.add(Opp.ratID);
        }
    }
    
    for(account acc:[Select Id,Rating from Account where ID In: accID]){
        acc.Rating= 'Hot';
        acclist.add(acc);
    }
     for(account acc:[Select Id,Rating from Account where ID In: ratID]){
        acc.Rating= 'Cold';
        acclist.add(acc);
    }
    Update acclist; 
    
   
}



And Facing below error...................>
Variable does not exist: ratID

Thanks in Advance!!!!!
Can any one help me writing the trigger for upating the account rating field to 'hot' when the oppty stage is equal to 'closed won'?

thanks in advance...