• Guru@SfCloud
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 11
    Replies
Hi Guys,

We have struck in developing of Burndown chart, please provide me the sample code, that would be great help to me.

Thanks in Advance....

Regards,
Gurunath 
Hi All,

I have requirement like based upon the multiple CCAddresses, for every CCAddress I need to create on CaseTeam Memeber under Case.

Can anyone suggest me How to split the CCAddress.

My code is 
Trigger Insert_CaseTeammember on EmailMessage (after insert) 
{   

 Set<String> EmailAddress = new Set<String>();
    Set<Id> ParId = new Set<Id>();
    
    for(EmailMessage Email: Trigger.new)
    {
        for(String Str:Email.CcAddress.Split(',',0))
        {
       
           EmailAddress.add(str);
         }
       
        ParId.add(Email.parentid);
    }
    
   
    List<Contact> listContacts = [Select Id,Email From Contact Where Email=:EmailAddress];
    CaseTeamRole role = [select Id from CaseTeamRole where Name =:'Backup FAE' limit 1];
    case cse=[select id,contactid from case where id=:ParId];
    
     List<CaseTeamMember> CaseTeam = new List<CaseTeamMember>();
     
       if(!listContacts.isempty())
        {    
          for(contact con:listContacts)
           {
              CaseTeamMember ct = new CaseTeamMember();
               ct.MemberId = con.Id;
               ct.ParentId = cse.id;
               ct.TeamRoleId = role.Id;
                
                CaseTeam.add(Ct);
                
               //insert ct;
           }  
        }
    
    if(!CaseTeam.isempty())
        {
        
        Insert CaseTeam;
        
        }     
 
 }

It is not working for multiple CCAddresses working for only one CCAddress.
Can any suggest where I did the Mistake .....this trigger needs to fire for Multiple CCAddresses.

If anyone help it would be greatly appreciated.

Thanks in Advance,
Gurunath Jinka.
Hi All,

This is Gurunath,I have a problem with standard Email-To-case functionality.
The Issue is some times standard email-to-case trigger is taking too much time(taking routing address and sending mail from another account to this routing address ) nearly 30 min and some time it will not take more than one min and I dont what is happening .

Can anyone please suggest me how to overcome this issue

If anyone help would be greatly appreciated.

Thanks in Advance,
Gurunath Jinka
 
Hello Everyone,

Can anyone please suggest me how to integrate the salesforce.com with Lotus notes.
Suggest me which type integration will possible like SOAP or REST Services(Except App's that which are available from App Exchange).


If Possible with SOAP or REST, Please provide the related information(Document) or Developer's Guide(Lotus Notes Developer's Guide).

Thanks,
Gurunath Jinka.
Hi All,

Right now I have a trigger on Opportunity, from the trigger I am calling the schedule class.
My concern is when I upload the opportunitties more than 100 it is throwing the error like Too many SOQL queries.
In my Trigger I am using the Iterator(Some where i red that iterator is an statefull protocol),so it is causing to fire class more than 100 times(Limit is 100 schedule jobs per day).

So anybody please suggest me how tom make the Schedule class as Stateless one....

If any one Help would be greatly appriciated.

Thanks,
Gurunath Jinka
Hi,

I am firing the trigger on Opportunity and calling the schedule class when I Upload the data like 200 records it is showing the error like too many soql queries and can any one help me to resolve this issue........

Trigger is:
trigger OpportunityTrigger on Opportunity (before update, before insert) {   
    //if(!SalesStageOrderIterable.doneit) {
        SalesStageOrderIterable.doneit = true;
        Map<String, Opportunity> opportunityMap = new Map<String, Opportunity>();
        Map<String, List<String>> oppToStagesMap = new Map<String, List<String>>();
        for(integer i=0; i<Trigger.size; i++) {
           
            Opportunity newOpportunity = Trigger.new[i];
            newOpportunity.SkipStages__c = true;
            opportunityMap.put(newOpportunity.Name+newOpportunity.CloseDate+newOpportunity.AccountId,newOpportunity);
            System.debug('DPK: newOpportunity: '+newOpportunity);
            //if(!newOpportunity.Override_Missing_Fields__c) {
                //SalesStageFieldChecker.checkFields(newOpportunity);           
            //}
           
            //Opportunity oldOpportunity = Trigger.old[i];
            if((Trigger.isInsert && newOpportunity.LeadSource != 'Sales Generated')
               || (!newOpportunity.Trigger_Ignore_Stage_Update__c &&
               (Trigger.isUpdate && newOpportunity.StageName != Trigger.old[i].StageName)
              )) {
                  System.debug('DPK:0.1');
                  //check change is 1 step, otherwise add to stagetracking Map<Id,List<String>>
                  String oldStageName;
                  if(Trigger.isUpdate) {
                      oldStageName = Trigger.old[i].StageName;
                      System.debug('DPK:0.2:'+oldStageName);
                  } else if(Trigger.isInsert) {
                      oldStageName = 'Start';
                      System.debug('DPK:0.3:'+oldStageName);
                  }
                  String newStageName = newOpportunity.StageName;
                 
                  System.debug('DPK - old:new: '+oldStageName+':'+newStageName);
                  Iterator<Sales_Opportunity_Stage_Order__c> iter = new foo().Iterator();
                  System.debug('DPK:iter: '+iter);
                  List<String> stagesToPass = oppToStagesMap.get(newOpportunity.Name+newOpportunity.CloseDate+newOpportunity.AccountId);
                  if(stagesToPass == null) {
                      stagesToPass = new List<String>();
                      oppToStagesMap.put(newOpportunity.Name+newOpportunity.CloseDate+newOpportunity.AccountId,stagesToPass);
                  }
                  System.debug('DPK:iter: '+iter);
                  boolean breakout = false;
                  boolean newStageSeen = false;
                  while(iter.hasNext() && !breakout) {
                      Sales_Opportunity_Stage_Order__c stage = iter.next();
                      if(stage.StageName__c == oldStageName) {
                          System.debug('DPK:1:'+oldStageName);
                         
                          while(iter.hasNext() && !breakout) {
                              System.debug('DPK:2');
                              Sales_Opportunity_Stage_Order__c nextStage = iter.next();
                              if(nextStage.StageName__c == newStageName) {
                                  System.debug('DPK:3:'+newStageName);
                                  breakout = true;
                                  newStageSeen = true;
                              } else {    
                                  newOpportunity.ShowMessage__c = true;
                                  newOpportunity.MessageShown__c = false;
                                  stagesToPass.add(nextStage.StageName__c);
                              }
                          }
                      }
                     
                  }
                  if(!newStageSeen) {
                      stagesToPass.clear();
                      newOpportunity.ShowMessage__c = false;
                  }
                  stagesToPass.add(newOpportunity.StageName);
                 
              }
            newOpportunity.Trigger_Ignore_Stage_Update__c = false;
        }
   
    List<Task> tasksToInsert = new List<Task>();

   
   
    for(String oppId : oppToStagesMap.keySet()) {
        System.debug('DPK:oppId'+oppId);
        Opportunity thisOpp = opportunityMap.get(oppId);
        String requestedStage = thisOpp.StageName;
        List<String> stagesToPass = oppToStagesMap.get(oppId);
        System.debug('DPK:stagesToPass:'+stagesToPass);           
        if(stagesToPass != null && !stagesToPass.isEmpty()) {
            if(thisOpp.SkipStages__c == true || stagesToPass.size()==1 || (stagesToPass.size() == 2 && stagesToPass[0] == 'Marketing Qualified')) {           
                for(integer i=0; i<stagesToPass.size(); i++) {
                   
                    if(i==0) {
                        thisOpp.StageName = stagesToPass[i];   
                    } else {
                        DateTime inXMinutes = DateTime.now().addMinutes(i);
                        String hour = String.valueOf(inXMinutes.hour());
                        String min = String.valueOf(inXMinutes.minute());
                        String ss = String.valueOf(inXMinutes.second());
                       
                        String triggerId = EncodingUtil.convertToHex(crypto.generateAesKey(128)).substring(1,20).toUpperCase();
                        String cronJobName = 'OpportunityStageUpdate@'+inXMinutes+':'+triggerId;
                        String nextFireTimeCron = ss + ' ' + min + ' ' + hour + ' * * ?';
                        String jobName = thisOpp.Name+':'+stagesToPass[i]+':'+inXMinutes;

//it is showing error from below line where calling the schedulable method and error is too many soql Queries                        
OpportunitySchedulable schedulable = new OpportunityStageUpdateSchedulable(jobName,thisOpp.id,stagesToPass[i],thisOpp.Name,thisOpp.CloseDate,thisOpp.AccountId);
                       
                        System.schedule(jobName, nextFireTimeCron, schedulable);
                        System.debug('DPK:stagesToPass[i]'+stagesToPass[i]);           
                       
                       
                       
                    }
                }
            }
            //else {
            //    thisOpp.addError('You have skipped some Stages. Please check "Skip Stages" if you want to continue.');
            //}
        }
       
        }
    //}
   
}

Schedule class is:
==============

global class OpportunitySchedulable implements Schedulable {

    private String cronJobName;
    private String stageName;
    private Id opportunityId;
    private String opportunityName;
    private Date closeDate;
    private Id accountId;
   
    global OpportunityStageUpdateSchedulable(String cronJobName, Id opportunityId, String stageName, String opportunityName, Date closeDate, Id accountId) {
        this.cronJobName = cronJobName;
        this.stageName = stageName;
        this.opportunityId = opportunityId;
        this.opportunityName = opportunityName;
        this.closeDate = closeDate;
        this.accountId = accountId;
       
    }
   
    global void execute(SchedulableContext ctx) {
       
        //newOpportunity.Name+newOpportunity.CloseDate+newOpportunity.AccountId
        List<Opportunity> opps;
       
        if(!String.isBlank(opportunityId)) {
            opps = [SELECT id FROM Opportunity WHERE id = :opportunityId];   
        }
        if(opps == null || opps.isEmpty()) {
            opps = [SELECT id FROM Opportunity WHERE Name = :opportunityName AND CloseDate = :closeDate AND AccountID = :accountId];
        }
        Opportunity theOpp;
        if(!opps.isEmpty()) {
            theOpp = opps[0];
        }
        if(theOpp != null) {
            theOpp.StageName = stageName;
            theOpp.Trigger_Ignore_Stage_Update__c = true;
            update theOpp;
        }
       
        CronTrigger cr =[SELECT id FROM CronTrigger WHERE CronJobDetail.Name = :cronJobName];

        System.abortJob(cr.id);   
    }
}


Hi,

I am trying to get the 100% coede coverage for my class but i strucked at 53% ,can anyone suggest me how to get the 100 % code coverage. if any one help would be greatly appriciated.

My Class wich is not get Covered(Bold lines are not get covered)

trigger CreatinOpportunities on Opportunity (after update) {

    Set<Id>  OppId=New Set<Id>();

    for(Opportunity Opp:trigger.new)
    {
        if(Opp.Sync_to_Sage__c=='Sent to Sage')
           OppId.add(Opp.id);
    }
      
   if(Oppid.size()>0)
   {
       List<Asset> AssetLst=new List<Asset>();
      
       System.debug('helllllllllllooooo'+Oppid.size());
      
       for(Schema.OpportunityLineItem OppLine:[Select id,Name,Quantity,Opportunity.Accountid,Description from OpportunityLineItem where Opportunityid IN:oppid] )
       {
           System.debug('OppLine.Size()***********'+OppLine);
      
           for(Integer i=0;i<OppLine.Quantity;i++)
           {
                        asset a = new asset();
                        a.name=OppLine.name;
                        a.Enquiry__c = OppLine.OpportunityId;         
                        a.Accountid= OppLine.Opportunity.AccountId;
                        a.Description = OppLine.Description;
                        //a.Product2Id = OLI.ProductCode;// There is no product code field on the Asset object
                        //a.Supplier__C = OLI.Make_Model__c;//Field is not writable
                        //a.Equipmentcost = //no field is available with this name  in asset                     
                        AssetLst.add(a);  
           }
       }

     insert AssetLst;  
   }

My Test Class:

@isTest
Public class CreatinOpportunities_Test{
    Public static testMethod void CreatinOpportunities_class_Test(){
   
  
       
        Account Acc = new Account();
        Acc.Name = 'TestAccount';
        Insert Acc;
       
        Contact Con = new Contact();
        Con.AccountId = Acc.Id;
        Con.LastName = 'ContactLast';
        Insert Con;
      
       
        Opportunity Opp =  new Opportunity();
        Opp.Account = Acc;
        Opp.Account_on_hold__c = true;
        Opp.Name = 'TestOpportunity';
        Opp.StageName = 'Prospecting';
        Opp.Sync_to_Sage__c = 'Sent to Sage';
        Opp.CloseDate = System.Today().adddays(10);
       
        Insert Opp;
       
       
       
       
        Product2 Prod = new Product2();
        Prod.Name = 'TestProduct';
        Prod.CurrencyIsoCode = 'EUR';
        //Prod.UseStandardPrice=false;       
       
        Insert Prod;
       
      
        Opportunity Opp1 =  new Opportunity();
        Opp1.Account = Acc;
        Opp1.Account_on_hold__c = true;
        Opp1.Name = 'TestOpportunity';
        Opp1.StageName = 'Prospecting';
        Opp1.Sync_to_Sage__c = 'Ready to sync';
        Opp1.CloseDate = System.Today().adddays(30);
      
       
        Insert Opp1;
       
        Opp1.Sync_to_Sage__c = 'Sent to Sage';
       
        Update Opp1;
       
        List<Opportunity> OppLst = new  List<Opportunity >{Opp,Opp1};
       
       
        Asset Ass = new Asset();
        Ass.Name = 'TestAss';
        Ass.AccountId = Acc.Id;
        Ass.CurrencyIsoCode = 'EUR';
        Ass.Enquiry__c = Opp1.Id;      
       
        Insert Ass;
          
        Pricebook2 price = new Pricebook2(Name = 'TestPrice',IsActive = true);
      
        //PriceBook2 pb2Standard = [select Id from Pricebook2 where  Name =:'Standard Price Book' AND isActive = true Limit 1];
       
       
    
        PricebookEntry prEntry = new PricebookEntry(Pricebook2Id = price.Id,UnitPrice = 10.00,Product2Id = Prod.Id,IsActive = true);
     
       
        OpportunityLineItem OppLi = new OpportunityLineItem(OpportunityId = Opp.Id,Quantity = 1,TotalPrice = 200,PricebookEntryId = PrEntry.Id);
       
        OpportunityLineItem OppLi1 = new OpportunityLineItem(OpportunityId = Opp1.Id,Quantity = 2,TotalPrice = 100,PricebookEntryId = PrEntry.Id);
       
        OpportunityLineItem OppLi2 = new OpportunityLineItem(OpportunityId = Opp1.Id,Quantity = 3,TotalPrice = 150,PricebookEntryId = PrEntry.Id);
       
  
        List<OpportunityLineItem > OppLst1 = new  List<OpportunityLineItem >{OppLi,OppLi1,OppLi2};
       
      
       
        //System.debug('OppLst1**************'+OppLst1.Size());
     
   
    }

}


Hi all, right now i am facing the code coverage issue ,my current code coverage is 41% ,can any one suggest me how to make it as 100% thanks in advance

my code is
Bold line are not get covered
Public class CreatingAssetsForOpportunities_class{

    Public static List<Asset> AssetLst = new List<Asset>(); 
    Public static Asset Assets = new Asset(); 

    public static void insertAssets(List<Opportunity> OppLst){
   
        System.debug('Method called from trigger');
        for(Opportunity O : OppLst){
       
            if(OppLst.size()>0){
           
                    System.debug('O.Sync_to_Sage__c : '+O.Sync_to_Sage__c);
                    if(O.Sync_to_Sage__c == 'Sent to Sage'){
                   
                    System.debug('O.OpportunityLineItems.size : '+O.OpportunityLineItems.size());
                    if(O.OpportunityLineItems.size()>0){
                   
                        for(OpportunityLineItem OLI : O.OpportunityLineItems){
                       
                            for(integer i = 0; i < OLI.Quantity; i++){
                                //Asset Assets = new Asset();
                                Assets = insertingMethod(OLI);
                                system.debug('Assets : '+insertingMethod(OLI));
                                AssetLst.add(Assets);
                                //insert AssetLst;
                            }
                        }
                        insert AssetLst;
                    }
                }
            }
        }
    }
   
    Public static Asset insertingMethod(OpportunityLineItem OLItoUseForAssetInsert){
   
        Asset A = new Asset();
        A.name = OLItoUseForAssetInsert.name;
        //A.ProductCode = OLItoUseForAssetInsert.ProductCode;  //Error : Invalid field ProductCode for SObject Asset
        //A.Description__c = OLItoUseForAssetInsert.Description;  //Error: Field is not writeable: Asset.Description__c
        //A.Supplier__C = OLItoUseForAssetInsert.;
        //no dimentions field
        //no equipment Cost
        A.Enquiry__c = OLItoUseForAssetInsert.Opportunity.Id;
        //AssetLst.add(A);
        return A;
    }
}
Hi,

Any one has involved in filenet to salesforce integration..... if so please share your ideas about the integration.
if any one helped would be greatly  appriciated.

Hi ,

I created trigger for lead conversion and i  am doing the lead conversion in class and its working properly but i am facing the issue with the Test code  coverage for classand my trigger had 100 % code coverage

Right now i am getting only 61% code coverage for my test class and please find the both trigger and class as well.

Trigger
------------:

trigger Leads on Lead (after update) {
    
    if(Trigger.isAfter && Trigger.isUpdate){
        Leads l = new Leads();
        l.SetContactRoleDefaults(Trigger.new, Trigger.oldMap);
    }

for this i had 100% code coverage

Class
======:



public class Leads {
    
// Sets default values on the Opportunity and Opportunity Contact Role record created during Conversion. Called on AFTER UPDATE
public void SetContactRoleDefaults(Lead[] leads, map<ID,Lead> old_leads)
{
    
    set<ID> set_opptyIDs = new set<ID>();
                
    // Get Opportunity IDs into a Set if the lead was just converted and an Opportunity was created
    for (Lead l:leads){
        if (l.IsConverted && !old_leads.get(l.id).IsConverted){
            if (l.ConvertedOpportunityId != null){
                set_opptyIDs.add(l.ConvertedOpportunityId);
            }
        }
    }
    
    // Update Opportunity Contact Roles
    list<OpportunityContactRole> list_opptyContactRolesToUpdate = new list<OpportunityContactRole>();
    for(OpportunityContactRole ocr:[select Id,IsPrimary,Role from OpportunityContactRole where OpportunityId in :set_opptyIDs]) {
        ocr.IsPrimary = true;
        ocr.Role = 'Decision Maker'; // set to what you want defaulted
        list_opptyContactRolesToUpdate.add(ocr);

    }
    
     System.debug('list_opptyContactRolesToUpdate size : '+list_opptyContactRolesToUpdate.size());
    
    if (list_opptyContactRolesToUpdate.size() > 0) {
    System.debug('list_opptyContactRolesToUpdate : '+list_opptyContactRolesToUpdate);
        delete list_opptyContactRolesToUpdate;
    }
    
}

}
Bold lines are not get covered

Test Class:
==========
@IsTest
private class Leads_Test {
    static testMethod void SetContactRoleDefaults_Test() {
           
            RecordType Rectype = [Select id from RecordType where name=:'Insurance Provider'];
            
            Account Acc = new Account();
            Acc.Name = 'Company';
            Acc.RecordTypeId = Rectype.Id;
            Insert Acc;
          
            Lead l = new Lead();
            l.lastname = 'Lastname';
            l.firstname = 'FirstName';
            l.company = 'Company';
            //l.Ready_to_Convert__c = true;
            insert l;
         
            System.debug('--------l Value---------'+l);
       
            User testUser1 = new User();
          
            //Convert the Lead
            test.startTest();
           
            Database.LeadConvert lc = new database.LeadConvert();          
            lc.setLeadId(l.id);
            lc.setDoNotCreateOpportunity(true);
            lc.setOwnerId(testUser1.id);
            lc.setConvertedStatus('Qualified');
           
            Database.LeadConvertResult lcr = Database.convertLead(lc);
            System.assert(lcr.isSuccess());
           
            Lead existingLead = [Select id, isConverted, ConvertedAccountId, ConvertedOpportunityId, createdbyid FROM Lead where id = :l.id];
           
            System.assert(existingLead.isConverted);
            System.assert(existingLead.ConvertedAccountId != null);
            System.assert(existingLead.ConvertedOpportunityId != null);
           
            test.stopTest();

}
}
Right now my code coverage is 61% can any help me  to reach the 100%
if any one help would be greatly appriciated .


Hi All,

I have requirement like based upon the multiple CCAddresses, for every CCAddress I need to create on CaseTeam Memeber under Case.

Can anyone suggest me How to split the CCAddress.

My code is 
Trigger Insert_CaseTeammember on EmailMessage (after insert) 
{   

 Set<String> EmailAddress = new Set<String>();
    Set<Id> ParId = new Set<Id>();
    
    for(EmailMessage Email: Trigger.new)
    {
        for(String Str:Email.CcAddress.Split(',',0))
        {
       
           EmailAddress.add(str);
         }
       
        ParId.add(Email.parentid);
    }
    
   
    List<Contact> listContacts = [Select Id,Email From Contact Where Email=:EmailAddress];
    CaseTeamRole role = [select Id from CaseTeamRole where Name =:'Backup FAE' limit 1];
    case cse=[select id,contactid from case where id=:ParId];
    
     List<CaseTeamMember> CaseTeam = new List<CaseTeamMember>();
     
       if(!listContacts.isempty())
        {    
          for(contact con:listContacts)
           {
              CaseTeamMember ct = new CaseTeamMember();
               ct.MemberId = con.Id;
               ct.ParentId = cse.id;
               ct.TeamRoleId = role.Id;
                
                CaseTeam.add(Ct);
                
               //insert ct;
           }  
        }
    
    if(!CaseTeam.isempty())
        {
        
        Insert CaseTeam;
        
        }     
 
 }

It is not working for multiple CCAddresses working for only one CCAddress.
Can any suggest where I did the Mistake .....this trigger needs to fire for Multiple CCAddresses.

If anyone help it would be greatly appreciated.

Thanks in Advance,
Gurunath Jinka.
Hello Everyone,

Can anyone please suggest me how to integrate the salesforce.com with Lotus notes.
Suggest me which type integration will possible like SOAP or REST Services(Except App's that which are available from App Exchange).


If Possible with SOAP or REST, Please provide the related information(Document) or Developer's Guide(Lotus Notes Developer's Guide).

Thanks,
Gurunath Jinka.
Hi All,

Right now I have a trigger on Opportunity, from the trigger I am calling the schedule class.
My concern is when I upload the opportunitties more than 100 it is throwing the error like Too many SOQL queries.
In my Trigger I am using the Iterator(Some where i red that iterator is an statefull protocol),so it is causing to fire class more than 100 times(Limit is 100 schedule jobs per day).

So anybody please suggest me how tom make the Schedule class as Stateless one....

If any one Help would be greatly appriciated.

Thanks,
Gurunath Jinka
Hi,

I am firing the trigger on Opportunity and calling the schedule class when I Upload the data like 200 records it is showing the error like too many soql queries and can any one help me to resolve this issue........

Trigger is:
trigger OpportunityTrigger on Opportunity (before update, before insert) {   
    //if(!SalesStageOrderIterable.doneit) {
        SalesStageOrderIterable.doneit = true;
        Map<String, Opportunity> opportunityMap = new Map<String, Opportunity>();
        Map<String, List<String>> oppToStagesMap = new Map<String, List<String>>();
        for(integer i=0; i<Trigger.size; i++) {
           
            Opportunity newOpportunity = Trigger.new[i];
            newOpportunity.SkipStages__c = true;
            opportunityMap.put(newOpportunity.Name+newOpportunity.CloseDate+newOpportunity.AccountId,newOpportunity);
            System.debug('DPK: newOpportunity: '+newOpportunity);
            //if(!newOpportunity.Override_Missing_Fields__c) {
                //SalesStageFieldChecker.checkFields(newOpportunity);           
            //}
           
            //Opportunity oldOpportunity = Trigger.old[i];
            if((Trigger.isInsert && newOpportunity.LeadSource != 'Sales Generated')
               || (!newOpportunity.Trigger_Ignore_Stage_Update__c &&
               (Trigger.isUpdate && newOpportunity.StageName != Trigger.old[i].StageName)
              )) {
                  System.debug('DPK:0.1');
                  //check change is 1 step, otherwise add to stagetracking Map<Id,List<String>>
                  String oldStageName;
                  if(Trigger.isUpdate) {
                      oldStageName = Trigger.old[i].StageName;
                      System.debug('DPK:0.2:'+oldStageName);
                  } else if(Trigger.isInsert) {
                      oldStageName = 'Start';
                      System.debug('DPK:0.3:'+oldStageName);
                  }
                  String newStageName = newOpportunity.StageName;
                 
                  System.debug('DPK - old:new: '+oldStageName+':'+newStageName);
                  Iterator<Sales_Opportunity_Stage_Order__c> iter = new foo().Iterator();
                  System.debug('DPK:iter: '+iter);
                  List<String> stagesToPass = oppToStagesMap.get(newOpportunity.Name+newOpportunity.CloseDate+newOpportunity.AccountId);
                  if(stagesToPass == null) {
                      stagesToPass = new List<String>();
                      oppToStagesMap.put(newOpportunity.Name+newOpportunity.CloseDate+newOpportunity.AccountId,stagesToPass);
                  }
                  System.debug('DPK:iter: '+iter);
                  boolean breakout = false;
                  boolean newStageSeen = false;
                  while(iter.hasNext() && !breakout) {
                      Sales_Opportunity_Stage_Order__c stage = iter.next();
                      if(stage.StageName__c == oldStageName) {
                          System.debug('DPK:1:'+oldStageName);
                         
                          while(iter.hasNext() && !breakout) {
                              System.debug('DPK:2');
                              Sales_Opportunity_Stage_Order__c nextStage = iter.next();
                              if(nextStage.StageName__c == newStageName) {
                                  System.debug('DPK:3:'+newStageName);
                                  breakout = true;
                                  newStageSeen = true;
                              } else {    
                                  newOpportunity.ShowMessage__c = true;
                                  newOpportunity.MessageShown__c = false;
                                  stagesToPass.add(nextStage.StageName__c);
                              }
                          }
                      }
                     
                  }
                  if(!newStageSeen) {
                      stagesToPass.clear();
                      newOpportunity.ShowMessage__c = false;
                  }
                  stagesToPass.add(newOpportunity.StageName);
                 
              }
            newOpportunity.Trigger_Ignore_Stage_Update__c = false;
        }
   
    List<Task> tasksToInsert = new List<Task>();

   
   
    for(String oppId : oppToStagesMap.keySet()) {
        System.debug('DPK:oppId'+oppId);
        Opportunity thisOpp = opportunityMap.get(oppId);
        String requestedStage = thisOpp.StageName;
        List<String> stagesToPass = oppToStagesMap.get(oppId);
        System.debug('DPK:stagesToPass:'+stagesToPass);           
        if(stagesToPass != null && !stagesToPass.isEmpty()) {
            if(thisOpp.SkipStages__c == true || stagesToPass.size()==1 || (stagesToPass.size() == 2 && stagesToPass[0] == 'Marketing Qualified')) {           
                for(integer i=0; i<stagesToPass.size(); i++) {
                   
                    if(i==0) {
                        thisOpp.StageName = stagesToPass[i];   
                    } else {
                        DateTime inXMinutes = DateTime.now().addMinutes(i);
                        String hour = String.valueOf(inXMinutes.hour());
                        String min = String.valueOf(inXMinutes.minute());
                        String ss = String.valueOf(inXMinutes.second());
                       
                        String triggerId = EncodingUtil.convertToHex(crypto.generateAesKey(128)).substring(1,20).toUpperCase();
                        String cronJobName = 'OpportunityStageUpdate@'+inXMinutes+':'+triggerId;
                        String nextFireTimeCron = ss + ' ' + min + ' ' + hour + ' * * ?';
                        String jobName = thisOpp.Name+':'+stagesToPass[i]+':'+inXMinutes;

//it is showing error from below line where calling the schedulable method and error is too many soql Queries                        
OpportunitySchedulable schedulable = new OpportunityStageUpdateSchedulable(jobName,thisOpp.id,stagesToPass[i],thisOpp.Name,thisOpp.CloseDate,thisOpp.AccountId);
                       
                        System.schedule(jobName, nextFireTimeCron, schedulable);
                        System.debug('DPK:stagesToPass[i]'+stagesToPass[i]);           
                       
                       
                       
                    }
                }
            }
            //else {
            //    thisOpp.addError('You have skipped some Stages. Please check "Skip Stages" if you want to continue.');
            //}
        }
       
        }
    //}
   
}

Schedule class is:
==============

global class OpportunitySchedulable implements Schedulable {

    private String cronJobName;
    private String stageName;
    private Id opportunityId;
    private String opportunityName;
    private Date closeDate;
    private Id accountId;
   
    global OpportunityStageUpdateSchedulable(String cronJobName, Id opportunityId, String stageName, String opportunityName, Date closeDate, Id accountId) {
        this.cronJobName = cronJobName;
        this.stageName = stageName;
        this.opportunityId = opportunityId;
        this.opportunityName = opportunityName;
        this.closeDate = closeDate;
        this.accountId = accountId;
       
    }
   
    global void execute(SchedulableContext ctx) {
       
        //newOpportunity.Name+newOpportunity.CloseDate+newOpportunity.AccountId
        List<Opportunity> opps;
       
        if(!String.isBlank(opportunityId)) {
            opps = [SELECT id FROM Opportunity WHERE id = :opportunityId];   
        }
        if(opps == null || opps.isEmpty()) {
            opps = [SELECT id FROM Opportunity WHERE Name = :opportunityName AND CloseDate = :closeDate AND AccountID = :accountId];
        }
        Opportunity theOpp;
        if(!opps.isEmpty()) {
            theOpp = opps[0];
        }
        if(theOpp != null) {
            theOpp.StageName = stageName;
            theOpp.Trigger_Ignore_Stage_Update__c = true;
            update theOpp;
        }
       
        CronTrigger cr =[SELECT id FROM CronTrigger WHERE CronJobDetail.Name = :cronJobName];

        System.abortJob(cr.id);   
    }
}


Hi,

I am trying to get the 100% coede coverage for my class but i strucked at 53% ,can anyone suggest me how to get the 100 % code coverage. if any one help would be greatly appriciated.

My Class wich is not get Covered(Bold lines are not get covered)

trigger CreatinOpportunities on Opportunity (after update) {

    Set<Id>  OppId=New Set<Id>();

    for(Opportunity Opp:trigger.new)
    {
        if(Opp.Sync_to_Sage__c=='Sent to Sage')
           OppId.add(Opp.id);
    }
      
   if(Oppid.size()>0)
   {
       List<Asset> AssetLst=new List<Asset>();
      
       System.debug('helllllllllllooooo'+Oppid.size());
      
       for(Schema.OpportunityLineItem OppLine:[Select id,Name,Quantity,Opportunity.Accountid,Description from OpportunityLineItem where Opportunityid IN:oppid] )
       {
           System.debug('OppLine.Size()***********'+OppLine);
      
           for(Integer i=0;i<OppLine.Quantity;i++)
           {
                        asset a = new asset();
                        a.name=OppLine.name;
                        a.Enquiry__c = OppLine.OpportunityId;         
                        a.Accountid= OppLine.Opportunity.AccountId;
                        a.Description = OppLine.Description;
                        //a.Product2Id = OLI.ProductCode;// There is no product code field on the Asset object
                        //a.Supplier__C = OLI.Make_Model__c;//Field is not writable
                        //a.Equipmentcost = //no field is available with this name  in asset                     
                        AssetLst.add(a);  
           }
       }

     insert AssetLst;  
   }

My Test Class:

@isTest
Public class CreatinOpportunities_Test{
    Public static testMethod void CreatinOpportunities_class_Test(){
   
  
       
        Account Acc = new Account();
        Acc.Name = 'TestAccount';
        Insert Acc;
       
        Contact Con = new Contact();
        Con.AccountId = Acc.Id;
        Con.LastName = 'ContactLast';
        Insert Con;
      
       
        Opportunity Opp =  new Opportunity();
        Opp.Account = Acc;
        Opp.Account_on_hold__c = true;
        Opp.Name = 'TestOpportunity';
        Opp.StageName = 'Prospecting';
        Opp.Sync_to_Sage__c = 'Sent to Sage';
        Opp.CloseDate = System.Today().adddays(10);
       
        Insert Opp;
       
       
       
       
        Product2 Prod = new Product2();
        Prod.Name = 'TestProduct';
        Prod.CurrencyIsoCode = 'EUR';
        //Prod.UseStandardPrice=false;       
       
        Insert Prod;
       
      
        Opportunity Opp1 =  new Opportunity();
        Opp1.Account = Acc;
        Opp1.Account_on_hold__c = true;
        Opp1.Name = 'TestOpportunity';
        Opp1.StageName = 'Prospecting';
        Opp1.Sync_to_Sage__c = 'Ready to sync';
        Opp1.CloseDate = System.Today().adddays(30);
      
       
        Insert Opp1;
       
        Opp1.Sync_to_Sage__c = 'Sent to Sage';
       
        Update Opp1;
       
        List<Opportunity> OppLst = new  List<Opportunity >{Opp,Opp1};
       
       
        Asset Ass = new Asset();
        Ass.Name = 'TestAss';
        Ass.AccountId = Acc.Id;
        Ass.CurrencyIsoCode = 'EUR';
        Ass.Enquiry__c = Opp1.Id;      
       
        Insert Ass;
          
        Pricebook2 price = new Pricebook2(Name = 'TestPrice',IsActive = true);
      
        //PriceBook2 pb2Standard = [select Id from Pricebook2 where  Name =:'Standard Price Book' AND isActive = true Limit 1];
       
       
    
        PricebookEntry prEntry = new PricebookEntry(Pricebook2Id = price.Id,UnitPrice = 10.00,Product2Id = Prod.Id,IsActive = true);
     
       
        OpportunityLineItem OppLi = new OpportunityLineItem(OpportunityId = Opp.Id,Quantity = 1,TotalPrice = 200,PricebookEntryId = PrEntry.Id);
       
        OpportunityLineItem OppLi1 = new OpportunityLineItem(OpportunityId = Opp1.Id,Quantity = 2,TotalPrice = 100,PricebookEntryId = PrEntry.Id);
       
        OpportunityLineItem OppLi2 = new OpportunityLineItem(OpportunityId = Opp1.Id,Quantity = 3,TotalPrice = 150,PricebookEntryId = PrEntry.Id);
       
  
        List<OpportunityLineItem > OppLst1 = new  List<OpportunityLineItem >{OppLi,OppLi1,OppLi2};
       
      
       
        //System.debug('OppLst1**************'+OppLst1.Size());
     
   
    }

}


Hello there,

Please tell me if is there any way by which I can insert Username and Password into the Visualforce Email Template?

Thanks in advance.
here, my requirments whenever i am creating new records on case object, insert or update to custom object cases__C, suppose i want to delete records in case objects
that corresponding records delete in custom object cases__C.how to do ?

trigger CreateCases on Case (after insert,after update)
{

  Case cs=Trigger.new[0];
   Case csold=Trigger.old[0];
  if (Trigger.isInsert)
  {
     List<cases__C> caslist=new list<cases__C>();
     Cases__c ci=new Cases__c();
     ci.Case_Number1__c=cs.CaseNumber;
     ci.Origin__c=cs.Origin;
     ci.Priority__c=cs.Priority;
     ci.Status__c=cs.Status;
     ci.Type__c=cs.Type;
     ci.Description__c=cs.Description;
     ci.Subject__c=cs.Subject;
     ci.Reason__c=cs.Reason;
     insert ci;
     //calist.add(ci);
  }
  if(Trigger.isUpdate)
  {
  
    list <Cases__c> caupdate=new list<Cases__c>();  
    caupdate=[select id,Case_Number1__c,Origin__c,Priority__c,Status__c,Type__c,Description__c,Subject__c,Reason__c from Cases__c where Case_Number1__c =: cs.CaseNumber];
     integer si=caupdate.size();
     system.debug('-------------------'+si);
    
     for(Cases__c cx: caupdate)
     {
         cx.Case_Number1__c=cs.CaseNumber;
         cx.Origin__c=cs.Origin;
         cx.Priority__c=cs.Priority;
         cx.Status__c=cs.Status;
         cx.Type__c=cs.Type;
         cx.Description__c=cs.Description;
         cx.Subject__c=cs.Subject;
         cx.Reason__c=cs.Reason;
         update cx;
     }
   }
    Case csold=Trigger.old[0];
   if(Trigger.isDelete )
   {
  
    Cases__c casdel =new Cases__c();
     casdel =[select id,Case_Number1__c from Cases__c  where  Case_Number1__c =: csold.CaseNumber ];--------> delete records coding.
     if(casdel != NULL )
     {
      delete casdel;
      }
   }
  
}
Hi,

Any one has involved in filenet to salesforce integration..... if so please share your ideas about the integration.
if any one helped would be greatly  appriciated.

trigger controlaAreaTalhaoAutomaticoBefore on Talhao__c (before insert, before update) {
    for(Talhao__c talhao:Trigger.new){
        if(talhao.Impede_Trigger_Area_Talhao_Automatico__c){
            Util.impedeTriggerAreaTalhaoAutomatico = true;
            talhao.Impede_Trigger_Area_Talhao_Automatico__c = false;
        }
        if(talhao.Area_do_Talhao__c == null || talhao.Area_do_Talhao__c < 0)
            talhao.addError('Área do Talhão: Inserir um valor positivo.');
    }
}