• wcwill978
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 17
    Questions
  • 30
    Replies
Hi, I have a class for a VF page that is used to attach files into a custom object off the account. I would like some help creating a test class for the class that would give a higher code coverage. Currently im only getting 6% code coverage. Below is what I have, thank you:

Class:
public class AttachController {
    
    public String name {get;set;}
    //public Boolean selectedAwesomeness {get;set;}
    public String description {get;set;}
    private Account account {get;set;} 
    public String salesAttachmentName {get;set;}
    public Blob fileBody {get;set;}
    
    public UploadAttachmentController(ApexPages.StandardController controller) { 
        this.account = (Account)controller.getRecord();
    }   
    
    // creates a new Sales_Attachments__c record
    private Database.SaveResult saveCustomAttachment() {
        Sales_Attachments__c obj = new Sales_Attachments__c();
        obj.Account__c = account.Id; 
        obj.Description__c = description;
        obj.Attachment_Name__c = name;
        return Database.insert(obj);
    }
    
    // create an actual Attachment record with the Sales_Attachments__c as parent
    private Database.SaveResult saveStandardAttachment(Id parentId) {
        Database.SaveResult result;
        
        Attachment attachment = new Attachment();
        attachment.body = this.fileBody;
        attachment.name = this.salesAttachmentName;
        attachment.parentId = parentId;
        result = Database.insert(attachment);
        fileBody = Blob.valueOf(' ');
        return result;
    }
    
    /**
    * Upload process is:
    *  1. Insert new Sales_Attachments__c record
    *  2. Insert new Attachment with the new Sales_Attachments__c record as parent
    *  3. Update the Sales_Attachments__c record with the ID of the new Attachment
    **/
    public PageReference processUpload() {
        try {
            Database.SaveResult customAttachmentResult = saveCustomAttachment();
        
            if (customAttachmentResult == null || !customAttachmentResult.isSuccess()) {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 
                  'Could not save attachment.'));
                return null;
            }
        
            Database.SaveResult attachmentResult = saveStandardAttachment(customAttachmentResult.getId());
        
            if (attachmentResult == null || !attachmentResult.isSuccess()) {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 
                  'Could not save attachment.'));            
                return null;
            } else {
                // update the custom attachment record with some attachment info
                Sales_Attachments__c customAttachment = [select id from Sales_Attachments__c where id = :customAttachmentResult.getId()];
                customAttachment.name = this.salesAttachmentName;
                customAttachment.Attachment_ID__c = attachmentResult.getId();
                update customAttachment;
            }
        
        } catch (Exception e) {
            ApexPages.AddMessages(e);
            return null;
        }
        
        return new PageReference('/'+account.Id);
    }
    
    public PageReference back() {
        return new PageReference('/'+account.Id);
    }     

}

VF Page:
<apex:page standardController="Account" tabStyle="Account" extensions="AttachController">

 <apex:sectionHeader title="{!Account.Name}" subtitle="Attach File"/>
 
 <apex:form id="form_Upload">
 <apex:pageBlock >

 <apex:pageBlockButtons >
   <apex:commandButton action="{!back}" value="Back"/>
   <apex:commandButton action="{!back}" value="Cancel"/>
 </apex:pageBlockButtons>
 <apex:pageMessages />
 
  <apex:pageBlockSection columns="1">
  
    <apex:pageBlockSectionItem >
      <apex:outputLabel value="Name" for="name"/> 
      <apex:inputTextarea id="name" value="{!name}" rows="1" cols="30"/>
    </apex:pageBlockSectionItem>
    
    <apex:pageBlockSectionItem >
      <apex:outputLabel value="File" for="file_File"/>
      <apex:inputFile id="file_File" value="{!fileBody}" filename="{!salesAttachmentName}"/>
    </apex:pageBlockSectionItem>
    
    <apex:pageBlockSectionItem >
      <apex:outputLabel value="Description" for="description"/> 
      <apex:inputTextarea id="description" value="{!description}" rows="4" cols="50"/>
    </apex:pageBlockSectionItem>
    
    <apex:pageBlockSectionItem >
      <apex:outputLabel value="" for="uploadBtn"/> 
      <apex:commandButton id="uploadBtn" value="Attach File" action="{!processUpload}" />
    </apex:pageBlockSectionItem>    
    
  </apex:pageBlockSection>
 
 </apex:pageBlock>


 </apex:form>

</apex:page>

Test Class:
@isTest
private class AttachTest {

    static testMethod void testUploadAttachmentController(){
    //Create test Sys Admin User to Run As
    Profile prof = [select id from profile where name='System Administrator'];

    User u1 = new User();
      u1.alias = 'alias3';
      u1.email ='testuser@email3.com';
      u1.emailencodingkey ='UTF-8';
      u1.lastname = 'userLast';
      u1.languagelocalekey ='en_US';  
      u1.localesidkey ='en_US';
      u1.profileid = prof.Id;
      u1.timezonesidkey ='America/Los_Angeles';
      u1.username ='testuser@email3.com';  

    insert u1;
    System.runAs(u1){  
    
        //Create Account
        List <Account> acctList = new List<Account>();
        acctList.add(new Account(Name='Acct1', Industry = 'Commercial'));
        acctList.add(new Account(Name='Acct2', Industry = 'Retail'));
        insert acctList;
        
        //New Sales_Attachments__c record where the actual SFDC child attachment will be added to.
        Sales_Attachments__c salesAttach = new Sales_Attachments__c();     
        salesAttach.Name = 'File1Test';
        salesAttach.Account__c = acctList[0].id;
        salesAttach.Description__c = '1234TEST';
        insert salesAttach;
        
        Sales_Attachments__c newSA = [SELECT ID, Name, Description__c FROM Sales_Attachments__c  WHERE ID = :salesAttach.ID];
        System.AssertEquals('1234TEST',newSA.Description__c);
            
       
        //Upload new attachment under the Sales_Attachments__c record
        Attachment attach = new Attachment();     
        attach.Name = 'Unit Test Attachment';
        Blob bodyBlob = Blob.valueOf('Unit Test Attachment Body');
        attach.body = bodyBlob;
        attach.ParentId = salesAttach.id;
        insert attach;
        
        salesAttach.Name = attach.Name;
        salesAttach.Attachment_ID__c = attach.Id;
        
        update salesAttach;
        
        Sales_Attachments__c testSA = [SELECT ID, Name FROM Sales_Attachments__c WHERE ID = :salesAttach.ID];
        System.AssertEquals('Unit Test Attachment',testSA.Name);
        
       
        List<Attachment> attachments=[select id, name from Attachment where parent.id=:salesAttach.id];
        System.assertEquals(1, attachments.size());
        
        ApexPages.StandardController sc = new ApexPages.StandardController(acctList[0]);
        UploadAttachmentController upload = new UploadAttachmentController(sc);
        
        PageReference pageRef = Page.UploadAttachment;
        pageRef.getParameters().put('id', String.valueOf(acctList[0].Id));
        Test.setCurrentPage(pageRef);
        
        System.assertEquals(attach.Name, attach.Name);
        
        }
    }
}



 

As of a couple of days ago some users began seeing the following error when attempting to refresh reports in Excel:

 

Unable to open https://na6-api.salesforce.com/&export=1xf=xls&enc=UTF-8. The Internet site reports that the item you requested could not be found. (HTTP/1.0 404)

 

They also mentioned that the spinning globe does not appear like it usually does. SFDC support reffred me to come here and post thsi isue to see if there's something going on with the tool.

 

Please help thank you!

Hi I am trying to write a trigger that will update all other open opportunities within the same account when one is closed. Right now we have workflow that sets the opportunity type based on some categories. If ten opportunities open for the same account they are automatically set to "Initial Purchase".

 

What I want to do is have a trigger run when one opportunity is closed won to update the other nine open opportunities to a different type. So the one that closes remains as Initial Purchase, but the other nine change to Existing Customer since they have already purchased from us.

 

Here is what I have so far, but when I close an opportunity as closed won it does not update the other open opportunities for the related account:

 

trigger updateOpportunityType on Opportunity (after update) 
{



// Build a map from the Opportunity ID's referenced in the Accounts for a reverse lookup later.
    Set<Id> OpptyIds = new Set<Id>();
    for (Opportunity opps: trigger.new) 
    if (opps.AccountId != null) 
    OpptyIds.add(opps.AccountId);
    
//Build a list of all open opportunities in the map.    
    List<Opportunity> opptys = new List<Opportunity>([select Id, Type FROM Opportunity 
                                WHERE Type = 'New Customer – Initial PurchaseId'
                                AND isClosed = false
                                AND Id in :OpptyIds]);
                                
//Build a list of the opportunity that is closing.
    List<Opportunity> closedoppty = new List<Opportunity>([select Id, Type FROM Opportunity 
                                WHERE Type = 'New Customer – Initial PurchaseId'
                                AND isClosed = true
                                AND StageName = 'Closed Won'
                                AND Id in :OpptyIds]);

    for (Opportunity openopps: opptys)
    {
        if(!closedoppty.isEmpty())
        {
            openopps.Type = 'New Customer – First 12 Months';
        }
    
    }
    
    update opptys;
    
}

 

Thanks.

Can anyone tell me if there is an easy way withipout having to use a visualforce page to bypass a validation rule on the account standdard object. I have an opportunity trigger that updates the Type field on an account. I also have a validation rule on that field that only allows users to select two values from the picklist. All the other values in the picklist are to be selected by the trigger. If the validtion rule is active then the trigger will not work because the trigger runs as the user and the validation rule kicks in before the trigger and does not allow the update. The only way i can get it to work is by deactivating the validation rule.

 

Is there a way that i can say on the validation rule to only fire when its a user and not via a trigger, or on the trigger can i say to bypass that validation rule?

 

Please help I have tried support and they suggested the visualforce page, but I do not want to use a custom page for a standard object just to do this.

 

Thank you.

I am trying to figure out what will be the best way to accomplish this task can anyone please suggest any good solutions:

 

I have a trigget that runs on opportunities and updates the "Type" field on Accts. When a new opportunity is opened the Type on the account is set to field engaged, if the deal is closed won then the account type goes to active, or if the deal is lost right now it goes to another value.

 

What I want to do is set the Type back to what it used to be before if the deal is closed lost. So if the acct was Inactive and a new deal is opened it automatically goes to Field Engaged, but if the account is closed lost I want it to go back to inactive. If the account was field engaged then go back to field engaged if the deal is lost? The problem is that as soon as the opportunity is opened the account is then set to field engaged, how can i store the old value so in the future if the account is lost i can set it back to that old value?

 

I though of having a hiden field that stores the value so then I can call that value or set the value of the visible field to that when the deal is closed lost?

 

Any ideas???

Hi I have a simple APEX class that updates accounts with old opportunities to inactive. The class is Schedulable and runs and works as it should. I am having a problem when I run the test class and trying to deploy it into Prod. The test class is failing with the following error message:

 

System.LimitException: jigsaw_clean:Too many script statements: 200001

 

Here is my class:

 

global class AcctInactiveUpdate implements Schedulable 
{
 global void execute(SchedulableContext sc) 
 {
 
 Map<id,account> aMap = new Map<id,account>([Select Id, Type, Last_Won_Opportunity__c, RecordTypeId FROM Account 
                                                    WHERE RecordTypeId != '012300000000Dk1'
                                                    AND Type = 'Active'
                                                    Limit 8000]);
                                                    

List<account> accList = aMap.values() ;
 
Set<id> accIds = aMap.keySet() ;


           for(Account acct: accList)  
           {
            //Get all Active Accounts where the last won deal was over 2yrs ago from above list
            if(acct.Last_Won_Opportunity__c < System.Today().addYears(-2)) 
             
              {
               acct.Type = 'Inactive'; 
               acct.Last_Set_to_Inactive__c = System.today(); 
              }
          }
          
          update accList;
   }
}


 

Here is the Test class I'm using which gives me 100% code coverage, but fails due to the governor limit:

 

@istest

class AcctInactiveUpdateTestClass {

public static testMethod void testschedule() {

        Test.StartTest();
            AcctInactiveUpdate sh = new AcctInactiveUpdate();
                String sch = '0 0 5 * * ?';
                system.schedule('Schedule TEST', sch, sh);
        Test.stopTest();
       
        }
    }

 

Can someone please help me what can I do to not hit the script statement limit? I added a limit of 8K accounts on the class to see if that helps and still no avail.

Hi,

 

I have been staring at this trigger trying to figure out how to include some logic that allows it to only create one record per opportunity. The trigger runs when a deal is closed won and has service. Basically what the trigger does is create an ESU record on the account, what we've been seeing is that sometimes when the trigger is fired it creates two records per opportunities. I need to somehow add some logic into the trigger to allow only one record per opportunity.

 

I read somewhere that I should do a "map" to pull the oppty ID into it and check t see if the record exists if not create a new one if it does then update it. So each opppty will have only one ESU tied to it. The ESU record has a relationship to the oppty.  The trigger is below as a comment (exceeeded character limite!)

 

Can someone help me with this please or show me how would I go about adding this into the existing trigger.

 

Thank you

 

I have about 10 fields on the opportunity page that are populated from a quote when a quote is set to primary. Anyways these are cureny fields for all our product classes. Everytime a part is purchased under that class the field is populated with the total value of product.

 

On the account screen I have a multi-picklist field (Products_Purchased__c) with the list of all products. I want to populate this picklist field everytime an opportunity is closed won and a value is entered on one of these fields. For example if I close an opportunity and there was $500 on the A-Series field on the opportunity I want A-Series to show on the Products_Purchased__c field on the account. 

 

So far I have this on the trigger:

 

trigger martCalcOpptyUpdateETSPurchasedonAcct on Opportunity (after insert, after update) {
List<Account> accsToUpdate = new List<Account>();

for(Opportunity opp : trigger.new)
{
    if (opp.StageName == 'Closed Won' && opp.A_Series__c > 0)
    accsToUpdate.add(new Account(Id = opp.Account.Id, ETS_Products_Purchased__c = 'A-Series'));
}
{
    if (opp.StageName == 'Closed Won' && opp.B_Series__c > 0)
    accsToUpdate.add(new Account(Id = opp.Account.Id, Products_Purchased__c = 'B-Series'));
}

if (accsToUpdate != null && !accsToUpdate.isEmpty())
Database.update(accsToUpdate);

}

 

Is there a way to colapse all the series and tell it to update the Products_Purchased field based on the field that has a value. An account can have multiple opportunities so we just want to show one value at a time so if we have 3 closed won opportunties all with A-Series purchased on the account screen i want to show only one A-Series, i think this will be taken care of by the multi-picklist.

 

Can some one help me expand this trigger to do what i'm looking for? Thank you.

Hi I am trying to create a trigger that will update a field on the opprtunity when an avtivity is logged on an opportunity.

 

The reason for this is that I want to send out email alerts when an opportunity is inactive or no activity has been done for a period of time. The users usually leave the stage unchanged for a month or two but if they are working on the opportunity they log calls or other activities on the Activity History related list. We want to notify the users if nothing has been logged or the stage has not changed in 2 months and let them know with an email alert that this opportunity is "inactive"

 

I was thinking of updating a hidden field on the opportunity everytime an activity is recorded then run workflow from that field that will count 2 moths after the last update if nothing has changed then send the email alert? Is this possible the way I'm thinking of doing it? Any help will be appreciated.

 

Thank you.

I'm trying to put together a work flow that will send an email alert to a specific user when an opportunity in his region has been inactive for 2 months. The user wants to keep track of opportunites that are "inactive" what this means if the opportunity stage or an activity has not been recorded within two months we wnat it to send an email alert to him.

 

What will be the best way of doing this for individual opportunities. I was thinking of a workflow, but the activity is a related object on the opportunity, so how will I put that into the workflow. Basically i want the workflow to fire if the stage has not changed in two months or if an activity has not been logged. If one or the other has changed or modified then the workflow will not fire.

 

Any help/suggestions will be appreciated.

 

Thank you

Hi,

 

I've been trying to create a validation rule to prevent users from creating new opportunities as closed won based on another field. basically I have another field and if they eneter a value in this field I want them to get an error if they try to save it as closed won when the opportunity is new.

 

I tried using create date = NOW and create date = last modified date that does not work. This is the latest version i have:

 

AND(
IsClosed = TRUE,
IsWon = TRUE,
NOT (ISBLANK(Professional_Services__c)),
CreatedDate = NOW()

)

 

And here is another version I tried:

 

AND(
ISPICKVAL(StageName,"Closed Won"),
(NOT(ISNULL(Professional_Services__c))),
 CreatedDate = NOW()

)

 

Any help will be appreciated, just want to prevent them from creating new opptys as closed.

 

Thank you.

Can someone please help me with a validation rule that does not allow an opportunity to be marked closed lost unless its the Account owner closing it. We want to only allow the account owner to be able to close the opportunity if its lost. So far I have:

 

AND (
ISPICKVAL(StageName, "Closed Lost" ),

)

 

Now I dont know what to use to validate that the user closing it is the account owner, if its not the account owner than an error can be displayed: "only account owner can close this deal as lost"

 

Thanks in advanced.

Hi I have a trigger that creates a custom object when an opportunity stage is set to "closed lost" and saved. I created a test class to deploy into prod, but can only get 64%coverage. Can someone help me increase my test coverage or guide me in the right dirrection so I can get as close to 100% Also when I run the test I get one Test Failure: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [CloseDate]: [CloseDate]

 

Below is my test Class:

 

@isTest
private class MyTestWLATrigger
{
    static testmethod void TestMethod1()
    {
        //Fill all mandatory properties of opportunity and don't miss stage name
        Opportunity opp = new Opportunity() ;
        opp.Name = 'Test Oppty' ;
        opp.stageName = '4: Generate Offer' ;
        opp.WonLostReason1__c = '' ;
        //Now insert the opportunity
        insert opp ;
        
        //To let your trigger code covered in write this
        opp.stageName = 'Closed Lost' ;
        //change the stage name
        opp.WonLostReason1__c = 'Price' ;
        //Now update the opportunity
        update opp ;
        System.assertEquals(opp.Name, opp.stageName, opp.WonLostReason1__c);
        
    }
}

And below is my trigger:

 

trigger AutoCreateWinLossAnalysisOnOpportunity on Opportunity (after update) 
{

  List<Opportunity> closedOps = new List<Opportunity>();
  List<Win_Loss_Analysis__c> newwinLossObjects = new List<Win_Loss_Analysis__c>();  
  List<Win_Loss_Analysis__c> updatewinLossObjects = new List<Win_Loss_Analysis__c>();
  
  List<RecordType> recordTypesForOppty = new List<RecordType>();
  recordTypesForOppty = [Select Name, ID From RecordType where SobjectType = 'Win_Loss_Analysis__c'];
  System.debug('recordTypesForOppty'+recordTypesForOppty);
  
    List<Id> ExistingIds = new List<Id>();
    
     
    Integer  count = Trigger.new.size(); 
    for(Opportunity newvalue : Trigger.new)
    {
      Opportunity oldvalue = Trigger.oldMap.get(newvalue.Id);
        if(oldvalue.StageName != newvalue.StageName || oldvalue.WonLostReason1__c != newvalue.WonLostReason1__c)  
       {
           if(newvalue.StageName == 'Closed Lost'){
            if(newvalue.WonLostReason1__c == 'Price' 
              || newvalue.WonLostReason1__c == 'Product Feature/Functionality' 
              || newvalue.WonLostReason1__c =='Relationship')
            {
            System.debug('newvalue'+newvalue);
               closedOps.add(newvalue);
                 ExistingIds.add(newvalue.Id);
       
            }
          }
       }
    }
    system.debug('Found : ' + closedOps.size() + ' Opps that need analysis records created');
    if (closedOps.size() > 0)  
    { 
      List<Win_Loss_Analysis__c> existing = [SELECT Id,Opportunity_Name__c FROM Win_Loss_Analysis__c WHERE  Opportunity_Name__c  in :ExistingIds];
      system.debug('Found : ' + existing.size() + ' Existing Win Loss Records');
      string LossAnalysis = null;
      for (Opportunity oppty : closedOps)
      {       
              // get the recordTypeId
              Id WinLossObjectRecordTypeId = null;
              string typeName;
              LossAnalysis = oppty.WonLostReason1__c.toLowerCase();
              System.debug('******LossAnalysis *******'+LossAnalysis);
          for (RecordType recordType : recordTypesForOppty)
          {
          
          System.debug('recordType'+recordType);
            typeName = recordType.Name.toLowerCase();
            
            System.debug('recordType.Name.toLowerCase()>>>>>>>'+recordType.Name.toLowerCase());
              System.debug('******typeName *******'+typeName );
            if (LossAnalysis == 'price' && typeName == 'price (lost)') 
            {
            
            System.debug('ist if>>>>>>');
              WinLossObjectRecordTypeId = recordType.Id;
            }
            if (LossAnalysis == 'product feature/functionality' && typeName == 'productfeature (lost)') 
            {
             System.debug('2nd if>>>>>>');
              WinLossObjectRecordTypeId = recordType.Id;
            }
            if (LossAnalysis == 'relationship' && typeName == 'relationship (lost)') 
            {
             System.debug('3rd if>>>>>>');
              WinLossObjectRecordTypeId = recordType.Id;
            }
          }
          system.debug('Record type id: ' + WinLossObjectRecordTypeId + ' found for oppt id' + WinLossObjectRecordTypeId );
              // construct the new custom object with the required fields set
              
              Win_Loss_Analysis__c wL = new Win_Loss_Analysis__c();
              System.debug('oppty.Id>>>>>>>'+oppty.Id);
              wL.Opportunity_Name__c = oppty.Id;
              wL.RecordTypeId = WinLossObjectRecordTypeId;
              System.debug('*************Checking RecordTypeId***********'+WinLossObjectRecordTypeId);
              System.debug('WinLossObjectRecordTypeId>>>>>>>'+WinLossObjectRecordTypeId);
              wL.Account_Name__c = oppty.AccountId;
               System.debug('oppty.AccountId>>>>>>>'+oppty.AccountId);
              if(existing.size() > 0)
              {
                   for(Win_Loss_Analysis__c exist : existing)
                {
                  if(exist.Opportunity_Name__c == oppty.Id)
                  {
                    wL.Id = exist.Id;
                    break;  
                  }              
                }
              }
              
              if(wL.Id == null)
              {
                newwinLossObjects.add(wL);
              }
              else
              {
                updatewinLossObjects.add(wL);
              }
              
      }
    }
    system.debug('Inserting ' + newwinLossObjects.size() + ' new Win Loss Objects' );
    system.debug('Updating ' + updatewinLossObjects.size() + '  Win Loss Objects' );
    if(newwinLossObjects.size() > 0)
         insert newwinLossObjects;
   
    if(updatewinLossObjects.size() > 0)
         update updatewinLossObjects;

}

Hi I have a trigger to create a win loss analysis when the opportunity stage is set to closed lost and the win loss reason field is set to one of the three values (price, product feature, relationship). When I try to save the trigger I get the following error "Compile Error: Field is not writeable: Win_Loss_Analysis__c.Id at line 72 column 21" I want to create the opportunity, but is a win loss analysis record already exists and if the reason is changed I want the object to be updated with the new value rather than create a new win loss analysis. Can some one help me figure this error out so I can get this running please:

 

trigger AutoCreateWinLossAnalysisOnOpportunity on Opportunity (after update)
{

  List<Opportunity> closedOps = new List<Opportunity>();
  List<Win_Loss_Analysis__c> newwinLossObjects = new List<Win_Loss_Analysis__c>();  
  List<Win_Loss_Analysis__c> updatewinLossObjects = new List<Win_Loss_Analysis__c>();
 
  List<RecordType> recordTypesForOppty = new List<RecordType>();
  recordTypesForOppty = [Select Name, ID From RecordType where SobjectType = 'Win_Loss_Analysis__c'];
    List<Id> ExistingIds = new List<Id>();
    
     
    Integer  count = Trigger.new.size();
    for(Opportunity newvalue : Trigger.new)
    {
      Opportunity oldvalue = Trigger.oldMap.get(newvalue.Id);
        if(oldvalue.StageName != newvalue.StageName || oldvalue.Loss_Analysis__c != newvalue.Loss_Analysis__c)  
       {
           if(newvalue.StageName == 'Closed Lost'){
            if(newvalue.Loss_Analysis__c == 'Price'
              || newvalue.Loss_Analysis__c == 'Product Feature/Functionality'
              || newvalue.Loss_Analysis__c =='Relationship')
            {
               closedOps.add(newvalue);
                 ExistingIds.add(newvalue.Id);
       
            }
          }
       }
    }
    system.debug('Found : ' + closedOps.size() + ' Opps that need analysis records created');
    if (closedOps.size() > 0)  
    {
      List<Win_Loss_Analysis__c> existing = [SELECT Id,Opportunity_Name__c FROM Win_Loss_Analysis__c WHERE  Opportunity_Name__c  in :ExistingIds];
      system.debug('Found : ' + existing.size() + ' Existing Win Loss Records');
      string LossAnalysis = null;
      for (Opportunity oppty : closedOps)
      {       
              // get the recordTypeId
              Id WinLossObjectRecordTypeId = null;
              string typeName;
              LossAnalysis = oppty.Loss_Analysis__c.toLowerCase();
          for (RecordType recordType : recordTypesForOppty)
          {
            typeName = recordType.Name.toLowerCase();
            if (LossAnalysis == 'price' && typeName == 'price')
            {
              WinLossObjectRecordTypeId = recordType.Id;
            }
            if (LossAnalysis == 'product feature/functionality' && typeName == 'productfeature')
            {
              WinLossObjectRecordTypeId = recordType.Id;
            }
            if (LossAnalysis == 'relationship' && typeName == 'relationship')
            {
              WinLossObjectRecordTypeId = recordType.Id;
            }
          }
          system.debug('Record type id: ' + WinLossObjectRecordTypeId + ' found for oppt id' + WinLossObjectRecordTypeId );
              // construct the new custom object with the required fields set
              
              Win_Loss_Analysis__c wL = new Win_Loss_Analysis__c();
              wL.Opportunity_Name__c = oppty.Id;
              wL.RecordTypeId = WinLossObjectRecordTypeId;
              wL.Account_Name__c = oppty.AccountId;
              if(existing.size() > 0)
              {
                   for(Win_Loss_Analysis__c exist : existing)
                {
                  if(exist.Opportunity_Name__c == oppty.Id)
                  {

              //the line below is line 72 this is where the error is generating from

                    wL.Id = exist.Id;
                    break;  
                  }              
                }
              }
              
              if(wL.Id == null)
              {
                newwinLossObjects.add(wL);
              }
              else
              {
                updatewinLossObjects.add(wL);
              }
              
      }
    }
    system.debug('Inserting ' + newwinLossObjects.size() + ' new Win Loss Objects' );
    system.debug('Updating ' + updatewinLossObjects.size() + '  Win Loss Objects' );
    if(newwinLossObjects.size() > 0)
         insert newwinLossObjects;
   
    if(updatewinLossObjects.size() > 0)
         update updatewinLossObjects;

}

Hi I created my first trigger and need help creating a test class (never created one before and dont know how to get started) to get into prod. can someone help me please I tired attaching the trigger, but it gives me anerror saying I exceeded the character limit.

 

Is there a way someone can send me an email please or is there an alternate way for me to post the trigger.

 

 

Hi I am trying to create a trigger that will auto create a new custom object when the SatgeName field is set to Closed Lost. So far I have created the custom object and the API name is "Win_Loss_Analysis__c". When the upportunity satge is saved I want the trigger to create a new object so we can later have workflow rules that will email the user to update and complete so we can keep track of why we lost that opportunity. So far this is what I have for the trigger:

 

trigger AutoCreateWinLossAnalysis on Opportunity (after update, after insert) {
Map<ID,Win_Loss_Analysis__c> mapRec = new Map<ID,Win_Loss_Analysis__c>();
    for(RecordType r: [Select r.Name, r.ID From RecordType where r.SobjectType = "Win_Loss_Analysis__c"]){
        mapRec.put(r.Name,r.ID)
    }
    List<Win_Loss_Analysis__c> lstWinLoss = new List<Win_Loss_Analysis__c>();
    for(Opportunity Loan:Trigger.New){
        if(StageName =='Closed Lost'){
            Win_Loss_Analysis__c wl = new Win_Loss_Analysis__c();
            if(mapRec.containsKey(opp.Loss_Analysis__c)){
                wl.o.RecordTypeId = mapRec.get(opp.Loss_Analysis__c)
            }
            
            lstWinLoss.add(wl);
        }
        
    }
    if(lstWinLoss.size()>0)
        insert lstWinLoss;
}

 

When I save I get the following error: Error: Compile Error: line 3:81 no viable alternative at character '"' at line 3 column 81.I have record types in the custom object that have page layouts assigned to them so when the opportunity is closed there is another required dependent field called Loss Analysis with values such as Price, Relationship, Product Feature, etc. After the opportunity is saved I would like it to triger the new custom object to create and if price was selected on the Loss Analysis field to show the page layout attached to that record type.

 

Thanks in advanced...

Hi I created a custom object called Win_Loss_Analysis__c within the opportunity and am trying to create a trigger that will automatically create a new analysis after the Opportunity is Stage is set to closedwon. The Field name of the stage field is: StageName.

 

Can someone please guide me in the right direction on how will this appex trigger look or how to get it started I really apreciate it, I'm new to Apex and am trying to learn. The object Win_Loss_Analysis__c has multiple page layouts and record types so basically when a user sets the opportunity stage to close lost we have a required dependent field called Loss Analysis with three values (Price, Product feature, relationship) based on the value they choose we have pagelayouts tied to record types that determine which values will show.

 

I just want the Win_Loss_Analysis__c to automatically create when these fields are updated based on the choices the user picked and then we will have workflow tied to the Win_Loss_Analysis__c to send an email to the opportunity owner reminding them to complete the Win_Loss_Analysis__c.

 

Any help will be appreciated, thank you

Hi, I have a class for a VF page that is used to attach files into a custom object off the account. I would like some help creating a test class for the class that would give a higher code coverage. Currently im only getting 6% code coverage. Below is what I have, thank you:

Class:
public class AttachController {
    
    public String name {get;set;}
    //public Boolean selectedAwesomeness {get;set;}
    public String description {get;set;}
    private Account account {get;set;} 
    public String salesAttachmentName {get;set;}
    public Blob fileBody {get;set;}
    
    public UploadAttachmentController(ApexPages.StandardController controller) { 
        this.account = (Account)controller.getRecord();
    }   
    
    // creates a new Sales_Attachments__c record
    private Database.SaveResult saveCustomAttachment() {
        Sales_Attachments__c obj = new Sales_Attachments__c();
        obj.Account__c = account.Id; 
        obj.Description__c = description;
        obj.Attachment_Name__c = name;
        return Database.insert(obj);
    }
    
    // create an actual Attachment record with the Sales_Attachments__c as parent
    private Database.SaveResult saveStandardAttachment(Id parentId) {
        Database.SaveResult result;
        
        Attachment attachment = new Attachment();
        attachment.body = this.fileBody;
        attachment.name = this.salesAttachmentName;
        attachment.parentId = parentId;
        result = Database.insert(attachment);
        fileBody = Blob.valueOf(' ');
        return result;
    }
    
    /**
    * Upload process is:
    *  1. Insert new Sales_Attachments__c record
    *  2. Insert new Attachment with the new Sales_Attachments__c record as parent
    *  3. Update the Sales_Attachments__c record with the ID of the new Attachment
    **/
    public PageReference processUpload() {
        try {
            Database.SaveResult customAttachmentResult = saveCustomAttachment();
        
            if (customAttachmentResult == null || !customAttachmentResult.isSuccess()) {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 
                  'Could not save attachment.'));
                return null;
            }
        
            Database.SaveResult attachmentResult = saveStandardAttachment(customAttachmentResult.getId());
        
            if (attachmentResult == null || !attachmentResult.isSuccess()) {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 
                  'Could not save attachment.'));            
                return null;
            } else {
                // update the custom attachment record with some attachment info
                Sales_Attachments__c customAttachment = [select id from Sales_Attachments__c where id = :customAttachmentResult.getId()];
                customAttachment.name = this.salesAttachmentName;
                customAttachment.Attachment_ID__c = attachmentResult.getId();
                update customAttachment;
            }
        
        } catch (Exception e) {
            ApexPages.AddMessages(e);
            return null;
        }
        
        return new PageReference('/'+account.Id);
    }
    
    public PageReference back() {
        return new PageReference('/'+account.Id);
    }     

}

VF Page:
<apex:page standardController="Account" tabStyle="Account" extensions="AttachController">

 <apex:sectionHeader title="{!Account.Name}" subtitle="Attach File"/>
 
 <apex:form id="form_Upload">
 <apex:pageBlock >

 <apex:pageBlockButtons >
   <apex:commandButton action="{!back}" value="Back"/>
   <apex:commandButton action="{!back}" value="Cancel"/>
 </apex:pageBlockButtons>
 <apex:pageMessages />
 
  <apex:pageBlockSection columns="1">
  
    <apex:pageBlockSectionItem >
      <apex:outputLabel value="Name" for="name"/> 
      <apex:inputTextarea id="name" value="{!name}" rows="1" cols="30"/>
    </apex:pageBlockSectionItem>
    
    <apex:pageBlockSectionItem >
      <apex:outputLabel value="File" for="file_File"/>
      <apex:inputFile id="file_File" value="{!fileBody}" filename="{!salesAttachmentName}"/>
    </apex:pageBlockSectionItem>
    
    <apex:pageBlockSectionItem >
      <apex:outputLabel value="Description" for="description"/> 
      <apex:inputTextarea id="description" value="{!description}" rows="4" cols="50"/>
    </apex:pageBlockSectionItem>
    
    <apex:pageBlockSectionItem >
      <apex:outputLabel value="" for="uploadBtn"/> 
      <apex:commandButton id="uploadBtn" value="Attach File" action="{!processUpload}" />
    </apex:pageBlockSectionItem>    
    
  </apex:pageBlockSection>
 
 </apex:pageBlock>


 </apex:form>

</apex:page>

Test Class:
@isTest
private class AttachTest {

    static testMethod void testUploadAttachmentController(){
    //Create test Sys Admin User to Run As
    Profile prof = [select id from profile where name='System Administrator'];

    User u1 = new User();
      u1.alias = 'alias3';
      u1.email ='testuser@email3.com';
      u1.emailencodingkey ='UTF-8';
      u1.lastname = 'userLast';
      u1.languagelocalekey ='en_US';  
      u1.localesidkey ='en_US';
      u1.profileid = prof.Id;
      u1.timezonesidkey ='America/Los_Angeles';
      u1.username ='testuser@email3.com';  

    insert u1;
    System.runAs(u1){  
    
        //Create Account
        List <Account> acctList = new List<Account>();
        acctList.add(new Account(Name='Acct1', Industry = 'Commercial'));
        acctList.add(new Account(Name='Acct2', Industry = 'Retail'));
        insert acctList;
        
        //New Sales_Attachments__c record where the actual SFDC child attachment will be added to.
        Sales_Attachments__c salesAttach = new Sales_Attachments__c();     
        salesAttach.Name = 'File1Test';
        salesAttach.Account__c = acctList[0].id;
        salesAttach.Description__c = '1234TEST';
        insert salesAttach;
        
        Sales_Attachments__c newSA = [SELECT ID, Name, Description__c FROM Sales_Attachments__c  WHERE ID = :salesAttach.ID];
        System.AssertEquals('1234TEST',newSA.Description__c);
            
       
        //Upload new attachment under the Sales_Attachments__c record
        Attachment attach = new Attachment();     
        attach.Name = 'Unit Test Attachment';
        Blob bodyBlob = Blob.valueOf('Unit Test Attachment Body');
        attach.body = bodyBlob;
        attach.ParentId = salesAttach.id;
        insert attach;
        
        salesAttach.Name = attach.Name;
        salesAttach.Attachment_ID__c = attach.Id;
        
        update salesAttach;
        
        Sales_Attachments__c testSA = [SELECT ID, Name FROM Sales_Attachments__c WHERE ID = :salesAttach.ID];
        System.AssertEquals('Unit Test Attachment',testSA.Name);
        
       
        List<Attachment> attachments=[select id, name from Attachment where parent.id=:salesAttach.id];
        System.assertEquals(1, attachments.size());
        
        ApexPages.StandardController sc = new ApexPages.StandardController(acctList[0]);
        UploadAttachmentController upload = new UploadAttachmentController(sc);
        
        PageReference pageRef = Page.UploadAttachment;
        pageRef.getParameters().put('id', String.valueOf(acctList[0].Id));
        Test.setCurrentPage(pageRef);
        
        System.assertEquals(attach.Name, attach.Name);
        
        }
    }
}



 

As of a couple of days ago some users began seeing the following error when attempting to refresh reports in Excel:

 

Unable to open https://na6-api.salesforce.com/&export=1xf=xls&enc=UTF-8. The Internet site reports that the item you requested could not be found. (HTTP/1.0 404)

 

They also mentioned that the spinning globe does not appear like it usually does. SFDC support reffred me to come here and post thsi isue to see if there's something going on with the tool.

 

Please help thank you!

Hi I am trying to write a trigger that will update all other open opportunities within the same account when one is closed. Right now we have workflow that sets the opportunity type based on some categories. If ten opportunities open for the same account they are automatically set to "Initial Purchase".

 

What I want to do is have a trigger run when one opportunity is closed won to update the other nine open opportunities to a different type. So the one that closes remains as Initial Purchase, but the other nine change to Existing Customer since they have already purchased from us.

 

Here is what I have so far, but when I close an opportunity as closed won it does not update the other open opportunities for the related account:

 

trigger updateOpportunityType on Opportunity (after update) 
{



// Build a map from the Opportunity ID's referenced in the Accounts for a reverse lookup later.
    Set<Id> OpptyIds = new Set<Id>();
    for (Opportunity opps: trigger.new) 
    if (opps.AccountId != null) 
    OpptyIds.add(opps.AccountId);
    
//Build a list of all open opportunities in the map.    
    List<Opportunity> opptys = new List<Opportunity>([select Id, Type FROM Opportunity 
                                WHERE Type = 'New Customer – Initial PurchaseId'
                                AND isClosed = false
                                AND Id in :OpptyIds]);
                                
//Build a list of the opportunity that is closing.
    List<Opportunity> closedoppty = new List<Opportunity>([select Id, Type FROM Opportunity 
                                WHERE Type = 'New Customer – Initial PurchaseId'
                                AND isClosed = true
                                AND StageName = 'Closed Won'
                                AND Id in :OpptyIds]);

    for (Opportunity openopps: opptys)
    {
        if(!closedoppty.isEmpty())
        {
            openopps.Type = 'New Customer – First 12 Months';
        }
    
    }
    
    update opptys;
    
}

 

Thanks.

Can anyone tell me if there is an easy way withipout having to use a visualforce page to bypass a validation rule on the account standdard object. I have an opportunity trigger that updates the Type field on an account. I also have a validation rule on that field that only allows users to select two values from the picklist. All the other values in the picklist are to be selected by the trigger. If the validtion rule is active then the trigger will not work because the trigger runs as the user and the validation rule kicks in before the trigger and does not allow the update. The only way i can get it to work is by deactivating the validation rule.

 

Is there a way that i can say on the validation rule to only fire when its a user and not via a trigger, or on the trigger can i say to bypass that validation rule?

 

Please help I have tried support and they suggested the visualforce page, but I do not want to use a custom page for a standard object just to do this.

 

Thank you.

I am trying to figure out what will be the best way to accomplish this task can anyone please suggest any good solutions:

 

I have a trigget that runs on opportunities and updates the "Type" field on Accts. When a new opportunity is opened the Type on the account is set to field engaged, if the deal is closed won then the account type goes to active, or if the deal is lost right now it goes to another value.

 

What I want to do is set the Type back to what it used to be before if the deal is closed lost. So if the acct was Inactive and a new deal is opened it automatically goes to Field Engaged, but if the account is closed lost I want it to go back to inactive. If the account was field engaged then go back to field engaged if the deal is lost? The problem is that as soon as the opportunity is opened the account is then set to field engaged, how can i store the old value so in the future if the account is lost i can set it back to that old value?

 

I though of having a hiden field that stores the value so then I can call that value or set the value of the visible field to that when the deal is closed lost?

 

Any ideas???

Hi I have a simple APEX class that updates accounts with old opportunities to inactive. The class is Schedulable and runs and works as it should. I am having a problem when I run the test class and trying to deploy it into Prod. The test class is failing with the following error message:

 

System.LimitException: jigsaw_clean:Too many script statements: 200001

 

Here is my class:

 

global class AcctInactiveUpdate implements Schedulable 
{
 global void execute(SchedulableContext sc) 
 {
 
 Map<id,account> aMap = new Map<id,account>([Select Id, Type, Last_Won_Opportunity__c, RecordTypeId FROM Account 
                                                    WHERE RecordTypeId != '012300000000Dk1'
                                                    AND Type = 'Active'
                                                    Limit 8000]);
                                                    

List<account> accList = aMap.values() ;
 
Set<id> accIds = aMap.keySet() ;


           for(Account acct: accList)  
           {
            //Get all Active Accounts where the last won deal was over 2yrs ago from above list
            if(acct.Last_Won_Opportunity__c < System.Today().addYears(-2)) 
             
              {
               acct.Type = 'Inactive'; 
               acct.Last_Set_to_Inactive__c = System.today(); 
              }
          }
          
          update accList;
   }
}


 

Here is the Test class I'm using which gives me 100% code coverage, but fails due to the governor limit:

 

@istest

class AcctInactiveUpdateTestClass {

public static testMethod void testschedule() {

        Test.StartTest();
            AcctInactiveUpdate sh = new AcctInactiveUpdate();
                String sch = '0 0 5 * * ?';
                system.schedule('Schedule TEST', sch, sh);
        Test.stopTest();
       
        }
    }

 

Can someone please help me what can I do to not hit the script statement limit? I added a limit of 8K accounts on the class to see if that helps and still no avail.

Hi,

 

I have been staring at this trigger trying to figure out how to include some logic that allows it to only create one record per opportunity. The trigger runs when a deal is closed won and has service. Basically what the trigger does is create an ESU record on the account, what we've been seeing is that sometimes when the trigger is fired it creates two records per opportunities. I need to somehow add some logic into the trigger to allow only one record per opportunity.

 

I read somewhere that I should do a "map" to pull the oppty ID into it and check t see if the record exists if not create a new one if it does then update it. So each opppty will have only one ESU tied to it. The ESU record has a relationship to the oppty.  The trigger is below as a comment (exceeeded character limite!)

 

Can someone help me with this please or show me how would I go about adding this into the existing trigger.

 

Thank you

 

Hi I am trying to create a trigger that will update a field on the opprtunity when an avtivity is logged on an opportunity.

 

The reason for this is that I want to send out email alerts when an opportunity is inactive or no activity has been done for a period of time. The users usually leave the stage unchanged for a month or two but if they are working on the opportunity they log calls or other activities on the Activity History related list. We want to notify the users if nothing has been logged or the stage has not changed in 2 months and let them know with an email alert that this opportunity is "inactive"

 

I was thinking of updating a hidden field on the opportunity everytime an activity is recorded then run workflow from that field that will count 2 moths after the last update if nothing has changed then send the email alert? Is this possible the way I'm thinking of doing it? Any help will be appreciated.

 

Thank you.

Hi,

 

I've been trying to create a validation rule to prevent users from creating new opportunities as closed won based on another field. basically I have another field and if they eneter a value in this field I want them to get an error if they try to save it as closed won when the opportunity is new.

 

I tried using create date = NOW and create date = last modified date that does not work. This is the latest version i have:

 

AND(
IsClosed = TRUE,
IsWon = TRUE,
NOT (ISBLANK(Professional_Services__c)),
CreatedDate = NOW()

)

 

And here is another version I tried:

 

AND(
ISPICKVAL(StageName,"Closed Won"),
(NOT(ISNULL(Professional_Services__c))),
 CreatedDate = NOW()

)

 

Any help will be appreciated, just want to prevent them from creating new opptys as closed.

 

Thank you.

Can someone please help me with a validation rule that does not allow an opportunity to be marked closed lost unless its the Account owner closing it. We want to only allow the account owner to be able to close the opportunity if its lost. So far I have:

 

AND (
ISPICKVAL(StageName, "Closed Lost" ),

)

 

Now I dont know what to use to validate that the user closing it is the account owner, if its not the account owner than an error can be displayed: "only account owner can close this deal as lost"

 

Thanks in advanced.

Hi I have a trigger that creates a custom object when an opportunity stage is set to "closed lost" and saved. I created a test class to deploy into prod, but can only get 64%coverage. Can someone help me increase my test coverage or guide me in the right dirrection so I can get as close to 100% Also when I run the test I get one Test Failure: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [CloseDate]: [CloseDate]

 

Below is my test Class:

 

@isTest
private class MyTestWLATrigger
{
    static testmethod void TestMethod1()
    {
        //Fill all mandatory properties of opportunity and don't miss stage name
        Opportunity opp = new Opportunity() ;
        opp.Name = 'Test Oppty' ;
        opp.stageName = '4: Generate Offer' ;
        opp.WonLostReason1__c = '' ;
        //Now insert the opportunity
        insert opp ;
        
        //To let your trigger code covered in write this
        opp.stageName = 'Closed Lost' ;
        //change the stage name
        opp.WonLostReason1__c = 'Price' ;
        //Now update the opportunity
        update opp ;
        System.assertEquals(opp.Name, opp.stageName, opp.WonLostReason1__c);
        
    }
}

And below is my trigger:

 

trigger AutoCreateWinLossAnalysisOnOpportunity on Opportunity (after update) 
{

  List<Opportunity> closedOps = new List<Opportunity>();
  List<Win_Loss_Analysis__c> newwinLossObjects = new List<Win_Loss_Analysis__c>();  
  List<Win_Loss_Analysis__c> updatewinLossObjects = new List<Win_Loss_Analysis__c>();
  
  List<RecordType> recordTypesForOppty = new List<RecordType>();
  recordTypesForOppty = [Select Name, ID From RecordType where SobjectType = 'Win_Loss_Analysis__c'];
  System.debug('recordTypesForOppty'+recordTypesForOppty);
  
    List<Id> ExistingIds = new List<Id>();
    
     
    Integer  count = Trigger.new.size(); 
    for(Opportunity newvalue : Trigger.new)
    {
      Opportunity oldvalue = Trigger.oldMap.get(newvalue.Id);
        if(oldvalue.StageName != newvalue.StageName || oldvalue.WonLostReason1__c != newvalue.WonLostReason1__c)  
       {
           if(newvalue.StageName == 'Closed Lost'){
            if(newvalue.WonLostReason1__c == 'Price' 
              || newvalue.WonLostReason1__c == 'Product Feature/Functionality' 
              || newvalue.WonLostReason1__c =='Relationship')
            {
            System.debug('newvalue'+newvalue);
               closedOps.add(newvalue);
                 ExistingIds.add(newvalue.Id);
       
            }
          }
       }
    }
    system.debug('Found : ' + closedOps.size() + ' Opps that need analysis records created');
    if (closedOps.size() > 0)  
    { 
      List<Win_Loss_Analysis__c> existing = [SELECT Id,Opportunity_Name__c FROM Win_Loss_Analysis__c WHERE  Opportunity_Name__c  in :ExistingIds];
      system.debug('Found : ' + existing.size() + ' Existing Win Loss Records');
      string LossAnalysis = null;
      for (Opportunity oppty : closedOps)
      {       
              // get the recordTypeId
              Id WinLossObjectRecordTypeId = null;
              string typeName;
              LossAnalysis = oppty.WonLostReason1__c.toLowerCase();
              System.debug('******LossAnalysis *******'+LossAnalysis);
          for (RecordType recordType : recordTypesForOppty)
          {
          
          System.debug('recordType'+recordType);
            typeName = recordType.Name.toLowerCase();
            
            System.debug('recordType.Name.toLowerCase()>>>>>>>'+recordType.Name.toLowerCase());
              System.debug('******typeName *******'+typeName );
            if (LossAnalysis == 'price' && typeName == 'price (lost)') 
            {
            
            System.debug('ist if>>>>>>');
              WinLossObjectRecordTypeId = recordType.Id;
            }
            if (LossAnalysis == 'product feature/functionality' && typeName == 'productfeature (lost)') 
            {
             System.debug('2nd if>>>>>>');
              WinLossObjectRecordTypeId = recordType.Id;
            }
            if (LossAnalysis == 'relationship' && typeName == 'relationship (lost)') 
            {
             System.debug('3rd if>>>>>>');
              WinLossObjectRecordTypeId = recordType.Id;
            }
          }
          system.debug('Record type id: ' + WinLossObjectRecordTypeId + ' found for oppt id' + WinLossObjectRecordTypeId );
              // construct the new custom object with the required fields set
              
              Win_Loss_Analysis__c wL = new Win_Loss_Analysis__c();
              System.debug('oppty.Id>>>>>>>'+oppty.Id);
              wL.Opportunity_Name__c = oppty.Id;
              wL.RecordTypeId = WinLossObjectRecordTypeId;
              System.debug('*************Checking RecordTypeId***********'+WinLossObjectRecordTypeId);
              System.debug('WinLossObjectRecordTypeId>>>>>>>'+WinLossObjectRecordTypeId);
              wL.Account_Name__c = oppty.AccountId;
               System.debug('oppty.AccountId>>>>>>>'+oppty.AccountId);
              if(existing.size() > 0)
              {
                   for(Win_Loss_Analysis__c exist : existing)
                {
                  if(exist.Opportunity_Name__c == oppty.Id)
                  {
                    wL.Id = exist.Id;
                    break;  
                  }              
                }
              }
              
              if(wL.Id == null)
              {
                newwinLossObjects.add(wL);
              }
              else
              {
                updatewinLossObjects.add(wL);
              }
              
      }
    }
    system.debug('Inserting ' + newwinLossObjects.size() + ' new Win Loss Objects' );
    system.debug('Updating ' + updatewinLossObjects.size() + '  Win Loss Objects' );
    if(newwinLossObjects.size() > 0)
         insert newwinLossObjects;
   
    if(updatewinLossObjects.size() > 0)
         update updatewinLossObjects;

}
I'm piloting Salesforce.com to a small group of users, and the first user in the field to try and install outlook edition and synch up was asked to enter his log in credentials when he clicked synch (he'd already entered them in the setup) and was given this error: "Unknown Exception in Synchrun: API request" and he couldn't synch. 
 
Does anyone have any ideas what might be causing that? 
 
Thanks,
  • April 06, 2007
  • Like
  • 0