• wixxey
  • NEWBIE
  • 50 Points
  • Member since 2013

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 22
    Questions
  • 26
    Replies

Hello!
I am having an issue of salesforce and rightsignature integration. my target is whenever a contact is created, i have to send rightsignature documents to email of the new contact. anyone here know how to do this? is it possible to use rightsignature from apex code, your guidance will be highly appreciated

Hello!
I am having an issue of salesforce and rightsignature integration. my target is whenever a contact is created, i have to send 4rightsignature to email of the new contact. anyone here know how to do this, your guidance will be highly appreciated

Hey!

 

I have the following SOQL

 

soql = 'select Id, Name, Price__c, Test_Name__c, Analyte__c , Manufacturer__c, Device__c, URL__c From Assessment__c where ';
        soql = soql+ 'Id NOT IN (Select Assessment__c From LocationAssesmentRelationship__c where Location__c = \''+ locationId +'\')';

 in the Nested SOQL the table LocationAssesmentRelationShip__c has an expiryDate__c column, i want to check whether the ExpiryDate is greater then the Date.today().

Kindly help if possible

 

 

I have been using a datatable along with a checkbox in each row, I want that the user shod not select more then one row. i want to use these checkboxes as radiobox, i want to keep the multiple selection off.. my code is

 

<apex:pageBlockTable value="{!results}" var="assessments">
                    <apex:column >
                        <apex:inputCheckbox value="{!assessments.selected}" id="selectLine1"/> 
                    </apex:column> 
                    <apex:column headervalue="Devices">
                   
                        <apex:outputtext value="{!assessments.as.Device__c}" />
                    </apex:column>
                    <apex:column headervalue="Manufacturer">
                        <apex:outputtext value="{!assessments.as.Manufacturer__c}"/>
                    </apex:column>
                    <apex:column headervalue="Test Name">
                        <apex:outputtext value="{!assessments.as.Test_Name__c}"/>
                    </apex:column>
                    <apex:column headervalue="Analyte">
                        <apex:outputtext value="{!assessments.as.Analyte__c}"/>
                    </apex:column>
                   <apex:column headervalue="Price in $">
                        <apex:outputtext value="{!assessments.as.Price__c}"/>
                    </apex:column>
                   
      </apex:pageBlockTable> 

 Kindly guide me whether this is possible

Hello,

 

I have developed a website in salesforce the problem i am facing is  When i log out i clear the cookies. but when i press the back button after logging out the session gets restored. How can i avoid the session restore or stop the back button to get back into site, any suggestion regarding this will be highly appreciated.

Hello!

 

I am adding an anchor tag in my Apex:message , but it doesnot show the link , my code is given below, kindly guide me if possible

 

code in controller

 

ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Password Changed Successfully... click on link to login with the new'+
        ' password <a href="http://abc.xyz.com/index>http://abc.xyz.com/index</a>"'));

 code in visualforce page

<apex:pagemessages escape="false" />

 

 

Hello!
I want to send a Static resource image in Email through a controller. the code which i have written for it is given below

Public void sendMail(){
     
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
         String[] toAddresses = new String[] {info.Location__r.Account__r.Email__c}; 
         mail.setToAddresses(toAddresses);
         mail.setSenderDisplayName('Support');
         mail.setSubject('Invoice');
         mail.setBccSender(false); 
         mail.setUseSignature(false);
         mail.setHtmlBody('<image src="' + StaticResourceURL.GetResourceURL('cpLogo')+ '"/>'); 
 Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); }

 and the StaticResourcUrl is a class which i have search on net for getting the url of a static resource

public class StaticResourceURL
{
    //Pass the resource name
    public static String GetResourceURL(String resourceName)
    {
        //Fetching the resource
        List<StaticResource> resourceList = [SELECT Name, NamespacePrefix, SystemModStamp FROM StaticResource WHERE Name = :resourceName];
                            
        //Checking if the result is returned or not
        if(resourceList.size() == 1)
        {
           //Getting namespace
           String namespace = resourceList[0].NamespacePrefix;
           //Resource URL
           
           return '/resource/' + resourceList[0].SystemModStamp.getTime() + '/' + (namespace != null && namespace != '' ? namespace + '__' : '') + resourceName; 
        }
        else return '';
    }
    
    public static testMethod void testStaticResourceURL(){
    	StaticResourceURL.GetResourceURL('cpLogo');
    	System.debug(StaticResourceURL.GetResourceURL('cpLogo'));
    }
    
}

 

but this code is not working for me although system.debug in the class returns /resource/1368709494000/cpLogo ... kindly guide me what is wrong with it

Hello,

I am having a problem in the code. The Contact object con is defined in code below, it is recieving all the values from the visualforce page. but before inserting this con object i want to change its owner field to the Account it is recieving in line #5. as this con object takes bydefault owner.

 

public with sharing class newContact {
    public Contact con {get;set;}
    public newContact(ApexPages.StandardController c) {
            con = (Contact)c.getRecord();
            con.AccountId = ApexPages.currentPage().getParameters().get('pid');
    }
     public PageReference save(){
       insert con;
       return new PageReference('/index/index?id='+con.AccountId); 
    }
    
    

 Kindly Guide me if possible

I am working with visualforce pages. I am using datatable in page and i have used a checkbox in each row in datatable, now i want to get only those rows whose checkbox values is true, the code is given below.

 

<apex:page controller="searchDuplicate">
<apex:pageBlock title="Searching for Duplicate Contacts Record">
 <center>
     <apex:form>
         <apex:dataTable id="dTable" value="{!selectedContactList}" var="cn" border="1" cellpadding="5">
            <apex:column headerValue="Name" value="{!cn.Name}" />
            <apex:column headerValue="Email" value="{!cn.Email}" />
            <apex:column headerValue="Select">
                <apex:inputCheckbox/>
            </apex:column>
         </apex:dataTable>
         <apex:commandButton value= "Delete Selected"/>
    </apex:form>
 </center>
</apex:pageBlock> 
</apex:page>

 kindly help

 

 

Hey Plz chk the Error i want to display the AggregateResult on my Visualforce page but it is generating Error " Invalid field Email for SObject AggregateResult" the code is given below

public with sharing class searchDuplicate {
   public   AggregateResult[] con{get;set;}
   
   public searchDuplicate()
   {
       find();
   }
    public void find(){
      con = [select Email from Contact group by Email having count(Email) > 1];
        System.debug(con);
    }
}

 and Visual Force code is

<apex:page controller="searchDuplicate">
    <apex:pageBlock title="Searching for Duplicate Contacts Record"> 
    </apex:pageBlock>
    <apex:pageBlock title="Contacts">
        <apex:dataTable value="{!con}" var="c" border="2" cellspacing="5" cellpadding="5">
            <apex:column headerValue="Email" value="{!c['Email']}" />
        </apex:dataTable>
    </apex:pageBlock>     
</apex:page>

 

I am writing a test code for the Class but it is generating this error

System.DmlException: Insert failed. First exception on row 0 with id 0039000000NoNCHAA3; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

Stack TraceClass.newContact.save: line 10, column 1
Class.newContact.testNewContact: line 30, column 1

 

public class newContact {
    public Contact con {get;set;}
    
    public newContact(ApexPages.StandardController c) {
            
            con = (Contact)c.getRecord();
            con.AccountId = ApexPages.currentPage().getParameters().get('pid');
    }
     public PageReference save(){
       insert con;
       
       return new PageReference('/index/index?id='+con.AccountId); 
    }
    
    public static testMethod void testNewContact(){
         PageReference pageRef = Page.newContact;
         Test.setCurrentPageReference(pageRef);
         
        Account a=new account();
        a.Name = 'Test Name';
        insert a;
        
        Contact con = new Contact(Email =  'test@test.com', LastName = 'Tester'); 
        con.Type__c = 'Customer Admin';
        con.accountid = a.id;
        insert con;
        
        ApexPages.StandardController sc = new ApexPages.standardController(con);
        newContact nC = new newContact(sc);
        PageReference pr = nC.save();
    }
}

 

 

  • April 26, 2013
  • Like
  • 0

Kindly help me in writing the test code for the below trigger, i will be thankful

trigger detectClone on Contact (before insert, after update){
    for(Contact acc : trigger.new){
        if(Trigger.isInsert){
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[] {acc.Email}; 
            mail.setToAddresses(toAddresses);
            mail.setSenderDisplayName('Support Team');
            mail.setSubject('LogIn information');
            mail.setBccSender(false);
            mail.setUseSignature(false);
         
            Double rnd = math.random();
            String str_rnd = String.valueOf(rnd);
            String temp_pass = str_rnd.replace('.','1');
            String pass = temp_pass.substring(1,6);
            
            mail.setHtmlBody('Dear '+acc.LastName+'<br/><br/>'+
            'Welcome to EZQCP! You have been invited to join the EZQCP [Account Name] account team.<br/> '+
            'Your user name is below:<br/><br/>'+
            'User Name: '+ acc.User_Name__c+'<br/>'+
            'Password: '+ pass +'<br/><br/>'+
            ' To accept the invitation and set your username, log in automatically by clicking www.xxxxx.xxxxxx<br/> '+
            'If you experience problems with the above link, please contact support@ezqcp.com for assistance.');
           
           Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });             
           acc.Password__c = pass;     
        }
        else if(Trigger.isUpdate ){
            List<Contact> admin = [Select Id, Type__c From Contact Where AccountId =:acc.AccountId AND
             Type__c = 'Customer Admin' ];
             if(admin.size()<1){
                 acc.addError('Each Account must have atleast one Contact with Admin privileges');
             }
        }
    }
}

 

  • April 25, 2013
  • Like
  • 0

Hi!

I am calling an API of FluidSurvey. when i make a POST request ... it post the request on the fluidSurvey but i didnt get the JSON response. rather it returns nothing. any suggestion??

 

my controller code

public class fluidSurvey{

    public String tst{set;get;}
    public String result{get;set;}
    
    public PageReference chk() {
        getData();
        return null;
    }

    public void getData(){
        String apiKey = 'xxxxxx';
        String pwd = 'xxxxxx';
        String u = 'https://app.fluidsurveys.com/api/v2/surveys/survey_id/responses/';
        
        HttpRequest req = new HttpRequest();
        Http http = new Http();
        HTTPResponse res;
        try{
            req.setEndPoint(u);
            req.setTimeout(20000);
            req.setMethod('POST');
            Blob headerValue = Blob.valueOf(apikey + ':' + pwd);
            String authorizationHeader = 'Basic '+ EncodingUtil.base64Encode(headerValue);
            req.setHeader('Authorization', authorizationHeader);
            req.setHeader('Content-Type', 'application/json');
            req.setHeader('Content-Length','31999');
            
            res = http.send(req); 
            tst= res.toString();
                     
               
        
	       catch(Exception e){
               System.debug('Callout error: '+ e);
               System.debug(tst+'--------'+res);
           }     
        }
       
}

 and the Apex page code is

<apex:page controller="newFS">
<center>
      <apex:form >
          <apex:pageBlock title="New Fluid Surveys API">
              <apex:outputText value="{!tst}"></apex:outputText><br/>
               <apex:pageBlockButtons location="bottom">
                  <apex:commandButton value="Submit" action="{!chk}"/>
               </apex:pageBlockButtons>   
          </apex:pageBlock>
      </apex:form>
      </center>
</apex:page>

 and api documentation link is http://docs.fluidsurveys.com/api/surveys.html#getting-a-list-of-surveys..

  • April 18, 2013
  • Like
  • 0

I have and PHP code for accessing the FluidSurvey API. anyone who can give me its APEX alternative or convert the code into apex.. i will be thankful

 

 

<?php
function GET($url){
        global $api_key, $password;
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($curl, CURLOPT_USERPWD, $api_key.':'.$password);
        curl_setopt($curl, CURLOPT_SSLVERSION,3);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;
                MSIE 5.01; Windows NT 5.0)");
        curl_setopt($curl, CURLOPT_URL, $url);
        $data = curl_exec($curl);
        curl_close($curl);
        return $data;
}
  • April 17, 2013
  • Like
  • 0

I have and PHP code for accessing the FluidSurvey API. anyone who can give me its APEX alternative or convert the code into apex.. i will be thankful

 

 

<?php
function GET($url){
        global $api_key, $password;
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($curl, CURLOPT_USERPWD, $api_key.':'.$password);
        curl_setopt($curl, CURLOPT_SSLVERSION,3);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;
                MSIE 5.01; Windows NT 5.0)");
        curl_setopt($curl, CURLOPT_URL, $url);
        $data = curl_exec($curl);
        curl_close($curl);
        return $data;
}
  • April 17, 2013
  • Like
  • 0

I am trying to access the fluid survey API in Salesforce. i use the following code but it create some error

the code for controller class is

    public class fluidSurvey{
        public String tst{set;get;}
        public String result{get;set;}
    
        public PageReference chk() {

            //if (!ApexPages.hasMessages())
                result=getData();
     
            return null;
        }
     public String getData()
       {
           HttpRequest req= new HttpRequest();
           Http http = new Http();
           req.setMethod('GET');
           String url = 'https://username:password@app.fluidsurveys.com/ap

i/v2/surveys/';
           req.setEndpoint(url);
           HttpResponse res = http.send(req);
           String json =  res.getBody().replace('\n','');
           tst = json;
            try {
                JSONObject j = new JSONObject( json );
                return parseJson(j);
            } catch (JSONObject.JSONException e) {
                return 'Error parsing JSON response from Google: '+e;
            }
           
       }
       
       public String parseJson(JSONObject resp){
           String detail =resp.getString('total');
            
           return detail;
       }
    }


and the code for apex page is

    <apex:page controller="fluidSurvey">
      <!-- Begin Default Content REMOVE THIS -->
       <h1>Fluid Survey</h1>
       <apex:form >
          
           <apex:outputText value="{!tst}"></apex:outputText>
          <apex:commandButton value="Submit" action="{!chk}"/>
      </apex:form>
    </apex:page>


but when i click the submit button it create the following error

System.CalloutException: For input string: "password@app.fluidsurveys.com"
Error is in expression '{!chk}' in component <apex:page> in page fluid-page

  • April 17, 2013
  • Like
  • 0

I am trying to access the fluid survey API in Salesforce. i use the following code but it create some error

the code for controller class is

    public class fluidSurvey{
        public String tst{set;get;}
        public String result{get;set;}
    
        public PageReference chk() {

            //if (!ApexPages.hasMessages())
                result=getData();
     
            return null;
        }
     public String getData()
       {
           HttpRequest req= new HttpRequest();
           Http http = new Http();
           req.setMethod('GET');
           String url = 'https://username:password@app.fluidsurveys.com/api/v2/surveys/';
           req.setEndpoint(url);
           HttpResponse res = http.send(req);
           String json =  res.getBody().replace('\n','');
           tst = json;
            try {
                JSONObject j = new JSONObject( json );
                return parseJson(j);
            } catch (JSONObject.JSONException e) {
                return 'Error parsing JSON response from Google: '+e;
            }
           
       }
       
       public String parseJson(JSONObject resp){
           String detail =resp.getString('total');
            
           return detail;
       }
    }


and the code for apex page is

    <apex:page controller="fluidSurvey">
      <!-- Begin Default Content REMOVE THIS -->
       <h1>Fluid Survey</h1>
       <apex:form >
          
           <apex:outputText value="{!tst}"></apex:outputText>
          <apex:commandButton value="Submit" action="{!chk}"/>
      </apex:form>
    </apex:page>


but when i click the submit button it create the following error

System.CalloutException: For input string: "password@app.fluidsurveys.com"
Error is in expression '{!chk}' in component <apex:page> in page fluid-page

  • April 16, 2013
  • Like
  • 0
Hello! anyone here who has use fluidsurvey api in salesforce ... kindly guide me regarding the url building which is implemented in oAuth 2.0 thanx
  • April 12, 2013
  • Like
  • 0

is there any methods in apex so that we can set the client url, so that i can access a fluidsurvey api ... any idea of how to use this api in salesforce...

 

regards

  • April 10, 2013
  • Like
  • 0

Kindly help me in writing a test code for this class .. i am new to visualforce

 

public class geoIp{
    public String host{set;get;}
    public String getResult{get;set;}
    
    public PageReference submit() {
 if (host.length() == 0) {
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'City cannot be blank'));
            }
     
            if (!ApexPages.hasMessages())
                getResult=getIp(host);
     
            return null;
       }
     public String getIP(String vHost)
       {
           HttpRequest req= new HttpRequest();
           Http http = new Http();
           req.setMethod('GET');
           String url = 'http://freegeoip.net/json/' + EncodingUtil.urlEncode(vHost,'UTF-8') + '';
           req.setEndpoint(url);
           HttpResponse res = http.send(req);
           String json =  res.getBody().replace('\n','');
           
            try {
                JSONObject j = new JSONObject( json );
                return parseJson(j);
            } catch (JSONObject.JSONException e) {
                return 'Error parsing JSON response from Google: '+e;
            }
           
       }
       
       public String parseJson(JSONObject resp){
           String detail = resp.getString('ip') + '   ' + resp.getString('country_code') + '   ' + resp.getString('country_name') + '   ' + resp.getString('region_code') + '   ' + resp.getString('region_name') +  '   ' + resp.getString('latitude') + '   ' + resp.getString('longitude') + '   ' + resp.getString('zipcode') + '   ' + resp.getString('areacode');
             
           return detail;
       }
}

  • April 09, 2013
  • Like
  • 0

Hey!

 

I have the following SOQL

 

soql = 'select Id, Name, Price__c, Test_Name__c, Analyte__c , Manufacturer__c, Device__c, URL__c From Assessment__c where ';
        soql = soql+ 'Id NOT IN (Select Assessment__c From LocationAssesmentRelationship__c where Location__c = \''+ locationId +'\')';

 in the Nested SOQL the table LocationAssesmentRelationShip__c has an expiryDate__c column, i want to check whether the ExpiryDate is greater then the Date.today().

Kindly help if possible

 

 

I have been using a datatable along with a checkbox in each row, I want that the user shod not select more then one row. i want to use these checkboxes as radiobox, i want to keep the multiple selection off.. my code is

 

<apex:pageBlockTable value="{!results}" var="assessments">
                    <apex:column >
                        <apex:inputCheckbox value="{!assessments.selected}" id="selectLine1"/> 
                    </apex:column> 
                    <apex:column headervalue="Devices">
                   
                        <apex:outputtext value="{!assessments.as.Device__c}" />
                    </apex:column>
                    <apex:column headervalue="Manufacturer">
                        <apex:outputtext value="{!assessments.as.Manufacturer__c}"/>
                    </apex:column>
                    <apex:column headervalue="Test Name">
                        <apex:outputtext value="{!assessments.as.Test_Name__c}"/>
                    </apex:column>
                    <apex:column headervalue="Analyte">
                        <apex:outputtext value="{!assessments.as.Analyte__c}"/>
                    </apex:column>
                   <apex:column headervalue="Price in $">
                        <apex:outputtext value="{!assessments.as.Price__c}"/>
                    </apex:column>
                   
      </apex:pageBlockTable> 

 Kindly guide me whether this is possible

Hello,

 

I have developed a website in salesforce the problem i am facing is  When i log out i clear the cookies. but when i press the back button after logging out the session gets restored. How can i avoid the session restore or stop the back button to get back into site, any suggestion regarding this will be highly appreciated.

Hello!

 

I am adding an anchor tag in my Apex:message , but it doesnot show the link , my code is given below, kindly guide me if possible

 

code in controller

 

ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Password Changed Successfully... click on link to login with the new'+
        ' password <a href="http://abc.xyz.com/index>http://abc.xyz.com/index</a>"'));

 code in visualforce page

<apex:pagemessages escape="false" />

 

 

Hello!
I want to send a Static resource image in Email through a controller. the code which i have written for it is given below

Public void sendMail(){
     
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
         String[] toAddresses = new String[] {info.Location__r.Account__r.Email__c}; 
         mail.setToAddresses(toAddresses);
         mail.setSenderDisplayName('Support');
         mail.setSubject('Invoice');
         mail.setBccSender(false); 
         mail.setUseSignature(false);
         mail.setHtmlBody('<image src="' + StaticResourceURL.GetResourceURL('cpLogo')+ '"/>'); 
 Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); }

 and the StaticResourcUrl is a class which i have search on net for getting the url of a static resource

public class StaticResourceURL
{
    //Pass the resource name
    public static String GetResourceURL(String resourceName)
    {
        //Fetching the resource
        List<StaticResource> resourceList = [SELECT Name, NamespacePrefix, SystemModStamp FROM StaticResource WHERE Name = :resourceName];
                            
        //Checking if the result is returned or not
        if(resourceList.size() == 1)
        {
           //Getting namespace
           String namespace = resourceList[0].NamespacePrefix;
           //Resource URL
           
           return '/resource/' + resourceList[0].SystemModStamp.getTime() + '/' + (namespace != null && namespace != '' ? namespace + '__' : '') + resourceName; 
        }
        else return '';
    }
    
    public static testMethod void testStaticResourceURL(){
    	StaticResourceURL.GetResourceURL('cpLogo');
    	System.debug(StaticResourceURL.GetResourceURL('cpLogo'));
    }
    
}

 

but this code is not working for me although system.debug in the class returns /resource/1368709494000/cpLogo ... kindly guide me what is wrong with it

Hello,

I am having a problem in the code. The Contact object con is defined in code below, it is recieving all the values from the visualforce page. but before inserting this con object i want to change its owner field to the Account it is recieving in line #5. as this con object takes bydefault owner.

 

public with sharing class newContact {
    public Contact con {get;set;}
    public newContact(ApexPages.StandardController c) {
            con = (Contact)c.getRecord();
            con.AccountId = ApexPages.currentPage().getParameters().get('pid');
    }
     public PageReference save(){
       insert con;
       return new PageReference('/index/index?id='+con.AccountId); 
    }
    
    

 Kindly Guide me if possible

Hey Plz chk the Error i want to display the AggregateResult on my Visualforce page but it is generating Error " Invalid field Email for SObject AggregateResult" the code is given below

public with sharing class searchDuplicate {
   public   AggregateResult[] con{get;set;}
   
   public searchDuplicate()
   {
       find();
   }
    public void find(){
      con = [select Email from Contact group by Email having count(Email) > 1];
        System.debug(con);
    }
}

 and Visual Force code is

<apex:page controller="searchDuplicate">
    <apex:pageBlock title="Searching for Duplicate Contacts Record"> 
    </apex:pageBlock>
    <apex:pageBlock title="Contacts">
        <apex:dataTable value="{!con}" var="c" border="2" cellspacing="5" cellpadding="5">
            <apex:column headerValue="Email" value="{!c['Email']}" />
        </apex:dataTable>
    </apex:pageBlock>     
</apex:page>

 

Hi, 

 

  I am new to salesforce wanted to know how to make code coverage to 75% from 67%. Below is the class i am using to check the code coverage. I need to deploy this to production.  Please suggest me how to modify the below class and make to get 75% Please suggest me 

 

public class DRConvertToOpportunitycontroller {

    public DRConvertToOpportunitycontroller (ApexPages.StandardController controller) {
    }
   
    Opportunity opp = new opportunity();

    public PageReference save() {
        string str = apexpages.currentpage().getparameters().get('id');
        System.debug('str == '+str);

        DealReg__c deal = [SELECT id, customer_name__c, deal_stage__c,
                            account_id__c, estimated_close_date__c,
                            estimated_value__c, competitor__c,
                            account__c, project_name__c,
                            distributor__c, reseller__c,
                            channel_source__c, discount_program__c,
                            ownerid, status__c, owner.type,
                            field_representative__c, theater__c,
                            Partner_Initiated__c,Partner_Led__c,K_12__c 
                        FROM DealReg__c
                        WHERE id = :str];
                        
      // Coded by Sudhir to Get User Information and Region Information from User Object                      
      // String userName = UserInfo.getUserName();                          
   // User Urs = [SELECT Region__c FROM User WHERE Username = : userName limit 1];                      
                          
        opp.name = Deal.project_name__c +  ' ' +'FOR'+' '+deal.customer_name__c;
        // Deal Field Representative field value will be used as Opportunity Owner, when available.
        // Else, Deal Owner field will be used.
        
        if (Deal.field_representative__c <> null) 
         {
           opp.OwnerId = Deal.field_representative__c;
        } else {
           opp.OwnerId = Deal.OwnerId;
        }
        
        // For NAM, Deal Owner (ISR) will become the Opportunity Secondary Owner
        if (Deal.theater__c == 'NAM') {
           opp.Secondary_Owner__c = Deal.OwnerId;    
           if ( opp.Partner_Driven__c == 'Yes'  && opp.Partner_Led__c == 'No' && opp.K_12__c == 'No'  ) 
           {
           opp.discount_program__c = 'DEALREG/PI';
           opp.Abbv_Discount_Program__c = 'DR/PI';        
           }
         else if ( opp.Partner_Driven__c == 'No'  && opp.Partner_Led__c == 'Yes' && opp.K_12__c == 'No'  ) 
         {
          opp.discount_program__c = 'DEALREG/PL';
          opp.Abbv_Discount_Program__c = 'DR/PL';    
         }
         else if ( opp.Partner_Driven__c == 'Yes'  && opp.Partner_Led__c == 'Yes' && opp.K_12__c == 'No'  ) 
         {
          opp.discount_program__c = 'DEALREG/PI/PL';
          opp.Abbv_Discount_Program__c = 'DR/PI/PL';  
         }
        else if ( opp.Partner_Driven__c == 'No'  && opp.Partner_Led__c == 'No' && opp.K_12__c == 'Yes' ) 
        {
         opp.discount_program__c = 'DEALREG/K-12';
         opp.Abbv_Discount_Program__c = 'DR/K12';    
        }
        else if ( opp.Partner_Driven__c == 'Yes'  && opp.Partner_Led__c == 'No' && opp.K_12__c == 'Yes' )
        {
        opp.discount_program__c = 'DEALREG/PI/K-12';
        opp.Abbv_Discount_Program__c = 'DR/PI/K12';    
        }
        else if (   opp.Partner_Driven__c == 'No'  && opp.Partner_Led__c == 'Yes' && opp.K_12__c == 'Yes'  )
        {
        opp.discount_program__c = 'DEALREG/PL/K-12';
        opp.Abbv_Discount_Program__c = 'DR/PL/K12';   
        }
        else if ( opp.Partner_Driven__c == 'Yes'  && opp.Partner_Led__c == 'Yes' && opp.K_12__c == 'Yes' )
        {
        opp.discount_program__c = 'DEALREG/PI/PL/K-12';
        opp.Abbv_Discount_Program__c = 'DR/PI/PL/K12';   
        }
       else
       {
        opp.discount_program__c = 'DEALREG';
        opp.Abbv_Discount_Program__c = 'DR';     
        }   
       }
       else
      {
       opp.discount_program__c = 'NSP';
       opp.Abbv_Discount_Program__c = 'NSP';   
      } 
           
              
        opp.StageName = Deal.deal_stage__c;
        opp.CloseDate = Deal.estimated_close_date__c;
        opp.Primary_Competitor__c = deal.competitor__c;
        opp.type = 'Existing Customer';
        opp.Government_Contract__c = 'None';
        opp.leadsource = 'Deal Registration';
        opp.Partner_Driven__c = 'yes';
        opp.Partner_Account__c = deal.reseller__c;
        opp.primary_distributor__c = deal.distributor__c;
        opp.primary_reseller__c = deal.reseller__c;
        opp.channel_source__c = deal.channel_source__c;
        opp.K_12__c  = deal.K_12__c;
        opp.Renewal_Opportunity__c = 'No';
        opp.Renewal_Incumbant_Reseller__c = 'No';
        opp.Renewal_K_12__c = 'No';    
        opp.DEALREG_SEND_QUOTE__c = 'Do Not Send';
        opp.RENEWAL_SEND_QUOTE__c = 'Do Not Send';  
        opp.accountid = deal.account__c;        
        opp.deal_registration__c = deal.id; 
        
        // mapping deal columns with oppertunity columns
        opp.Partner_Driven__c = deal.Partner_Initiated__c;
        opp.Partner_Led__c = deal.Partner_Led__c;      
      
      if(deal.Status__c <> 'Approved'){
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Only an approved Deal can be converted to an Opportunity.'));
           return null;
        } else if(deal.owner.type == 'Queue'){
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'A Deal needs to be assigned before it can be converted to an Opportunity.'));
           return null;
        } else{
     
         insert opp;
     
            PageReference pg = new PageReference('/'+opp.id);
            return pg;
        }
    } 
}

 

I am writing a test code for the Class but it is generating this error

System.DmlException: Insert failed. First exception on row 0 with id 0039000000NoNCHAA3; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

Stack TraceClass.newContact.save: line 10, column 1
Class.newContact.testNewContact: line 30, column 1

 

public class newContact {
    public Contact con {get;set;}
    
    public newContact(ApexPages.StandardController c) {
            
            con = (Contact)c.getRecord();
            con.AccountId = ApexPages.currentPage().getParameters().get('pid');
    }
     public PageReference save(){
       insert con;
       
       return new PageReference('/index/index?id='+con.AccountId); 
    }
    
    public static testMethod void testNewContact(){
         PageReference pageRef = Page.newContact;
         Test.setCurrentPageReference(pageRef);
         
        Account a=new account();
        a.Name = 'Test Name';
        insert a;
        
        Contact con = new Contact(Email =  'test@test.com', LastName = 'Tester'); 
        con.Type__c = 'Customer Admin';
        con.accountid = a.id;
        insert con;
        
        ApexPages.StandardController sc = new ApexPages.standardController(con);
        newContact nC = new newContact(sc);
        PageReference pr = nC.save();
    }
}

 

 

  • April 26, 2013
  • Like
  • 0

Kindly help me in writing the test code for the below trigger, i will be thankful

trigger detectClone on Contact (before insert, after update){
    for(Contact acc : trigger.new){
        if(Trigger.isInsert){
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[] {acc.Email}; 
            mail.setToAddresses(toAddresses);
            mail.setSenderDisplayName('Support Team');
            mail.setSubject('LogIn information');
            mail.setBccSender(false);
            mail.setUseSignature(false);
         
            Double rnd = math.random();
            String str_rnd = String.valueOf(rnd);
            String temp_pass = str_rnd.replace('.','1');
            String pass = temp_pass.substring(1,6);
            
            mail.setHtmlBody('Dear '+acc.LastName+'<br/><br/>'+
            'Welcome to EZQCP! You have been invited to join the EZQCP [Account Name] account team.<br/> '+
            'Your user name is below:<br/><br/>'+
            'User Name: '+ acc.User_Name__c+'<br/>'+
            'Password: '+ pass +'<br/><br/>'+
            ' To accept the invitation and set your username, log in automatically by clicking www.xxxxx.xxxxxx<br/> '+
            'If you experience problems with the above link, please contact support@ezqcp.com for assistance.');
           
           Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });             
           acc.Password__c = pass;     
        }
        else if(Trigger.isUpdate ){
            List<Contact> admin = [Select Id, Type__c From Contact Where AccountId =:acc.AccountId AND
             Type__c = 'Customer Admin' ];
             if(admin.size()<1){
                 acc.addError('Each Account must have atleast one Contact with Admin privileges');
             }
        }
    }
}

 

  • April 25, 2013
  • Like
  • 0

Hi!

I am calling an API of FluidSurvey. when i make a POST request ... it post the request on the fluidSurvey but i didnt get the JSON response. rather it returns nothing. any suggestion??

 

my controller code

public class fluidSurvey{

    public String tst{set;get;}
    public String result{get;set;}
    
    public PageReference chk() {
        getData();
        return null;
    }

    public void getData(){
        String apiKey = 'xxxxxx';
        String pwd = 'xxxxxx';
        String u = 'https://app.fluidsurveys.com/api/v2/surveys/survey_id/responses/';
        
        HttpRequest req = new HttpRequest();
        Http http = new Http();
        HTTPResponse res;
        try{
            req.setEndPoint(u);
            req.setTimeout(20000);
            req.setMethod('POST');
            Blob headerValue = Blob.valueOf(apikey + ':' + pwd);
            String authorizationHeader = 'Basic '+ EncodingUtil.base64Encode(headerValue);
            req.setHeader('Authorization', authorizationHeader);
            req.setHeader('Content-Type', 'application/json');
            req.setHeader('Content-Length','31999');
            
            res = http.send(req); 
            tst= res.toString();
                     
               
        
	       catch(Exception e){
               System.debug('Callout error: '+ e);
               System.debug(tst+'--------'+res);
           }     
        }
       
}

 and the Apex page code is

<apex:page controller="newFS">
<center>
      <apex:form >
          <apex:pageBlock title="New Fluid Surveys API">
              <apex:outputText value="{!tst}"></apex:outputText><br/>
               <apex:pageBlockButtons location="bottom">
                  <apex:commandButton value="Submit" action="{!chk}"/>
               </apex:pageBlockButtons>   
          </apex:pageBlock>
      </apex:form>
      </center>
</apex:page>

 and api documentation link is http://docs.fluidsurveys.com/api/surveys.html#getting-a-list-of-surveys..

  • April 18, 2013
  • Like
  • 0