• Douglas Traster
  • NEWBIE
  • 45 Points
  • Member since 2014
  • Salesforce Administrator
  • HUDL

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 2
    Likes Given
  • 9
    Questions
  • 8
    Replies
I am trying to build a unit test for my webservice.

I have the following class that is able to pull an ID from a custom object:

global with sharing class SendDataforForms {
    webservice static string SendDataforForms(Id AccountId) {
    String result = 'need to add try catch to help in debug';
 
        try{
            Id SQId = [Select Id from Student_Questionnaire__c
                      where Account__r.Id =:AccountId ].Id;
        System.debug('StudentQuestionnaireId: ' + SQId);
        TenStreetWebservice.GetStudentIDforData(SQId);
        result = 'OK';  
        return result;
            
        }catch(DmlException e) {
            System.debug('The Following exception has occurred: '+e.getMessage());
            result = e.getMessage();
            return result;  
        }       
    }  
}

Which, in turn, calls a webservice:
global class TenStreetWebservice {
    public TenStreetWebservice () {
        
    }
    @future (callout=true)
    public static void GetStudentIDforData(Id StudentQuestionnaireId) {
        System.debug('Start StudentQID');
        System.debug('StudentQuestionnaireId: ' + StudentQuestionnaireId);
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

        req.setEndpoint('http://cloud01.roadmaster.com:46908/api/v1/SendTo10Street?StudentQuestionnaireId='+StudentQuestionnaireId );
        req.setMethod('POST');
        req.setTimeout(50000);        
        try {
            res = http.send(req);
        } catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
}
     }
       }

I am having problems with testing the string that I should be testing.  I have this so far, but am lost on how I should go:

@isTest
global class TenStreetWebSvcMockImpl implements WebServiceMock {
    global void doInvoke(
           Object Stub,
           Object request,
           Map<String, Object> response,
           String endpoint,
           String soapAction,
           String requestName,
           String responseNS,
           String responseName,
           String responseType) {
               public String[] createSendDataforForms; 
               }

   }

Any help would be appreciated.
I have created a visual force page that includes a checkbox.  How do I go about updating a custom field on another object with the result of the vf checkbox?  True (checked) = Answer1, False(not checked) = Answer 2?

I have read about wrapping etc, but not sure if this is the correct process or not?  

Please Help!!!!!!
I am completely at a loss.  There is no documentation that tells me how to fix this issue.  I turned on the Critical Update in a sandbox and got the following:

I get the following error:
Error is in expression '{!submitHavePricing}' in component <apex:commandButton> in page formpricingsummarypg: Class.EmailFormWithAttachments.SendPricingFormEmail: line 50, column 1
Class.FormPricingSummaryCls.SubmitHavePricing: line 2226, column 1

The code at line 50 is :
      // Take the PDF content
        Blob b;
        if (Test.isRunningTest())
            b = Blob.valueOf('Test');
        else
            b = pdf.getContent();

and Line 2226 is 

 public PageReference SubmitHavePricing() {
        PageReference pr = null;
        if (Submit(false)) {
            pageController.getRecord();
            pr = Page.OpportunityForms;
            pr.getParameters().put( 'id', opp.Id );
            pr.setredirect(true);
            EmailFormWithAttachments.SendPricingFormEmail(f.id, false);

Basically, the 2226 is just calling the PDF to email to you when you hit submit on the VisualForce Page.  

If I turn off the critical update it works.  
I am trying to come up with a way possibly using a validation rule that will require Opportunity Team members to be filled out when entering an Opportunity.  

Would I do a validation rule on the Opportuntiy teams?  If so, how would I write USER cannot be blank when Opportunity is active??  Please help me wrap my head around this.
I have the following trigger:

trigger activeOpp on Opportunity (after insert, after update) {
    
    List<contact> conUpdList = new List <contact>();
    List<Id> oppConIDList = new List<Id>();
    List<opportunity> oppConList = new List<opportunity>();
    List<Contact> conList = new List<Contact>();
    Map<ID, Contact> conMap = new Map<ID, Contact>();

    
    for (opportunity opp: Trigger.new){
      system.debug(opp.StageName+ ' ' +opp.Contact__c);
        if(opp.Contact__c!= null){
            oppConList.add(opp);
            oppConIDList.add(opp.Contact__c);
            system.debug(opp.Contact__c);
        }
    }   
    
    if(!oppConIDList.isEmpty()){   
        conList  = [select ID, Active_Opportunity__c from contact where ID = :oppConIDList];
       
    }
        
    if(!conList.isEmpty()){
        for(Contact con : conList){
            conMap.put(con.ID,con);     
        }
    }
        if(!oppConList.isEmpty()){    
        for(Opportunity optyObj : oppConList){
       Contact c = conMap.get(optyObj.Contact__c);
            if( c!= null )
               
            {
            if (optyObj.StageName == 'Closed Won' || optyObj.StageName == 'Closed Lost'){
                c.Active_Opportunity__c = False;
                system.debug(c.Active_Opportunity__c);
            }
            
            else if(optyObj.StageName == 'Prospecting'
            || optyObj.StageName == 'Qualified Interest'
            || optyObj.StageName == 'Needs Analysis'
            || optyObj.StageName == 'Value Proposition'
            || optyObj.StageName == 'Proposal/Price Quote'
            || optyObj.StageName == 'Negotiation/Review'
            || optyObj.StageName == 'Verbal Commit'
            || optyObj.StageName == 'Closed Pending'){
                c.Active_Opportunity__c = True;
            }
            conUpdList.add(c);        
        }
    }
    }
    if(!conUpdList.isEmpty()){
        update conUpdList;
    }
}
I am trying to use the following test, but not sure why it is only giving me 75%?  Any help on why I can't get this working.

@isTest

private class TestOppTrgWContUpd {

    static testmethod void TestOpportunityTrgr() {
   
           Test.startTest();

       // Create two contacts

           Contact ct1 = new Contact();
           Contact ct2 = new Contact();
           ct1.FirstName = 'John';
           ct1.LastName = 'Doe';
           ct2.FirstName = 'Jane';
           ct2.LastName = 'Smith';
           //ct1.Account = 'Public School';
          // ct2.Account = 'Public School';
           ct1.Category__c = 'Public School';
           ct2.Category__c = 'Public School';
           ct1.Role__c = 'Instructional Technology';
           ct2.Role__c = 'Other';
           ct1.Email = 'jdoe@school.edu';
           ct2.Email = 'jsmith@hed.edu';
           Insert ct1;    
           Insert ct2;

           system.debug('Completed Contact Creation'); 

           

     

        // Create Opportunity

          Opportunity op1 = new Opportunity();
          Opportunity op2 = new Opportunity();
          
          op1.name = 'Opportunity Contact Insertion Test';
          //op1.account = 'Public School';
          op1.CloseDate =  Date.today()+2;
          op1.StageName = 'Prospecting';
          op1.forecastcategoryname = 'Pipeline';   
          op1.Contact__c = ct1.Id ;

          //insert op1;
          
          op1.name = 'Opportunity Contact Insertion Test';
          //op1.account = 'Public School';
          op1.CloseDate =  Date.today()+2;
          op1.StageName = 'Prospecting';
          op1.forecastcategoryname = 'Pipeline';   
          op1.Contact__c = ct1.Id ;
          
          //insert op2;
          
          Database.SaveResult sr1 = Database.insert(op1, true);
          Database.SaveResult sr2 = Database.insert(op2, true);

          System.assert(sr1.isSuccess());
          System.assert(sr2.isSuccess());

          system.debug('Inserted new opportunity');

          

       // Update Opportunity with new contact

 

          op1.Contact__c = ct2.Id;

          //update op1;

          Database.SaveResult sr3 = Database.update(op1, true);

          System.assert(sr3.isSuccess());

          system.debug('Opportunity updated');

          

          Test.stopTest();

          System.assert(sr3.isSuccess()); 

    }    

}
I have been able to get a trigger to work that either updates a checkbox on the Contact Object based on whether an Opportunity is Open or not (based on the Stage Name).

This checkbox updates Pardot.  What the Marketing dept would like to know is there a way that I can pass the Opportunity Contact Role (any of them, not just primary) over to the Contact Object?  

I could create a custom object, and then create a lookup value link to Opportunity to use a cross-object formula, but I don't see it there.  Plus, since Contact is a child in the relationship, I can't get a value to show due to the 1:M relationship.  

Can anyone think of another way to do this?
I am getting the following error on a trigger I am trying to initiate.

System.NullPointerException: Attempt to de-reference a null object: Trigger.activeOpp: line 42, column 1

Help!!! I know it is a null value on one, but not sure where to change the code...

trigger activeOpp on Opportunity (after insert, after update) {
    
    List<contact> conUpdList = new List <contact>();
    List<Id> oppConIDList = new List<Id>();
    List<opportunity> oppConList = new List<opportunity>();
    List<Contact> conList = new List<Contact>();
    Map<ID, Contact> conMap = new Map<ID, Contact>();

    
    for (opportunity opp: Trigger.new){
        if(opp.Contact__c!= null){
            oppConList.add(opp);
            oppConIDList.add(opp.Contact__c);
        }
    }   
    
    if(!oppConIDList.isEmpty()){   
        conList  = [select Name__c, Active_Opportunity__c from contact where Name__c = :oppConIDList];
    }
        
    if(!conList.isEmpty()){
        for(Contact con : conList){
            conMap.put(con.ID,con);     
        }
    }
    
    if(!oppConList.isEmpty()){    
        for(Opportunity optyObj : oppConList){
            Contact c = conMap.get(optyObj.Contact__c);
            if (optyObj.StageName == 'Closed Won' || optyObj.StageName == 'Closed Lost'){
                c.Active_Opportunity__c = False;
            }
            
            else if(optyObj.StageName == 'Prospecting'
            || optyObj.StageName == 'Qualified Interest'
            || optyObj.StageName == 'Needs Analysis'
            || optyObj.StageName == 'Value Proposition'
            || optyObj.StageName == 'Proposal/Price Quote'
            || optyObj.StageName == 'Negotiation/Review'
            || optyObj.StageName == 'Verbal Commit'
            || optyObj.StageName == 'Closed Pending'){
                c.Active_Opportunity__c = True;
            }
            conUpdList.add(c);        
        }
    }
    if(!conUpdList.isEmpty()){
        update conUpdList;
    }
}
I am fairly new to Apex.

I broke into 2 triggers, to get it to save .
They are supposed to look at the Opportunity Stage field and then update a custom field on Contacts -- Active_Opportunity__C (a checkbox).  

I am getting 0% code coverage on both and when I enter contact and new opportunity, the contact field is not populating?   What am I doing wrong?

Active_Opportunity__c (Contacts)
False 

Stage (Opportunities)
Closed Won
Closed Lost

Active_Opportunity__c (Contacts)
True

Stage (Opportunities)
Prospecting
Qualified Interest
Needs Analysis
Value Proposition
Proposal/Price Quote
Negotiation/Review
Verbal Commit
Closed Pending

Can I put these 2 into 1 and then would I just mock up an opporunity for the Unit Test?

trigger activeOpportunity on Opportunity (after insert, after update) {
    
    List<contact> conList = new List <contact>();
    
    for (opportunity optyObj: Trigger.new){
        if (optyObj.StageName == 'Closed Won' 
        && optyObj.StageName == 'Closed Lost'
        && optyObj.Contact__c <> null){
            
            conList = [select Id, Active_Opportunity__c from contact where Id = :optyObj.Contact__c ];
            for(contact conObj: conList){
                conObj.Active_Opportunity__c = False;
            }
            update(conList);
        }   
    }
}

trigger activeOpportunity2 on Opportunity (after insert, after update) {
    
    List<contact> conList = new List <contact>();
    
    for (opportunity optyObj: Trigger.new){
        if (optyObj.StageName == 'Prospecting' 
        && optyObj.StageName == 'Qualified Interest'
        && optyObj.StageName == 'Needs Analysis'
        && optyObj.StageName == 'Value Proposition'
        && optyObj.StageName == 'Proposal/Price Quote'
        && optyObj.StageName == 'Negotiation/Review'
        && optyObj.StageName == 'Verbal Commit'
        && optyObj.StageName == 'Closed Pending'
        && optyObj.Contact__c <> null){
            
            conList = [select Id, Active_Opportunity__c from contact where Id = :optyObj.Contact__c ];
            for(contact conObj: conList){
                conObj.Active_Opportunity__c = True;
            }
            update(conList);
        }   
    }
}
 
I am having a problem with a trigger.  I am trying to update the Active Opportunity(checkbox) account in Contact when an Opportunity is active, then the field should be True. When the StageName in Opportunity is either Closed Won or Closed Lost then False.

trigger updateActiveOpportunity on opportunity (after insert, after update){
    list<Id> ConIds = new list<Id>();
    list<Contact> Contacts = new list<contact>();
    for(opportunity o:trigger.new){
        conIds.add(o.contactId);
    }
    for(contact c:[select Id, Active_Opportunity__c from contact where Id IN :contIds]){
        for(opportunity opp:trigger.new){
            if(opp.stage=='closed won','closed lost'){
                c.Active_Opportunity__c='False';
                contacts.add(c);
            }
        }
    }
    update Contacts;
}
I am completely at a loss.  There is no documentation that tells me how to fix this issue.  I turned on the Critical Update in a sandbox and got the following:

I get the following error:
Error is in expression '{!submitHavePricing}' in component <apex:commandButton> in page formpricingsummarypg: Class.EmailFormWithAttachments.SendPricingFormEmail: line 50, column 1
Class.FormPricingSummaryCls.SubmitHavePricing: line 2226, column 1

The code at line 50 is :
      // Take the PDF content
        Blob b;
        if (Test.isRunningTest())
            b = Blob.valueOf('Test');
        else
            b = pdf.getContent();

and Line 2226 is 

 public PageReference SubmitHavePricing() {
        PageReference pr = null;
        if (Submit(false)) {
            pageController.getRecord();
            pr = Page.OpportunityForms;
            pr.getParameters().put( 'id', opp.Id );
            pr.setredirect(true);
            EmailFormWithAttachments.SendPricingFormEmail(f.id, false);

Basically, the 2226 is just calling the PDF to email to you when you hit submit on the VisualForce Page.  

If I turn off the critical update it works.  
As per Summer release 15, if someone calling this method will be treated as call out, Does it means that it has timeout of 2 minutes ?
What if customer using getContentAsPDF() method to generate the PDF , Did they get any impact (If they are generating large PDF's)?
I am getting the following error on a trigger I am trying to initiate.

System.NullPointerException: Attempt to de-reference a null object: Trigger.activeOpp: line 42, column 1

Help!!! I know it is a null value on one, but not sure where to change the code...

trigger activeOpp on Opportunity (after insert, after update) {
    
    List<contact> conUpdList = new List <contact>();
    List<Id> oppConIDList = new List<Id>();
    List<opportunity> oppConList = new List<opportunity>();
    List<Contact> conList = new List<Contact>();
    Map<ID, Contact> conMap = new Map<ID, Contact>();

    
    for (opportunity opp: Trigger.new){
        if(opp.Contact__c!= null){
            oppConList.add(opp);
            oppConIDList.add(opp.Contact__c);
        }
    }   
    
    if(!oppConIDList.isEmpty()){   
        conList  = [select Name__c, Active_Opportunity__c from contact where Name__c = :oppConIDList];
    }
        
    if(!conList.isEmpty()){
        for(Contact con : conList){
            conMap.put(con.ID,con);     
        }
    }
    
    if(!oppConList.isEmpty()){    
        for(Opportunity optyObj : oppConList){
            Contact c = conMap.get(optyObj.Contact__c);
            if (optyObj.StageName == 'Closed Won' || optyObj.StageName == 'Closed Lost'){
                c.Active_Opportunity__c = False;
            }
            
            else if(optyObj.StageName == 'Prospecting'
            || optyObj.StageName == 'Qualified Interest'
            || optyObj.StageName == 'Needs Analysis'
            || optyObj.StageName == 'Value Proposition'
            || optyObj.StageName == 'Proposal/Price Quote'
            || optyObj.StageName == 'Negotiation/Review'
            || optyObj.StageName == 'Verbal Commit'
            || optyObj.StageName == 'Closed Pending'){
                c.Active_Opportunity__c = True;
            }
            conUpdList.add(c);        
        }
    }
    if(!conUpdList.isEmpty()){
        update conUpdList;
    }
}
I am fairly new to Apex.

I broke into 2 triggers, to get it to save .
They are supposed to look at the Opportunity Stage field and then update a custom field on Contacts -- Active_Opportunity__C (a checkbox).  

I am getting 0% code coverage on both and when I enter contact and new opportunity, the contact field is not populating?   What am I doing wrong?

Active_Opportunity__c (Contacts)
False 

Stage (Opportunities)
Closed Won
Closed Lost

Active_Opportunity__c (Contacts)
True

Stage (Opportunities)
Prospecting
Qualified Interest
Needs Analysis
Value Proposition
Proposal/Price Quote
Negotiation/Review
Verbal Commit
Closed Pending

Can I put these 2 into 1 and then would I just mock up an opporunity for the Unit Test?

trigger activeOpportunity on Opportunity (after insert, after update) {
    
    List<contact> conList = new List <contact>();
    
    for (opportunity optyObj: Trigger.new){
        if (optyObj.StageName == 'Closed Won' 
        && optyObj.StageName == 'Closed Lost'
        && optyObj.Contact__c <> null){
            
            conList = [select Id, Active_Opportunity__c from contact where Id = :optyObj.Contact__c ];
            for(contact conObj: conList){
                conObj.Active_Opportunity__c = False;
            }
            update(conList);
        }   
    }
}

trigger activeOpportunity2 on Opportunity (after insert, after update) {
    
    List<contact> conList = new List <contact>();
    
    for (opportunity optyObj: Trigger.new){
        if (optyObj.StageName == 'Prospecting' 
        && optyObj.StageName == 'Qualified Interest'
        && optyObj.StageName == 'Needs Analysis'
        && optyObj.StageName == 'Value Proposition'
        && optyObj.StageName == 'Proposal/Price Quote'
        && optyObj.StageName == 'Negotiation/Review'
        && optyObj.StageName == 'Verbal Commit'
        && optyObj.StageName == 'Closed Pending'
        && optyObj.Contact__c <> null){
            
            conList = [select Id, Active_Opportunity__c from contact where Id = :optyObj.Contact__c ];
            for(contact conObj: conList){
                conObj.Active_Opportunity__c = True;
            }
            update(conList);
        }   
    }
}
 
I am having a problem with a trigger.  I am trying to update the Active Opportunity(checkbox) account in Contact when an Opportunity is active, then the field should be True. When the StageName in Opportunity is either Closed Won or Closed Lost then False.

trigger updateActiveOpportunity on opportunity (after insert, after update){
    list<Id> ConIds = new list<Id>();
    list<Contact> Contacts = new list<contact>();
    for(opportunity o:trigger.new){
        conIds.add(o.contactId);
    }
    for(contact c:[select Id, Active_Opportunity__c from contact where Id IN :contIds]){
        for(opportunity opp:trigger.new){
            if(opp.stage=='closed won','closed lost'){
                c.Active_Opportunity__c='False';
                contacts.add(c);
            }
        }
    }
    update Contacts;
}

Hi All,

I need to display a picture in VFPage. In my custom field, I have the formula 
image("/resource/STR_TRIANGLE" & case( IconFlag__c, 1,"", 2,"",'none') ,"",20,20)
I want to display the STR_TRIANGLE picture, if FlowerFlag ==1, if FlowerFlag === 2  or other, there is nothing.
It displayed a dark pictureshadow  when it’s 2 or other .

Any idea Please?

Hi,
after releasing first version of managed package , we have made changes in product layout but it does not seems to be changed in next released beta version so what is the reason behind it, 
we have also create a permission set on profile but changes can not overrides in next beta version.
so what should we do.?

Thanks in advance