• betterbhushan
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 7
    Replies

How to make sure the user that installed my salesforce app is registered with my company and purchased subscription.

One way I could think of is I'll email user SHA activation key and when they install app there will be form to enter activation key which could be encrypted and sent to my website end where it will verify if key is in database. Here i don't know how to send post request to my website and how to encrypt key.

What are the other ways?

 

public with sharing class ddDashboard {

 public class phonesterDat{

  String type;
  Integer total;
  Integer valid;

  public String getType() {
   return type;
  }

  public void setType(String type){
   this.type= type;
  }

  public Integer getTotal() {
   return total;
  }
  public void setTotal(Integer total){
   this.total= total;
  }

  public Integer getValid() {
   return valid;
  }
  public void setValid(Integer valid){
   this.valid= valid;
  }

}
 public List<phonesterDat> getEmailData() {
 List<phonesterDat> var1 = new List<phonesterDat>();
 phonesterDat var = new phonesterDat();
 var.setType('Contact Email');
 var.setTotal([select count() from Contact where Email != null]);
 var.setValid([select count() from Contact where Email_Valid__c = true]);
 var1.add(var);
 return var1;
}


public List<phonesterDat> getCompanyData() {
List<phonesterDat> var1 = new List<phonesterDat>();
List<Account> accounts = [select DD_Segment__c from Account];
List<Keyword__c> keywords = [select kw__c from Keyword__c limit 50000];
for (Keyword__c keyword : keywords) {
 phonesterDat var = new phonesterDat();
 String str = keyword.kw__c;
 var.setType(str);
 Integer cnt = 0;
 for (Account acc : accounts) {
  if (acc.DD_Segment__c != null && acc.DD_Segment__c.contains(str)) {
    cnt = cnt+1;
 }
}
var.setTotal(cnt);
var1.add(var);
}
return var1;
}

}

 How to write test coverage for above code?

I am trying to get count of all Accounts which includes certain keyword present (multi-pick list).  But I get the following error:

 

System.LimitException: Too many SOQL queries: 101

 

I'm fairly new to Apex code.  The problem is that I am running SOQL inside a FOR loop, but I'm not quite sure how to resolve it. Apex Code is as below.  Any help would be appreciated.  Thanks.

 

 

public String getType() {
return type;
}
public void setType(String type){
this.type= type;
}

public Integer getTotal() {
return total;
}
public void setTotal(Integer total){
this.total= total;
}

public Integer getValid() {
return valid;
}
public void setValid(Integer valid){
this.valid= valid;
}

}

 

 

public List<phonesterDat> getCompanyData() {
List<phonesterDat> var1 = new List<phonesterDat>();
for (Keyword__c keyword : [select kw__c from Keyword__c]) {
phonesterDat var = new phonesterDat();
String str = keyword.kw__c;
var.setType(str);
var.setTotal([select count() from Account where DD_Segment__c includes (:str)]);
var1.add(var);
}
return var1;
}

 

If you want to whole code base. It is available here http://pastie.org/5151131

I am trying to get count of all Accounts which includes certain keyword present (multi-pick list).  But I get the following error:

 

System.LimitException: Too many SOQL queries: 101

 

I'm fairly new to Apex code.  The problem is that I am running SOQL inside a FOR loop, but I'm not quite sure how to resolve it. Apex Code is as below.  Any help would be appreciated.  Thanks.

 

 

public String getType() {
return type;
}
public void setType(String type){
this.type= type;
}

public Integer getTotal() {
return total;
}
public void setTotal(Integer total){
this.total= total;
}

public Integer getValid() {
return valid;
}
public void setValid(Integer valid){
this.valid= valid;
}

}

 

 

public List<phonesterDat> getCompanyData() {
List<phonesterDat> var1 = new List<phonesterDat>();
for (Keyword__c keyword : [select kw__c from Keyword__c]) {
phonesterDat var = new phonesterDat();
String str = keyword.kw__c;
var.setType(str);
var.setTotal([select count() from Account where DD_Segment__c includes (:str)]);
var1.add(var);
}
return var1;
}

 

If you want to whole code base. It is available here http://pastie.org/5151131

public List<Map<String,Object>> getPhoneData() {
   List<Map<String, Object>> mapp = new List<Map<String, Object>>();
   Map<String, Object> temp = new Map<String, Object>{'type' => 'Account Phone', 'count' => new List<Integer>{[select count() from Account where Phone_valid__c = true], [select count() from Account where Phone != null]}};
   mapp.add(temp);
   Map<String, Object> temp1 = new Map<String, Object>{'type' => 'Account Fax', 'count' => [select count() from Account where Fax_valid__c = true]};
   mapp.add(temp1);
   Map<String, Object> temp2 = new Map<String, Object>{'type' => 'Contact Phone', 'count' => [select count() from Contact where Phone_valid__c = true]};
   mapp.add(temp2);
   Map<String, Object> temp3 = new Map<String, Object>{'type' => 'Contact Mobile', 'count' => [select count() from Contact where Mobile_valid__c = true]};
   mapp.add(temp3);
   Map<String, Object> temp4 = new Map<String, Object>{'type' => 'Contact Fax', 'count' => [select count() from Contact where Fax_valid__c = true]};
   mapp.add(temp4);
   Map<String, Object> temp5 = new Map<String, Object>{'type' => 'Contact Home Phone', 'count' => [select count() from Contact where Home_Phone_valid__c = true]};
   mapp.add(temp5);
   Map<String, Object> temp6 = new Map<String, Object>{'type' => 'Contact Other Phone', 'count' => [select count() from Contact where Other_Phone_valid__c = true]};
   mapp.add(temp6);
   Map<String, Object> temp7 = new Map<String, Object>{'type' => 'Lead Phone', 'count' => [select count() from Lead where Phone_valid__c = true]};
   mapp.add(temp7);
   Map<String, Object> temp8 = new Map<String, Object>{'type' => 'Lead Mobile', 'count' => [select count() from Lead where Mobile_valid__c = true]};
   mapp.add(temp8);
   Map<String, Object> temp9 = new Map<String, Object>{'type' => 'Lead Fax', 'count' => [select count() from Account where Fax_valid__c = true]};
       mapp.add(temp9);
   return mapp;
   }
   

 Now I want to iterate over Map in Visualforce Page whic I am doing like this:

 

            <apex:pageBlockTable title="Results" value="{!PhoneData}" var="d" >     
            <apex:column value="{!d['type']}" headerValue="Type" />
            <apex:column value="{!d['count']}" headerValue="Total"/>
           
            <apex:column value="{!d}" headerValue="everything"/>
            
          
            
            </apex:pageBlockTable><br/><br/><br/>

 Now, d['count'] is List. I want 1st value of this list 

 

say d['count'] = [1,2,3]

 

How will i get that value in VF? I tried d['count'].get(0)

I have custom object KeywordAccountAssociation__c. This object has three fields

  1. Account__c - Master-Detail(Account)
  2. Keyword__c - Master-Detail(Keyword)
  3. Compositecp__c - Text(255) (External ID) (Unique Case Sensitive)

I have a custom field in Account

  • DD_Segment__c - multi-picklist

Now I want to update (Insert is fine too) values of DD_Segment__c wheneverKeywordAccountAssociation__c is updated. I could write trigger for this but I don't know how? I am new to Salesforce Development and my background is ruby (so getting accustomed to apex is bit difficult for me).

KeywordAccountAssociation__c has multiple rows of Account__c which has same account_id and those account_id are related to a record of custom object Keyword__c. I want to get all keywords related to one account and update in its (account's) multi-picklist. How can I achieve this? If you have doubts about this please do ask. Thanks!

I am trying to create trigger but getting..

 

Error: Compile Error: unexpected token: 'trigger' at line 1 column 0

 

the code:

 

trigger keywordAccountUpdate on KeywordAccountAssociation__c (after insert, after update){
    set<id> = new set<id>();
    for (KeywordAccountAssociation__c a : Trigger.new)
        accountIds.put(a.Account__c);
    map<id,Account> accountMap = new map<id,Account>([select id, DD_Segment__c from Account where id in :accountIds]);
    for (KeywordAccountAssociation__c kaa : Trigger.new){
        if (AccountMap.containskey(kaa.Account__c)){
            Account thisAccount = AccountMap.get(kaa.Account__c);
            String s = thisAccount.DD_Segment__c + ';new value'; // Always add value
            if ((thisAccount.DD_Segment__c).contains('second value')
                s += ';second value';
            AccountsToUpdate.add(new Account(id=thisAccount.id, DD_Segment__c = s));
        }
    }
}

 

Can we fetch all the accounts and store it in external database of my application using Apex Batch? If yes could you write a bit of code to get me started. Thanks!

Has anybody connected to Salesforce through Rails 3 App via oauth? Could you please post code for doing same. I am trying to same but I get some error below is my code. 

 

def oauth_client
        consumer_key = '....'
        consumer_secret = '....'
        oauth_options = {
          :site               => 'https://login.salesforce.com',
          :scheme             => :body,
          :request_token_path => '/_nc_external/system/security/oauth/RequestTokenHandler',
          :authorize_path     => '/setup/secur/RemoteAccessAuthorizationPage.apexp',
          :access_token_path  => '/_nc_external/system/security/oauth/AccessTokenHandler',
        }
        OAuth::Consumer.new consumer_key, consumer_secret, oauth_options
      end

      def oauth_redirect_uri
        uri = URI.parse(request.url)
        uri.path = '/sfdc/oauth_callback'
        uri.query = nil
        #  uri = "http://localhost:3000/sfdc/oauth_callback"
        uri.to_s
      end

      def oauth_connect
        consumer_key    = '...' # from SalesForce
        consumer = oauth_client
        request = consumer.get_request_token
        redirect_to request.authorize_url(
        :redirect_uri => oauth_redirect_uri,
        :oauth_consumer_key => consumer_key
        )
      end

      def oauth_callback  
        access = request.get_access_token :oauth_verifier => params[:oauth_verifier]
        p access
        render :text => access.token
      end

 

Error undefined method get_access_token for #<ActionDispatch::Request:0x12b79f370>. the request variable is nil here. How do I get it back?

How do I edit related list label without modufying label of custom object?

How to edit only related list label without modfigying label of object.

I have this specific problem where I have two Objects 1) Keyword__c and 2) Account. They have master-detail relationship. Now I want to create a table where I want to display each value from Keyword__c in one column and count of Account for that from Master-detail relationship in other column. I tried something like below but I haven't been successful.

 

My Visualforce page has 

 

<apex:pageBlockTable title="Results" value="{!AllKeyword}" var="k">
<apex:column value="{!k.kw__c}" headerValue="Keywords" />
<apex:column headerValue="Count" value="{!KeywordCount}">
<apex:param name="kw" value="{!k.kw__c}"/>
</apex:column>
</apex:pageBlockTable>

  but it says 

 

Error: You may specify either a ''value'' attribute or a body for the column component, but not both	

  

and controller has 

 

public Integer getKeywordCount() {
  Integer cnt;
  String keyID;
  String kw = ApexPages.currentPage().getParameters().get('kw');  
   keyID = [Select Id from Keyword__c where kw__c = kw];  
   cnt = [Select count() FROM KeywordAccountAssociation__c Where Keyword__c = keyID];
  return cnt;
  }

 

but it says 

 

Error: companyDashboard Compile Error: unexpected token: 'kw'

 

Appreciate any help.

I am using oauth2 and databaseforcom gem to connect with Salesforce.com and extract user's data. But my access_token is not returning all the parameters it is supposed to retrun viz. instance_url. Below is my authentication code.

class SfdcController < ApplicationController
  OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
  #include Databasedotcom::Rails::Controller
 # $sfdc_app_config=YAML.load_file("#{Rails.root.to_s}/config/databasedotcom.yml")


  def oauth_client
    consumer_key = ''
    consumer_secret = ''
    OAuth2::Client.new(consumer_key, consumer_secret, {:site => 'https://login.salesforce.com', :authorize_path => '/services/oauth2/authorize', :access_token_path => '/services/oauth2/token', :ssl=>{:verify => false }})
  end

  #
  #Creates the uri which will be the redirect path
  #
  def oauth_redirect_uri
    uri = URI.parse(request.url)
    uri.path = '/sfdc/oauth_callback'
    uri.query = nil
    uri="http://localhost:3000/sfdc/oauth_callback"
    uri.to_s
  end
  #
  #This is the action which will fetch the access token.
  #
  def oauth_connect
    uri = URI.parse(request.url)
    consumer_key = ''
    redirect_to oauth_client.web_server.authorize_url(
    :redirect_uri => oauth_redirect_uri,
    :client_id => consumer_key,
    :response_type => 'code'
    )
  end

  #
  #This is the action which will handle the callback once the authorization is done
  #
  def oauth_callback
    access_token = oauth_client.web_server.get_access_token(params[:code], :redirect_uri => oauth_redirect_uri, :grant_type => 'authorization_code')
    client = Databasedotcom::Client.new("#{Rails.root}/config/databasedotcom.yml")
    client.authenticate :token => access_token.token, :instance_url => "http://ap1.salesforce.com"
    client.materialize('Account')
    render :text => access_token.token
  end
end

 

and access_token it gives is 

 

<OAuth2::AccessToken:0x12b96f830 @refresh_token="5Aep8617VFpoP.M.4tK4KlWuvvwufeW5s3R_RMldf5nRDDnuQ1gZ08F.GQXQaIveDsyLrv4W5fShQ==", @token="00D90000000bfa4!AQMAQMDfipmZ2129JCGNhXecqOnYAbeImhSLTA1j5rWxB9NX2esGlgQkIHVfCyNMQe0ETJQJb16m7v74sgjX5ErUZJzOUm0h", @client=#<OAuth2::Client:0x12b85a120 @options={:authorize_path=>"/services/oauth2/authorize", :ssl=>{:verify=>false}, :access_token_path=>"/services/oauth2/token"}, @site="https://login.salesforce.com", @connection=#<Faraday::Connection:0x12b85a0d0 @options={}, @path_prefix="/", @scheme="https", @host="login.salesforce.com", @headers={}, @port=nil, @parallel_manager=nil, @builder=#<Faraday::Builder:0x12b859c70 @handlers=[#<Proc:0x0000000102680fd0@/Users/bhushan/.rvm/gems/ruby-1.8.7-p352@companyplus/gems/faraday-0.4.6/lib/faraday/builder.rb:17>, #<Proc:0x000000010267ee60@/Users/bhushan/.rvm/gems/ruby-1.8.7-p352@companyplus/gems/faraday-0.4.6/lib/faraday/builder.rb:55>]>, @ssl={}, @params={}>, @secret="7223836429183804591", @id="3MVG9Y6d_Btp4xp5____________________________________Pft9QvURaQN", @json=nil>, @expires_in=nil>

 

when I do

 

access_token["instance_url"]

 

I get 

 

undefined method `[]' for #<OAuth2::AccessToken:0x12b99be80>

 

 

what is wrong?

public with sharing class ddDashboard {

 public class phonesterDat{

  String type;
  Integer total;
  Integer valid;

  public String getType() {
   return type;
  }

  public void setType(String type){
   this.type= type;
  }

  public Integer getTotal() {
   return total;
  }
  public void setTotal(Integer total){
   this.total= total;
  }

  public Integer getValid() {
   return valid;
  }
  public void setValid(Integer valid){
   this.valid= valid;
  }

}
 public List<phonesterDat> getEmailData() {
 List<phonesterDat> var1 = new List<phonesterDat>();
 phonesterDat var = new phonesterDat();
 var.setType('Contact Email');
 var.setTotal([select count() from Contact where Email != null]);
 var.setValid([select count() from Contact where Email_Valid__c = true]);
 var1.add(var);
 return var1;
}


public List<phonesterDat> getCompanyData() {
List<phonesterDat> var1 = new List<phonesterDat>();
List<Account> accounts = [select DD_Segment__c from Account];
List<Keyword__c> keywords = [select kw__c from Keyword__c limit 50000];
for (Keyword__c keyword : keywords) {
 phonesterDat var = new phonesterDat();
 String str = keyword.kw__c;
 var.setType(str);
 Integer cnt = 0;
 for (Account acc : accounts) {
  if (acc.DD_Segment__c != null && acc.DD_Segment__c.contains(str)) {
    cnt = cnt+1;
 }
}
var.setTotal(cnt);
var1.add(var);
}
return var1;
}

}

 How to write test coverage for above code?

I am using the databasedotcom gem and Ruby 1.9.2 I execute this query: quer = "SELECT SUM(MRR__c) FROM Account WHERE Type = 'Customer'" mrr = client.query quer it returns this object: => [#0x000001035dfa80>] How do I work with this object? 0x000001035dfa80>

I have this specific problem where I have two Objects 1) Keyword__c and 2) Account. They have master-detail relationship. Now I want to create a table where I want to display each value from Keyword__c in one column and count of Account for that from Master-detail relationship in other column. I tried something like below but I haven't been successful.

 

My Visualforce page has 

 

<apex:pageBlockTable title="Results" value="{!AllKeyword}" var="k">
<apex:column value="{!k.kw__c}" headerValue="Keywords" />
<apex:column headerValue="Count" value="{!KeywordCount}">
<apex:param name="kw" value="{!k.kw__c}"/>
</apex:column>
</apex:pageBlockTable>

  but it says 

 

Error: You may specify either a ''value'' attribute or a body for the column component, but not both	

  

and controller has 

 

public Integer getKeywordCount() {
  Integer cnt;
  String keyID;
  String kw = ApexPages.currentPage().getParameters().get('kw');  
   keyID = [Select Id from Keyword__c where kw__c = kw];  
   cnt = [Select count() FROM KeywordAccountAssociation__c Where Keyword__c = keyID];
  return cnt;
  }

 

but it says 

 

Error: companyDashboard Compile Error: unexpected token: 'kw'

 

Appreciate any help.

I'm trying to set up a remote access application so I can use OAuth and then the API from my application. I set up a brand-new developer account today and followed the instructions here:

 

https://na7.salesforce.com/help/doc/user_ed.jsp?section=help&target=remoteaccess_authenticate.htm&loc=help&hash=access_data

 

I'm using an OAuth library in Ruby (the 'oauth' gem).

 

So far, I've been able to succesfully retrieve a request token, and when I use that token I can authenticate with salesforce using the login URL metnioned. However, after succesful login my browser gets redirected to an error page (it looks like a few redirects happen, but I can't tell exactly). Finally I get an error message that says "Remote Access Authorization Error" and then "There was a problem setting up your remote access". The URL in the browser looks like this:

 

https://na7.salesforce.com/setup/secur/RemoteAccessErrorPage.apexp?oauth_error_code=1800

 

This error code, alas, is not listed amongst those in the documentation.

 

This happens whether I go through the login step as my developer user, or as a friend's user on an Enterprise account.

 

Any ideas about what's going on here?

 

I can't seem to get past this problem.  Any ideas?

 

Thanks,

Mike