-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
5Questions
-
15Replies
Rendering in apex:outputPanel
vf page:
apex:pageBlockTable value="{!Opportunity}" var="op" align="center" style="border:none;"
apex:column
apex:outputPanel rendered="{!IF(CONTAINS(mapKey,op.name)=True,False,True)}"
apex:commandButton value="Add to LY Prospect List" action="{!show}" rerender="popup" onclick="this.style.visibility = 'hidden' "
apex:param name="OppName" value="{!op.id}" assignTo="{!opid}"/
/apex:commandButton
/apex:OutputPanel
Apex Page:
public string mapkey;
for(Companies com: compList){
if(MrktRatngMap.containsKey(com.ComName)==True){
mapKey=mapKey+' '+com.ComName;
}
}
Q Please let me know the meaning of the statement: apex:outputPanel rendered="{!IF(CONTAINS(mapKey,op.name)=True,False,True)}"
apex:pageBlockTable value="{!Opportunity}" var="op" align="center" style="border:none;"
apex:column
apex:outputPanel rendered="{!IF(CONTAINS(mapKey,op.name)=True,False,True)}"
apex:commandButton value="Add to LY Prospect List" action="{!show}" rerender="popup" onclick="this.style.visibility = 'hidden' "
apex:param name="OppName" value="{!op.id}" assignTo="{!opid}"/
/apex:commandButton
/apex:OutputPanel
Apex Page:
public string mapkey;
for(Companies com: compList){
if(MrktRatngMap.containsKey(com.ComName)==True){
mapKey=mapKey+' '+com.ComName;
}
}
Q Please let me know the meaning of the statement: apex:outputPanel rendered="{!IF(CONTAINS(mapKey,op.name)=True,False,True)}"
- LinkYogi
- June 24, 2015
- Like
- 0
variable is not incrementing in apex class
Hi All,
My issue is variable(counter) is not incrementing.
I am running the class in batches, but debug statement 'counter prev' only gives 1.
Apex Code:
global class Update_Records{
//**********************
//Declare Variables
//*********************
public string testmrksig{set;get;}
public string x;
public string y;
public List<opportunity> OppList {set;get;}
public string oppString{get;set;}
public string respons{get;set;}
public List<Opportunity> opper = new list<opportunity>();
public Map<string,Decimal> MrktRatngMap{get;set;}
public Map<string,string> CompUrlMap{get;set;}
public Map<string,string>dossierurlMap{get;set;}
public Map<string,string>dossierurlsummarymap{get;set;}
public string mapKey{get;set;}
ID userId =UserInfo.getUserId();
public List<SelectOption> AvilIns { get; set; }
public String SeltIns {get;set;}
private ApexPages.StandardController stdController;
//***************
//Constructor
//***************
public Update_Records()
{
MrktRatngMap = new Map<string,Decimal>();
CompUrlMap = new Map<string,string>();
dossierurlMap = new map<string,string>();
dossierurlsummarymap = new map<string,string>();
//OppData();
Opportunity ope= new opportunity();
}
//***********************************************************************
//Method to send request and parse response related to opportunities
//***********************************************************************
public void OppData(){
Integer counter=0;
Integer batchsize=150;
OppList =[select id, name, Marketing_Signal__c from opportunity];
for(Opportunity opp: OppList)
{
counter+=1;
if(opp.name <> null){
if(oppString == null){
String url = EncodingUtil.urlEncode(opp.name,'UTF-8');
oppString = '&names[]='+url;
}
else{
String url = EncodingUtil.urlEncode(opp.name,'UTF-8');
oppString = oppString + '&names[]='+url;
}
}
system.debug('counter prev** '+counter);
if (math.mod(counter,batchsize)==0)
{
system.debug('counter** '+counter);
list<Marketingsignalwrapper>mswlist= new list <Marketingsignalwrapper>();
for(opportunity oop:OppList)
{
if(MrktRatngMap.containsKey(oop.name)!=True ){
oop.Marketing_Signal__c = MrktRatngMap.get(oop.name);
}
Marketingsignalwrapper Temp = new Marketingsignalwrapper (oop);
mswlist.add(temp);
}
mswlist.sort();
opper.clear();
for (Marketingsignalwrapper o1 : mswlist )
{
opportunity o2= new opportunity();
{
opper.add(o1.oppy);
}
}
HttpRequest htreq = new HttpRequest();
String initialUrl = 'https://app.linkyogi.com/api/v1/companies/search?userId=' + UserId + oppString;
htreq.setEndpoint(initialUrl);
htreq.setMethod('POST');
htreq.setHeader('APIKEY', '67546e2238254a5c557205d624814a32ad35cf96');
Http http = new Http();
try
{
system.debug('response statement**** ');
HttpResponse res=new HttpResponse();
if(!Test.IsRunningTest())
res = http.send(htreq);
else
res.setBody(//);
respons = res.getBody();
system.debug('*******----------'+respons);
string dossier_url;
string dossier_summary_url;
string marketing_signal;
string company_url;
string present;
string names;
boolean nameCheck = False;
List<Companies> compList = new List<Companies>();
JSONparser parser = JSON.createparser(respons);
while (parser.nextToken() != null) {
if (parser.getCurrentToken() == JSONToken.START_OBJECT){
while(parser.nextToken() != null){
if (parser.getCurrentToken() == JSONToken.FIELD_NAME ) {
if(nameCheck == False){
names = parser.getText();
nameCheck = True;
}
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'dossier_url')) {
parser.nextToken();
dossier_url = parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'dossier_summary_url')) {
parser.nextToken();
dossier_summary_url= parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'marketing_signal')) {
parser.nextToken();
marketing_signal = parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'company_url')) {
parser.nextToken();
company_url = parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'present')) {
parser.nextToken();
present= parser.getText();
}
if(parser.getCurrentToken() == JSONToken.END_OBJECT){
Companies com = new Companies(names,dossier_url ,dossier_summary_url,marketing_signal, company_url,present);
compList.add(com);
dossier_url = null;
dossier_summary_url=null;
marketing_signal = null;
company_url = null;
present = null;
nameCheck = False;
}
}
}
}
for(Companies com: compList){
if(com.present == 'true'){
MrktRatngMap.put(com.ComName, Decimal.ValueOf(com.marketing_signal));
CompUrlMap.put(com.ComName, com.company_url);
dossierurlsummarymap.put(com.ComName, com.dossier_summary_url); //prad
dossierurlMap.put(com.ComName, com.dossier_url );
x= dossierurlMap.get(com.ComName);
system.debug('----------------------------------------------> x'+x);
}
if(MrktRatngMap.containsKey(com.ComName)==True){
mapKey=mapKey+' '+com.ComName;
testmrksig+='::'+com.ComName+'::'+com.marketing_signal;
}
}
}
catch(System.CalloutException e)
{
System.debug('A Callout Exception of method Oppdata: ' + e.getMessage());
}
}
counter=0;
}
}
//*************************************
//Inner class to Combine Json Response
//*************************************
public class Companies{
public string dossier_url {get;set;}
public string dossier_summary_url{get;set;}
public string marketing_signal {get;set;}
public string company_url{get;set;}
public string present {get;set;}
public string ComName{get;set;}
public Companies( string nm,string durl,string dsurl, string MarkSg, string comUrl,string prsnt){
this.dossier_url = durl;
this.dossier_summary_url=dsurl;
this.marketing_signal = MarkSg;
this.company_url = comUrl;
this.present = prsnt;
this.ComName = nm;
}
}
global class Marketingsignalwrapper implements Comparable
{
public opportunity oppy{get;set;}
global Marketingsignalwrapper(opportunity op) {
oppy = op;
}
global Integer compareTo(Object compareTo)
{
Marketingsignalwrapper msw=(Marketingsignalwrapper)compareTo;
Integer returnValue = 0;
if (oppy.Marketing_Signal__c>msw.oppy.Marketing_Signal__c) {
// Set return value to a positive value.
returnValue = 1;
} else if (oppy.Marketing_Signal__c< msw.oppy.Marketing_Signal__c){
//Set return value to a negative value.
returnValue = -1;
}
return returnValue;
}
}
}
My issue is variable(counter) is not incrementing.
I am running the class in batches, but debug statement 'counter prev' only gives 1.
Apex Code:
global class Update_Records{
//**********************
//Declare Variables
//*********************
public string testmrksig{set;get;}
public string x;
public string y;
public List<opportunity> OppList {set;get;}
public string oppString{get;set;}
public string respons{get;set;}
public List<Opportunity> opper = new list<opportunity>();
public Map<string,Decimal> MrktRatngMap{get;set;}
public Map<string,string> CompUrlMap{get;set;}
public Map<string,string>dossierurlMap{get;set;}
public Map<string,string>dossierurlsummarymap{get;set;}
public string mapKey{get;set;}
ID userId =UserInfo.getUserId();
public List<SelectOption> AvilIns { get; set; }
public String SeltIns {get;set;}
private ApexPages.StandardController stdController;
//***************
//Constructor
//***************
public Update_Records()
{
MrktRatngMap = new Map<string,Decimal>();
CompUrlMap = new Map<string,string>();
dossierurlMap = new map<string,string>();
dossierurlsummarymap = new map<string,string>();
//OppData();
Opportunity ope= new opportunity();
}
//***********************************************************************
//Method to send request and parse response related to opportunities
//***********************************************************************
public void OppData(){
Integer counter=0;
Integer batchsize=150;
OppList =[select id, name, Marketing_Signal__c from opportunity];
for(Opportunity opp: OppList)
{
counter+=1;
if(opp.name <> null){
if(oppString == null){
String url = EncodingUtil.urlEncode(opp.name,'UTF-8');
oppString = '&names[]='+url;
}
else{
String url = EncodingUtil.urlEncode(opp.name,'UTF-8');
oppString = oppString + '&names[]='+url;
}
}
system.debug('counter prev** '+counter);
if (math.mod(counter,batchsize)==0)
{
system.debug('counter** '+counter);
list<Marketingsignalwrapper>mswlist= new list <Marketingsignalwrapper>();
for(opportunity oop:OppList)
{
if(MrktRatngMap.containsKey(oop.name)!=True ){
oop.Marketing_Signal__c = MrktRatngMap.get(oop.name);
}
Marketingsignalwrapper Temp = new Marketingsignalwrapper (oop);
mswlist.add(temp);
}
mswlist.sort();
opper.clear();
for (Marketingsignalwrapper o1 : mswlist )
{
opportunity o2= new opportunity();
{
opper.add(o1.oppy);
}
}
HttpRequest htreq = new HttpRequest();
String initialUrl = 'https://app.linkyogi.com/api/v1/companies/search?userId=' + UserId + oppString;
htreq.setEndpoint(initialUrl);
htreq.setMethod('POST');
htreq.setHeader('APIKEY', '67546e2238254a5c557205d624814a32ad35cf96');
Http http = new Http();
try
{
system.debug('response statement**** ');
HttpResponse res=new HttpResponse();
if(!Test.IsRunningTest())
res = http.send(htreq);
else
res.setBody(//);
respons = res.getBody();
system.debug('*******----------'+respons);
string dossier_url;
string dossier_summary_url;
string marketing_signal;
string company_url;
string present;
string names;
boolean nameCheck = False;
List<Companies> compList = new List<Companies>();
JSONparser parser = JSON.createparser(respons);
while (parser.nextToken() != null) {
if (parser.getCurrentToken() == JSONToken.START_OBJECT){
while(parser.nextToken() != null){
if (parser.getCurrentToken() == JSONToken.FIELD_NAME ) {
if(nameCheck == False){
names = parser.getText();
nameCheck = True;
}
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'dossier_url')) {
parser.nextToken();
dossier_url = parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'dossier_summary_url')) {
parser.nextToken();
dossier_summary_url= parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'marketing_signal')) {
parser.nextToken();
marketing_signal = parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'company_url')) {
parser.nextToken();
company_url = parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'present')) {
parser.nextToken();
present= parser.getText();
}
if(parser.getCurrentToken() == JSONToken.END_OBJECT){
Companies com = new Companies(names,dossier_url ,dossier_summary_url,marketing_signal, company_url,present);
compList.add(com);
dossier_url = null;
dossier_summary_url=null;
marketing_signal = null;
company_url = null;
present = null;
nameCheck = False;
}
}
}
}
for(Companies com: compList){
if(com.present == 'true'){
MrktRatngMap.put(com.ComName, Decimal.ValueOf(com.marketing_signal));
CompUrlMap.put(com.ComName, com.company_url);
dossierurlsummarymap.put(com.ComName, com.dossier_summary_url); //prad
dossierurlMap.put(com.ComName, com.dossier_url );
x= dossierurlMap.get(com.ComName);
system.debug('----------------------------------------------> x'+x);
}
if(MrktRatngMap.containsKey(com.ComName)==True){
mapKey=mapKey+' '+com.ComName;
testmrksig+='::'+com.ComName+'::'+com.marketing_signal;
}
}
}
catch(System.CalloutException e)
{
System.debug('A Callout Exception of method Oppdata: ' + e.getMessage());
}
}
counter=0;
}
}
//*************************************
//Inner class to Combine Json Response
//*************************************
public class Companies{
public string dossier_url {get;set;}
public string dossier_summary_url{get;set;}
public string marketing_signal {get;set;}
public string company_url{get;set;}
public string present {get;set;}
public string ComName{get;set;}
public Companies( string nm,string durl,string dsurl, string MarkSg, string comUrl,string prsnt){
this.dossier_url = durl;
this.dossier_summary_url=dsurl;
this.marketing_signal = MarkSg;
this.company_url = comUrl;
this.present = prsnt;
this.ComName = nm;
}
}
global class Marketingsignalwrapper implements Comparable
{
public opportunity oppy{get;set;}
global Marketingsignalwrapper(opportunity op) {
oppy = op;
}
global Integer compareTo(Object compareTo)
{
Marketingsignalwrapper msw=(Marketingsignalwrapper)compareTo;
Integer returnValue = 0;
if (oppy.Marketing_Signal__c>msw.oppy.Marketing_Signal__c) {
// Set return value to a positive value.
returnValue = 1;
} else if (oppy.Marketing_Signal__c< msw.oppy.Marketing_Signal__c){
//Set return value to a negative value.
returnValue = -1;
}
return returnValue;
}
}
}
- LinkYogi
- June 12, 2015
- Like
- 0
Batch class is not updating records for large number of records
Hi All,
I facing an issue that batch class is not updating records for large number of records.
Batch Class:
global class oppwithmarketing implements Database.Batchable<sObject>, Database.AllowsCallouts, Database.Stateful
{
global Map<string,Decimal> MrktSignals;
global map<string,string>Dosierurl;
global map<string,string>DosierSummaryurl;
global final string query = 'select id, name, Marketing_Signal__c,dosierurl__c,dosiersummaryurl__c from opportunity';
global Database.QueryLocator start(Database.BatchableContext BC)
{
Update_Records op = new Update_Records();
op.OppData();
MrktSignals = op.MrktRatngMap.clone();
system.debug('MrktSignals** '+MrktSignals );
Dosierurl= op.dossierurlMap.clone();
system.debug('Dosierurl** '+Dosierurl);
DosierSummaryurl= op.dossierurlsummarymap.clone();
system.debug('DosierSummaryurl** '+DosierSummaryurl);
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> batch)
{
try
{
for(Sobject so :batch)
{
opportunity opp1 = (opportunity)so;
if(MrktSignals.containsKey(opp1.name) && MrktSignals.get(opp1.name) <> null){
so.put('Marketing_Signal__c',MrktSignals.get(opp1.name));
}
if(Dosierurl.containsKey(opp1.name) && Dosierurl.get(opp1.name) <> null){
so.put('dosierurl__c',Dosierurl.get(opp1.name));
}
if(DosierSummaryurl.containsKey(opp1.name) && DosierSummaryurl.get(opp1.name) <> null){
so.put('dosiersummaryurl__c',DosierSummaryurl.get(opp1.name));
}
}
if (batch.size()>0)
{
Database.SaveResult[] list_save=Database.Update(batch, false);
for (Database.SaveResult sr: list_save)
{
if (sr.isSuccess())
{
system.debug( ' **** ' + sr.getId());
}
else
{
for (Database.Error err: sr.getErrors())
system.debug(err.getStatusCode()+' **** '+err.getMessage()+ ' **** '+err.getFields());
//system.debug(sr.getStatusCode()+' **** '+sr.getMessage());
}
}
}
}
catch(System.QueryException e)
{
System.debug('System.QueryException on oppwithmarketing batch class ' + e);
}
}
global void finish(Database.BatchableContext BC) {
system.debug(LoggingLevel.WARN, 'Batch Job Complete');
}
}
Developer Console:
Execute:
oppwithmarketing b = new oppwithmarketing();
database.executebatch(b);
Note: When I run the batch class 'oppwithmarketing' for 100 records, it works. But, for 500 or more records, it is not updating the records. Although, I am getting no error.
I facing an issue that batch class is not updating records for large number of records.
Batch Class:
global class oppwithmarketing implements Database.Batchable<sObject>, Database.AllowsCallouts, Database.Stateful
{
global Map<string,Decimal> MrktSignals;
global map<string,string>Dosierurl;
global map<string,string>DosierSummaryurl;
global final string query = 'select id, name, Marketing_Signal__c,dosierurl__c,dosiersummaryurl__c from opportunity';
global Database.QueryLocator start(Database.BatchableContext BC)
{
Update_Records op = new Update_Records();
op.OppData();
MrktSignals = op.MrktRatngMap.clone();
system.debug('MrktSignals** '+MrktSignals );
Dosierurl= op.dossierurlMap.clone();
system.debug('Dosierurl** '+Dosierurl);
DosierSummaryurl= op.dossierurlsummarymap.clone();
system.debug('DosierSummaryurl** '+DosierSummaryurl);
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> batch)
{
try
{
for(Sobject so :batch)
{
opportunity opp1 = (opportunity)so;
if(MrktSignals.containsKey(opp1.name) && MrktSignals.get(opp1.name) <> null){
so.put('Marketing_Signal__c',MrktSignals.get(opp1.name));
}
if(Dosierurl.containsKey(opp1.name) && Dosierurl.get(opp1.name) <> null){
so.put('dosierurl__c',Dosierurl.get(opp1.name));
}
if(DosierSummaryurl.containsKey(opp1.name) && DosierSummaryurl.get(opp1.name) <> null){
so.put('dosiersummaryurl__c',DosierSummaryurl.get(opp1.name));
}
}
if (batch.size()>0)
{
Database.SaveResult[] list_save=Database.Update(batch, false);
for (Database.SaveResult sr: list_save)
{
if (sr.isSuccess())
{
system.debug( ' **** ' + sr.getId());
}
else
{
for (Database.Error err: sr.getErrors())
system.debug(err.getStatusCode()+' **** '+err.getMessage()+ ' **** '+err.getFields());
//system.debug(sr.getStatusCode()+' **** '+sr.getMessage());
}
}
}
}
catch(System.QueryException e)
{
System.debug('System.QueryException on oppwithmarketing batch class ' + e);
}
}
global void finish(Database.BatchableContext BC) {
system.debug(LoggingLevel.WARN, 'Batch Job Complete');
}
}
Developer Console:
Execute:
oppwithmarketing b = new oppwithmarketing();
database.executebatch(b);
Note: When I run the batch class 'oppwithmarketing' for 100 records, it works. But, for 500 or more records, it is not updating the records. Although, I am getting no error.
- LinkYogi
- June 11, 2015
- Like
- 0
onclick function not working for commandlink
Hi All,
Below is my code:
VF Page:
<apex:page controller="SummaryPdfDispController" standardStylesheets="false" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock Id="status1">
<apex:commandLink action="{!SendEmail}" value="Email Dossier" reRender="status1" styleClass="element" onclick="this.value = 'Sending...'"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Note:
1. If I omit the onclick functionality then action- SendEmail is called.
2. I could not use commandbutton as per project purpose.
3. I have used javascript on onclick functionality, but it did not work.
Below is my code:
VF Page:
<apex:page controller="SummaryPdfDispController" standardStylesheets="false" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock Id="status1">
<apex:commandLink action="{!SendEmail}" value="Email Dossier" reRender="status1" styleClass="element" onclick="this.value = 'Sending...'"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Note:
1. If I omit the onclick functionality then action- SendEmail is called.
2. I could not use commandbutton as per project purpose.
3. I have used javascript on onclick functionality, but it did not work.
- LinkYogi
- June 03, 2015
- Like
- 0
code to download pdf by rest service
Hi All,
Below is my code:
VF Page:
<apex:page controller="SummaryPdfDispController" standardStylesheets="false" showHeader="false" sidebar="false">
<apex:form Id="status">
<apex:outputLink value="{!URLFOR($Action.Attachment.Download, attachmentId)}" target="_blank" styleClass="element">Download Dossier</apex:outputLink>
</apex:form>
</apex:page>
Apex Code:
public class SummaryPdfDispController {
public class SummaryPdfDispController
{ //===============================
//===Declare Variables===========
//===============================
public string companyUrl1 {set;get;}
public string cmpname {set;get;}
public string status {set;get;}
public integer statuscode {set;get;}
public String blobResult {set;get;}
public string PageId{get;set;}
public string blb{get;set;}
public id attachmentId{get;set;}
public string Accname{get;set;}
public string htmlRes{get;set;}
public string CssRes{get;set;}
public string EmailResponse{get;set;}
transient blob downloadResponse;
public string url;
public List<attachment> attachmentList= new List<attachment>();
public attachment at{get;set;}
//=============================================================== //===Constructor to show Html and Css response on vf page======== //===============================================================
public SummaryPdfDispController ()
{
cmpname=Apexpages.currentPage().getParameters().get('Cmp');
PageId = Apexpages.currentPage().getParameters().get('ids');
system.debug('********-----PageId'+ PageId); system.debug('====cmpname====='+cmpname);
if(PageId <> null && PageId <> '')
{
url = [select link_yogi__dosiersummaryurl__c,Account.name from opportunity where id=:PageId].link_yogi__dosiersummaryurl__c;
}
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
req.setHeader('APIKEY', '67546e2238254a5c557205d624814a32ad35cf96');
Http http = new Http();
req.setTimeout(120000);
try {
HttpResponse res=new HttpResponse();
if(!Test.IsRunningTest())
res = http.send(req);
else
//
system.debug('==response=='+res.getbody());
blb=res.getBody();
system.debug('==========blb============>'+ blb);
status=res.getStatus();
statuscode=res.getStatusCode();
JSONParser parser = JSON.createParser(res.getBody());
while (parser.nextToken() != null)
{
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'html'))
{
parser.nextToken();
htmlRes= parser.gettext();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'css'))
{
parser.nextToken();
CssRes = parser.gettext();
}
}
system.debug('==Html==='+htmlRes); system.debug('====CSS Response=='+CssRes);
}
catch(System.CalloutException e)
{
System.debug('System.Callout Exception for SummaryPdfDispController Constructor ' + e.getMessage());
}
}
//========================================
//===Method to Download Dossier as Pdf====
//========================================
public void DownloadPdf()
{
string url = [select link_yogi__dosierurl__c,Account.name from opportunity where id=:PageId].link_yogi__dosierurl__c]; HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
req.setHeader('APIKEY', '67546e2238254a5c557205d624814a32ad35cf96');
Http http = new Http();
req.setTimeout(120000);
try
{
HttpResponse res=new HttpResponse();
if(!Test.IsRunningTest())
res = http.send(req);
else
// ----
system.debug('==response=='+res.getbody());
downloadResponse =res.getBodyAsBlob();
status=res.getStatus();
statuscode=res.getStatusCode();
system.debug('===Response==='+downloadResponse);
}
catch(System.CalloutException e)
{
System.debug('System.Callout Exception for DownloadPdf Method ' + e.getMessage());
}
if(downloadResponse <> null)
{
attachmentList=[select id,name,parentid from attachment where parentId =: PageId AND name=: cmpname+'.pdf']; system.debug('==Existing company Attachments to delete=='+attachmentList);
if(attachmentList.isEmpty() == False)
{
try
{
delete attachmentList;
}
catch(System.QueryException e)
{
System.debug('System.QueryException for DownloadPdf Method on delete operation ' + e);
}
}
at= new attachment();
at.parentId = PageId;
at.body = downloadResponse;
at.name = cmpname+'.pdf';
try
{
insert at;
}
catch(System.QueryException e)
{
System.debug('System.QueryException for DownloadPdf Method on insert operation ' + e);
}
attachmentId = at.id;
downloadResponse= null;
at= null;
system.debug('====Attachment====='+at);
}
}
}
Below is my code:
VF Page:
<apex:page controller="SummaryPdfDispController" standardStylesheets="false" showHeader="false" sidebar="false">
<apex:form Id="status">
<apex:outputLink value="{!URLFOR($Action.Attachment.Download, attachmentId)}" target="_blank" styleClass="element">Download Dossier</apex:outputLink>
</apex:form>
</apex:page>
Apex Code:
public class SummaryPdfDispController {
public class SummaryPdfDispController
{ //===============================
//===Declare Variables===========
//===============================
public string companyUrl1 {set;get;}
public string cmpname {set;get;}
public string status {set;get;}
public integer statuscode {set;get;}
public String blobResult {set;get;}
public string PageId{get;set;}
public string blb{get;set;}
public id attachmentId{get;set;}
public string Accname{get;set;}
public string htmlRes{get;set;}
public string CssRes{get;set;}
public string EmailResponse{get;set;}
transient blob downloadResponse;
public string url;
public List<attachment> attachmentList= new List<attachment>();
public attachment at{get;set;}
//=============================================================== //===Constructor to show Html and Css response on vf page======== //===============================================================
public SummaryPdfDispController ()
{
cmpname=Apexpages.currentPage().getParameters().get('Cmp');
PageId = Apexpages.currentPage().getParameters().get('ids');
system.debug('********-----PageId'+ PageId); system.debug('====cmpname====='+cmpname);
if(PageId <> null && PageId <> '')
{
url = [select link_yogi__dosiersummaryurl__c,Account.name from opportunity where id=:PageId].link_yogi__dosiersummaryurl__c;
}
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
req.setHeader('APIKEY', '67546e2238254a5c557205d624814a32ad35cf96');
Http http = new Http();
req.setTimeout(120000);
try {
HttpResponse res=new HttpResponse();
if(!Test.IsRunningTest())
res = http.send(req);
else
//
system.debug('==response=='+res.getbody());
blb=res.getBody();
system.debug('==========blb============>'+ blb);
status=res.getStatus();
statuscode=res.getStatusCode();
JSONParser parser = JSON.createParser(res.getBody());
while (parser.nextToken() != null)
{
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'html'))
{
parser.nextToken();
htmlRes= parser.gettext();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'css'))
{
parser.nextToken();
CssRes = parser.gettext();
}
}
system.debug('==Html==='+htmlRes); system.debug('====CSS Response=='+CssRes);
}
catch(System.CalloutException e)
{
System.debug('System.Callout Exception for SummaryPdfDispController Constructor ' + e.getMessage());
}
}
//========================================
//===Method to Download Dossier as Pdf====
//========================================
public void DownloadPdf()
{
string url = [select link_yogi__dosierurl__c,Account.name from opportunity where id=:PageId].link_yogi__dosierurl__c]; HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
req.setHeader('APIKEY', '67546e2238254a5c557205d624814a32ad35cf96');
Http http = new Http();
req.setTimeout(120000);
try
{
HttpResponse res=new HttpResponse();
if(!Test.IsRunningTest())
res = http.send(req);
else
// ----
system.debug('==response=='+res.getbody());
downloadResponse =res.getBodyAsBlob();
status=res.getStatus();
statuscode=res.getStatusCode();
system.debug('===Response==='+downloadResponse);
}
catch(System.CalloutException e)
{
System.debug('System.Callout Exception for DownloadPdf Method ' + e.getMessage());
}
if(downloadResponse <> null)
{
attachmentList=[select id,name,parentid from attachment where parentId =: PageId AND name=: cmpname+'.pdf']; system.debug('==Existing company Attachments to delete=='+attachmentList);
if(attachmentList.isEmpty() == False)
{
try
{
delete attachmentList;
}
catch(System.QueryException e)
{
System.debug('System.QueryException for DownloadPdf Method on delete operation ' + e);
}
}
at= new attachment();
at.parentId = PageId;
at.body = downloadResponse;
at.name = cmpname+'.pdf';
try
{
insert at;
}
catch(System.QueryException e)
{
System.debug('System.QueryException for DownloadPdf Method on insert operation ' + e);
}
attachmentId = at.id;
downloadResponse= null;
at= null;
system.debug('====Attachment====='+at);
}
}
}
- LinkYogi
- June 03, 2015
- Like
- 0
Rendering in apex:outputPanel
vf page:
apex:pageBlockTable value="{!Opportunity}" var="op" align="center" style="border:none;"
apex:column
apex:outputPanel rendered="{!IF(CONTAINS(mapKey,op.name)=True,False,True)}"
apex:commandButton value="Add to LY Prospect List" action="{!show}" rerender="popup" onclick="this.style.visibility = 'hidden' "
apex:param name="OppName" value="{!op.id}" assignTo="{!opid}"/
/apex:commandButton
/apex:OutputPanel
Apex Page:
public string mapkey;
for(Companies com: compList){
if(MrktRatngMap.containsKey(com.ComName)==True){
mapKey=mapKey+' '+com.ComName;
}
}
Q Please let me know the meaning of the statement: apex:outputPanel rendered="{!IF(CONTAINS(mapKey,op.name)=True,False,True)}"
apex:pageBlockTable value="{!Opportunity}" var="op" align="center" style="border:none;"
apex:column
apex:outputPanel rendered="{!IF(CONTAINS(mapKey,op.name)=True,False,True)}"
apex:commandButton value="Add to LY Prospect List" action="{!show}" rerender="popup" onclick="this.style.visibility = 'hidden' "
apex:param name="OppName" value="{!op.id}" assignTo="{!opid}"/
/apex:commandButton
/apex:OutputPanel
Apex Page:
public string mapkey;
for(Companies com: compList){
if(MrktRatngMap.containsKey(com.ComName)==True){
mapKey=mapKey+' '+com.ComName;
}
}
Q Please let me know the meaning of the statement: apex:outputPanel rendered="{!IF(CONTAINS(mapKey,op.name)=True,False,True)}"
- LinkYogi
- June 24, 2015
- Like
- 0
variable is not incrementing in apex class
Hi All,
My issue is variable(counter) is not incrementing.
I am running the class in batches, but debug statement 'counter prev' only gives 1.
Apex Code:
global class Update_Records{
//**********************
//Declare Variables
//*********************
public string testmrksig{set;get;}
public string x;
public string y;
public List<opportunity> OppList {set;get;}
public string oppString{get;set;}
public string respons{get;set;}
public List<Opportunity> opper = new list<opportunity>();
public Map<string,Decimal> MrktRatngMap{get;set;}
public Map<string,string> CompUrlMap{get;set;}
public Map<string,string>dossierurlMap{get;set;}
public Map<string,string>dossierurlsummarymap{get;set;}
public string mapKey{get;set;}
ID userId =UserInfo.getUserId();
public List<SelectOption> AvilIns { get; set; }
public String SeltIns {get;set;}
private ApexPages.StandardController stdController;
//***************
//Constructor
//***************
public Update_Records()
{
MrktRatngMap = new Map<string,Decimal>();
CompUrlMap = new Map<string,string>();
dossierurlMap = new map<string,string>();
dossierurlsummarymap = new map<string,string>();
//OppData();
Opportunity ope= new opportunity();
}
//***********************************************************************
//Method to send request and parse response related to opportunities
//***********************************************************************
public void OppData(){
Integer counter=0;
Integer batchsize=150;
OppList =[select id, name, Marketing_Signal__c from opportunity];
for(Opportunity opp: OppList)
{
counter+=1;
if(opp.name <> null){
if(oppString == null){
String url = EncodingUtil.urlEncode(opp.name,'UTF-8');
oppString = '&names[]='+url;
}
else{
String url = EncodingUtil.urlEncode(opp.name,'UTF-8');
oppString = oppString + '&names[]='+url;
}
}
system.debug('counter prev** '+counter);
if (math.mod(counter,batchsize)==0)
{
system.debug('counter** '+counter);
list<Marketingsignalwrapper>mswlist= new list <Marketingsignalwrapper>();
for(opportunity oop:OppList)
{
if(MrktRatngMap.containsKey(oop.name)!=True ){
oop.Marketing_Signal__c = MrktRatngMap.get(oop.name);
}
Marketingsignalwrapper Temp = new Marketingsignalwrapper (oop);
mswlist.add(temp);
}
mswlist.sort();
opper.clear();
for (Marketingsignalwrapper o1 : mswlist )
{
opportunity o2= new opportunity();
{
opper.add(o1.oppy);
}
}
HttpRequest htreq = new HttpRequest();
String initialUrl = 'https://app.linkyogi.com/api/v1/companies/search?userId=' + UserId + oppString;
htreq.setEndpoint(initialUrl);
htreq.setMethod('POST');
htreq.setHeader('APIKEY', '67546e2238254a5c557205d624814a32ad35cf96');
Http http = new Http();
try
{
system.debug('response statement**** ');
HttpResponse res=new HttpResponse();
if(!Test.IsRunningTest())
res = http.send(htreq);
else
res.setBody(//);
respons = res.getBody();
system.debug('*******----------'+respons);
string dossier_url;
string dossier_summary_url;
string marketing_signal;
string company_url;
string present;
string names;
boolean nameCheck = False;
List<Companies> compList = new List<Companies>();
JSONparser parser = JSON.createparser(respons);
while (parser.nextToken() != null) {
if (parser.getCurrentToken() == JSONToken.START_OBJECT){
while(parser.nextToken() != null){
if (parser.getCurrentToken() == JSONToken.FIELD_NAME ) {
if(nameCheck == False){
names = parser.getText();
nameCheck = True;
}
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'dossier_url')) {
parser.nextToken();
dossier_url = parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'dossier_summary_url')) {
parser.nextToken();
dossier_summary_url= parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'marketing_signal')) {
parser.nextToken();
marketing_signal = parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'company_url')) {
parser.nextToken();
company_url = parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'present')) {
parser.nextToken();
present= parser.getText();
}
if(parser.getCurrentToken() == JSONToken.END_OBJECT){
Companies com = new Companies(names,dossier_url ,dossier_summary_url,marketing_signal, company_url,present);
compList.add(com);
dossier_url = null;
dossier_summary_url=null;
marketing_signal = null;
company_url = null;
present = null;
nameCheck = False;
}
}
}
}
for(Companies com: compList){
if(com.present == 'true'){
MrktRatngMap.put(com.ComName, Decimal.ValueOf(com.marketing_signal));
CompUrlMap.put(com.ComName, com.company_url);
dossierurlsummarymap.put(com.ComName, com.dossier_summary_url); //prad
dossierurlMap.put(com.ComName, com.dossier_url );
x= dossierurlMap.get(com.ComName);
system.debug('----------------------------------------------> x'+x);
}
if(MrktRatngMap.containsKey(com.ComName)==True){
mapKey=mapKey+' '+com.ComName;
testmrksig+='::'+com.ComName+'::'+com.marketing_signal;
}
}
}
catch(System.CalloutException e)
{
System.debug('A Callout Exception of method Oppdata: ' + e.getMessage());
}
}
counter=0;
}
}
//*************************************
//Inner class to Combine Json Response
//*************************************
public class Companies{
public string dossier_url {get;set;}
public string dossier_summary_url{get;set;}
public string marketing_signal {get;set;}
public string company_url{get;set;}
public string present {get;set;}
public string ComName{get;set;}
public Companies( string nm,string durl,string dsurl, string MarkSg, string comUrl,string prsnt){
this.dossier_url = durl;
this.dossier_summary_url=dsurl;
this.marketing_signal = MarkSg;
this.company_url = comUrl;
this.present = prsnt;
this.ComName = nm;
}
}
global class Marketingsignalwrapper implements Comparable
{
public opportunity oppy{get;set;}
global Marketingsignalwrapper(opportunity op) {
oppy = op;
}
global Integer compareTo(Object compareTo)
{
Marketingsignalwrapper msw=(Marketingsignalwrapper)compareTo;
Integer returnValue = 0;
if (oppy.Marketing_Signal__c>msw.oppy.Marketing_Signal__c) {
// Set return value to a positive value.
returnValue = 1;
} else if (oppy.Marketing_Signal__c< msw.oppy.Marketing_Signal__c){
//Set return value to a negative value.
returnValue = -1;
}
return returnValue;
}
}
}
My issue is variable(counter) is not incrementing.
I am running the class in batches, but debug statement 'counter prev' only gives 1.
Apex Code:
global class Update_Records{
//**********************
//Declare Variables
//*********************
public string testmrksig{set;get;}
public string x;
public string y;
public List<opportunity> OppList {set;get;}
public string oppString{get;set;}
public string respons{get;set;}
public List<Opportunity> opper = new list<opportunity>();
public Map<string,Decimal> MrktRatngMap{get;set;}
public Map<string,string> CompUrlMap{get;set;}
public Map<string,string>dossierurlMap{get;set;}
public Map<string,string>dossierurlsummarymap{get;set;}
public string mapKey{get;set;}
ID userId =UserInfo.getUserId();
public List<SelectOption> AvilIns { get; set; }
public String SeltIns {get;set;}
private ApexPages.StandardController stdController;
//***************
//Constructor
//***************
public Update_Records()
{
MrktRatngMap = new Map<string,Decimal>();
CompUrlMap = new Map<string,string>();
dossierurlMap = new map<string,string>();
dossierurlsummarymap = new map<string,string>();
//OppData();
Opportunity ope= new opportunity();
}
//***********************************************************************
//Method to send request and parse response related to opportunities
//***********************************************************************
public void OppData(){
Integer counter=0;
Integer batchsize=150;
OppList =[select id, name, Marketing_Signal__c from opportunity];
for(Opportunity opp: OppList)
{
counter+=1;
if(opp.name <> null){
if(oppString == null){
String url = EncodingUtil.urlEncode(opp.name,'UTF-8');
oppString = '&names[]='+url;
}
else{
String url = EncodingUtil.urlEncode(opp.name,'UTF-8');
oppString = oppString + '&names[]='+url;
}
}
system.debug('counter prev** '+counter);
if (math.mod(counter,batchsize)==0)
{
system.debug('counter** '+counter);
list<Marketingsignalwrapper>mswlist= new list <Marketingsignalwrapper>();
for(opportunity oop:OppList)
{
if(MrktRatngMap.containsKey(oop.name)!=True ){
oop.Marketing_Signal__c = MrktRatngMap.get(oop.name);
}
Marketingsignalwrapper Temp = new Marketingsignalwrapper (oop);
mswlist.add(temp);
}
mswlist.sort();
opper.clear();
for (Marketingsignalwrapper o1 : mswlist )
{
opportunity o2= new opportunity();
{
opper.add(o1.oppy);
}
}
HttpRequest htreq = new HttpRequest();
String initialUrl = 'https://app.linkyogi.com/api/v1/companies/search?userId=' + UserId + oppString;
htreq.setEndpoint(initialUrl);
htreq.setMethod('POST');
htreq.setHeader('APIKEY', '67546e2238254a5c557205d624814a32ad35cf96');
Http http = new Http();
try
{
system.debug('response statement**** ');
HttpResponse res=new HttpResponse();
if(!Test.IsRunningTest())
res = http.send(htreq);
else
res.setBody(//);
respons = res.getBody();
system.debug('*******----------'+respons);
string dossier_url;
string dossier_summary_url;
string marketing_signal;
string company_url;
string present;
string names;
boolean nameCheck = False;
List<Companies> compList = new List<Companies>();
JSONparser parser = JSON.createparser(respons);
while (parser.nextToken() != null) {
if (parser.getCurrentToken() == JSONToken.START_OBJECT){
while(parser.nextToken() != null){
if (parser.getCurrentToken() == JSONToken.FIELD_NAME ) {
if(nameCheck == False){
names = parser.getText();
nameCheck = True;
}
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'dossier_url')) {
parser.nextToken();
dossier_url = parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'dossier_summary_url')) {
parser.nextToken();
dossier_summary_url= parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'marketing_signal')) {
parser.nextToken();
marketing_signal = parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'company_url')) {
parser.nextToken();
company_url = parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'present')) {
parser.nextToken();
present= parser.getText();
}
if(parser.getCurrentToken() == JSONToken.END_OBJECT){
Companies com = new Companies(names,dossier_url ,dossier_summary_url,marketing_signal, company_url,present);
compList.add(com);
dossier_url = null;
dossier_summary_url=null;
marketing_signal = null;
company_url = null;
present = null;
nameCheck = False;
}
}
}
}
for(Companies com: compList){
if(com.present == 'true'){
MrktRatngMap.put(com.ComName, Decimal.ValueOf(com.marketing_signal));
CompUrlMap.put(com.ComName, com.company_url);
dossierurlsummarymap.put(com.ComName, com.dossier_summary_url); //prad
dossierurlMap.put(com.ComName, com.dossier_url );
x= dossierurlMap.get(com.ComName);
system.debug('----------------------------------------------> x'+x);
}
if(MrktRatngMap.containsKey(com.ComName)==True){
mapKey=mapKey+' '+com.ComName;
testmrksig+='::'+com.ComName+'::'+com.marketing_signal;
}
}
}
catch(System.CalloutException e)
{
System.debug('A Callout Exception of method Oppdata: ' + e.getMessage());
}
}
counter=0;
}
}
//*************************************
//Inner class to Combine Json Response
//*************************************
public class Companies{
public string dossier_url {get;set;}
public string dossier_summary_url{get;set;}
public string marketing_signal {get;set;}
public string company_url{get;set;}
public string present {get;set;}
public string ComName{get;set;}
public Companies( string nm,string durl,string dsurl, string MarkSg, string comUrl,string prsnt){
this.dossier_url = durl;
this.dossier_summary_url=dsurl;
this.marketing_signal = MarkSg;
this.company_url = comUrl;
this.present = prsnt;
this.ComName = nm;
}
}
global class Marketingsignalwrapper implements Comparable
{
public opportunity oppy{get;set;}
global Marketingsignalwrapper(opportunity op) {
oppy = op;
}
global Integer compareTo(Object compareTo)
{
Marketingsignalwrapper msw=(Marketingsignalwrapper)compareTo;
Integer returnValue = 0;
if (oppy.Marketing_Signal__c>msw.oppy.Marketing_Signal__c) {
// Set return value to a positive value.
returnValue = 1;
} else if (oppy.Marketing_Signal__c< msw.oppy.Marketing_Signal__c){
//Set return value to a negative value.
returnValue = -1;
}
return returnValue;
}
}
}
- LinkYogi
- June 12, 2015
- Like
- 0
Batch class is not updating records for large number of records
Hi All,
I facing an issue that batch class is not updating records for large number of records.
Batch Class:
global class oppwithmarketing implements Database.Batchable<sObject>, Database.AllowsCallouts, Database.Stateful
{
global Map<string,Decimal> MrktSignals;
global map<string,string>Dosierurl;
global map<string,string>DosierSummaryurl;
global final string query = 'select id, name, Marketing_Signal__c,dosierurl__c,dosiersummaryurl__c from opportunity';
global Database.QueryLocator start(Database.BatchableContext BC)
{
Update_Records op = new Update_Records();
op.OppData();
MrktSignals = op.MrktRatngMap.clone();
system.debug('MrktSignals** '+MrktSignals );
Dosierurl= op.dossierurlMap.clone();
system.debug('Dosierurl** '+Dosierurl);
DosierSummaryurl= op.dossierurlsummarymap.clone();
system.debug('DosierSummaryurl** '+DosierSummaryurl);
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> batch)
{
try
{
for(Sobject so :batch)
{
opportunity opp1 = (opportunity)so;
if(MrktSignals.containsKey(opp1.name) && MrktSignals.get(opp1.name) <> null){
so.put('Marketing_Signal__c',MrktSignals.get(opp1.name));
}
if(Dosierurl.containsKey(opp1.name) && Dosierurl.get(opp1.name) <> null){
so.put('dosierurl__c',Dosierurl.get(opp1.name));
}
if(DosierSummaryurl.containsKey(opp1.name) && DosierSummaryurl.get(opp1.name) <> null){
so.put('dosiersummaryurl__c',DosierSummaryurl.get(opp1.name));
}
}
if (batch.size()>0)
{
Database.SaveResult[] list_save=Database.Update(batch, false);
for (Database.SaveResult sr: list_save)
{
if (sr.isSuccess())
{
system.debug( ' **** ' + sr.getId());
}
else
{
for (Database.Error err: sr.getErrors())
system.debug(err.getStatusCode()+' **** '+err.getMessage()+ ' **** '+err.getFields());
//system.debug(sr.getStatusCode()+' **** '+sr.getMessage());
}
}
}
}
catch(System.QueryException e)
{
System.debug('System.QueryException on oppwithmarketing batch class ' + e);
}
}
global void finish(Database.BatchableContext BC) {
system.debug(LoggingLevel.WARN, 'Batch Job Complete');
}
}
Developer Console:
Execute:
oppwithmarketing b = new oppwithmarketing();
database.executebatch(b);
Note: When I run the batch class 'oppwithmarketing' for 100 records, it works. But, for 500 or more records, it is not updating the records. Although, I am getting no error.
I facing an issue that batch class is not updating records for large number of records.
Batch Class:
global class oppwithmarketing implements Database.Batchable<sObject>, Database.AllowsCallouts, Database.Stateful
{
global Map<string,Decimal> MrktSignals;
global map<string,string>Dosierurl;
global map<string,string>DosierSummaryurl;
global final string query = 'select id, name, Marketing_Signal__c,dosierurl__c,dosiersummaryurl__c from opportunity';
global Database.QueryLocator start(Database.BatchableContext BC)
{
Update_Records op = new Update_Records();
op.OppData();
MrktSignals = op.MrktRatngMap.clone();
system.debug('MrktSignals** '+MrktSignals );
Dosierurl= op.dossierurlMap.clone();
system.debug('Dosierurl** '+Dosierurl);
DosierSummaryurl= op.dossierurlsummarymap.clone();
system.debug('DosierSummaryurl** '+DosierSummaryurl);
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> batch)
{
try
{
for(Sobject so :batch)
{
opportunity opp1 = (opportunity)so;
if(MrktSignals.containsKey(opp1.name) && MrktSignals.get(opp1.name) <> null){
so.put('Marketing_Signal__c',MrktSignals.get(opp1.name));
}
if(Dosierurl.containsKey(opp1.name) && Dosierurl.get(opp1.name) <> null){
so.put('dosierurl__c',Dosierurl.get(opp1.name));
}
if(DosierSummaryurl.containsKey(opp1.name) && DosierSummaryurl.get(opp1.name) <> null){
so.put('dosiersummaryurl__c',DosierSummaryurl.get(opp1.name));
}
}
if (batch.size()>0)
{
Database.SaveResult[] list_save=Database.Update(batch, false);
for (Database.SaveResult sr: list_save)
{
if (sr.isSuccess())
{
system.debug( ' **** ' + sr.getId());
}
else
{
for (Database.Error err: sr.getErrors())
system.debug(err.getStatusCode()+' **** '+err.getMessage()+ ' **** '+err.getFields());
//system.debug(sr.getStatusCode()+' **** '+sr.getMessage());
}
}
}
}
catch(System.QueryException e)
{
System.debug('System.QueryException on oppwithmarketing batch class ' + e);
}
}
global void finish(Database.BatchableContext BC) {
system.debug(LoggingLevel.WARN, 'Batch Job Complete');
}
}
Developer Console:
Execute:
oppwithmarketing b = new oppwithmarketing();
database.executebatch(b);
Note: When I run the batch class 'oppwithmarketing' for 100 records, it works. But, for 500 or more records, it is not updating the records. Although, I am getting no error.
- LinkYogi
- June 11, 2015
- Like
- 0
onclick function not working for commandlink
Hi All,
Below is my code:
VF Page:
<apex:page controller="SummaryPdfDispController" standardStylesheets="false" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock Id="status1">
<apex:commandLink action="{!SendEmail}" value="Email Dossier" reRender="status1" styleClass="element" onclick="this.value = 'Sending...'"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Note:
1. If I omit the onclick functionality then action- SendEmail is called.
2. I could not use commandbutton as per project purpose.
3. I have used javascript on onclick functionality, but it did not work.
Below is my code:
VF Page:
<apex:page controller="SummaryPdfDispController" standardStylesheets="false" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock Id="status1">
<apex:commandLink action="{!SendEmail}" value="Email Dossier" reRender="status1" styleClass="element" onclick="this.value = 'Sending...'"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Note:
1. If I omit the onclick functionality then action- SendEmail is called.
2. I could not use commandbutton as per project purpose.
3. I have used javascript on onclick functionality, but it did not work.
- LinkYogi
- June 03, 2015
- Like
- 0
code to download pdf by rest service
Hi All,
Below is my code:
VF Page:
<apex:page controller="SummaryPdfDispController" standardStylesheets="false" showHeader="false" sidebar="false">
<apex:form Id="status">
<apex:outputLink value="{!URLFOR($Action.Attachment.Download, attachmentId)}" target="_blank" styleClass="element">Download Dossier</apex:outputLink>
</apex:form>
</apex:page>
Apex Code:
public class SummaryPdfDispController {
public class SummaryPdfDispController
{ //===============================
//===Declare Variables===========
//===============================
public string companyUrl1 {set;get;}
public string cmpname {set;get;}
public string status {set;get;}
public integer statuscode {set;get;}
public String blobResult {set;get;}
public string PageId{get;set;}
public string blb{get;set;}
public id attachmentId{get;set;}
public string Accname{get;set;}
public string htmlRes{get;set;}
public string CssRes{get;set;}
public string EmailResponse{get;set;}
transient blob downloadResponse;
public string url;
public List<attachment> attachmentList= new List<attachment>();
public attachment at{get;set;}
//=============================================================== //===Constructor to show Html and Css response on vf page======== //===============================================================
public SummaryPdfDispController ()
{
cmpname=Apexpages.currentPage().getParameters().get('Cmp');
PageId = Apexpages.currentPage().getParameters().get('ids');
system.debug('********-----PageId'+ PageId); system.debug('====cmpname====='+cmpname);
if(PageId <> null && PageId <> '')
{
url = [select link_yogi__dosiersummaryurl__c,Account.name from opportunity where id=:PageId].link_yogi__dosiersummaryurl__c;
}
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
req.setHeader('APIKEY', '67546e2238254a5c557205d624814a32ad35cf96');
Http http = new Http();
req.setTimeout(120000);
try {
HttpResponse res=new HttpResponse();
if(!Test.IsRunningTest())
res = http.send(req);
else
//
system.debug('==response=='+res.getbody());
blb=res.getBody();
system.debug('==========blb============>'+ blb);
status=res.getStatus();
statuscode=res.getStatusCode();
JSONParser parser = JSON.createParser(res.getBody());
while (parser.nextToken() != null)
{
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'html'))
{
parser.nextToken();
htmlRes= parser.gettext();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'css'))
{
parser.nextToken();
CssRes = parser.gettext();
}
}
system.debug('==Html==='+htmlRes); system.debug('====CSS Response=='+CssRes);
}
catch(System.CalloutException e)
{
System.debug('System.Callout Exception for SummaryPdfDispController Constructor ' + e.getMessage());
}
}
//========================================
//===Method to Download Dossier as Pdf====
//========================================
public void DownloadPdf()
{
string url = [select link_yogi__dosierurl__c,Account.name from opportunity where id=:PageId].link_yogi__dosierurl__c]; HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
req.setHeader('APIKEY', '67546e2238254a5c557205d624814a32ad35cf96');
Http http = new Http();
req.setTimeout(120000);
try
{
HttpResponse res=new HttpResponse();
if(!Test.IsRunningTest())
res = http.send(req);
else
// ----
system.debug('==response=='+res.getbody());
downloadResponse =res.getBodyAsBlob();
status=res.getStatus();
statuscode=res.getStatusCode();
system.debug('===Response==='+downloadResponse);
}
catch(System.CalloutException e)
{
System.debug('System.Callout Exception for DownloadPdf Method ' + e.getMessage());
}
if(downloadResponse <> null)
{
attachmentList=[select id,name,parentid from attachment where parentId =: PageId AND name=: cmpname+'.pdf']; system.debug('==Existing company Attachments to delete=='+attachmentList);
if(attachmentList.isEmpty() == False)
{
try
{
delete attachmentList;
}
catch(System.QueryException e)
{
System.debug('System.QueryException for DownloadPdf Method on delete operation ' + e);
}
}
at= new attachment();
at.parentId = PageId;
at.body = downloadResponse;
at.name = cmpname+'.pdf';
try
{
insert at;
}
catch(System.QueryException e)
{
System.debug('System.QueryException for DownloadPdf Method on insert operation ' + e);
}
attachmentId = at.id;
downloadResponse= null;
at= null;
system.debug('====Attachment====='+at);
}
}
}
Below is my code:
VF Page:
<apex:page controller="SummaryPdfDispController" standardStylesheets="false" showHeader="false" sidebar="false">
<apex:form Id="status">
<apex:outputLink value="{!URLFOR($Action.Attachment.Download, attachmentId)}" target="_blank" styleClass="element">Download Dossier</apex:outputLink>
</apex:form>
</apex:page>
Apex Code:
public class SummaryPdfDispController {
public class SummaryPdfDispController
{ //===============================
//===Declare Variables===========
//===============================
public string companyUrl1 {set;get;}
public string cmpname {set;get;}
public string status {set;get;}
public integer statuscode {set;get;}
public String blobResult {set;get;}
public string PageId{get;set;}
public string blb{get;set;}
public id attachmentId{get;set;}
public string Accname{get;set;}
public string htmlRes{get;set;}
public string CssRes{get;set;}
public string EmailResponse{get;set;}
transient blob downloadResponse;
public string url;
public List<attachment> attachmentList= new List<attachment>();
public attachment at{get;set;}
//=============================================================== //===Constructor to show Html and Css response on vf page======== //===============================================================
public SummaryPdfDispController ()
{
cmpname=Apexpages.currentPage().getParameters().get('Cmp');
PageId = Apexpages.currentPage().getParameters().get('ids');
system.debug('********-----PageId'+ PageId); system.debug('====cmpname====='+cmpname);
if(PageId <> null && PageId <> '')
{
url = [select link_yogi__dosiersummaryurl__c,Account.name from opportunity where id=:PageId].link_yogi__dosiersummaryurl__c;
}
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
req.setHeader('APIKEY', '67546e2238254a5c557205d624814a32ad35cf96');
Http http = new Http();
req.setTimeout(120000);
try {
HttpResponse res=new HttpResponse();
if(!Test.IsRunningTest())
res = http.send(req);
else
//
system.debug('==response=='+res.getbody());
blb=res.getBody();
system.debug('==========blb============>'+ blb);
status=res.getStatus();
statuscode=res.getStatusCode();
JSONParser parser = JSON.createParser(res.getBody());
while (parser.nextToken() != null)
{
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'html'))
{
parser.nextToken();
htmlRes= parser.gettext();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'css'))
{
parser.nextToken();
CssRes = parser.gettext();
}
}
system.debug('==Html==='+htmlRes); system.debug('====CSS Response=='+CssRes);
}
catch(System.CalloutException e)
{
System.debug('System.Callout Exception for SummaryPdfDispController Constructor ' + e.getMessage());
}
}
//========================================
//===Method to Download Dossier as Pdf====
//========================================
public void DownloadPdf()
{
string url = [select link_yogi__dosierurl__c,Account.name from opportunity where id=:PageId].link_yogi__dosierurl__c]; HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
req.setHeader('APIKEY', '67546e2238254a5c557205d624814a32ad35cf96');
Http http = new Http();
req.setTimeout(120000);
try
{
HttpResponse res=new HttpResponse();
if(!Test.IsRunningTest())
res = http.send(req);
else
// ----
system.debug('==response=='+res.getbody());
downloadResponse =res.getBodyAsBlob();
status=res.getStatus();
statuscode=res.getStatusCode();
system.debug('===Response==='+downloadResponse);
}
catch(System.CalloutException e)
{
System.debug('System.Callout Exception for DownloadPdf Method ' + e.getMessage());
}
if(downloadResponse <> null)
{
attachmentList=[select id,name,parentid from attachment where parentId =: PageId AND name=: cmpname+'.pdf']; system.debug('==Existing company Attachments to delete=='+attachmentList);
if(attachmentList.isEmpty() == False)
{
try
{
delete attachmentList;
}
catch(System.QueryException e)
{
System.debug('System.QueryException for DownloadPdf Method on delete operation ' + e);
}
}
at= new attachment();
at.parentId = PageId;
at.body = downloadResponse;
at.name = cmpname+'.pdf';
try
{
insert at;
}
catch(System.QueryException e)
{
System.debug('System.QueryException for DownloadPdf Method on insert operation ' + e);
}
attachmentId = at.id;
downloadResponse= null;
at= null;
system.debug('====Attachment====='+at);
}
}
}
- LinkYogi
- June 03, 2015
- Like
- 0